Skip to content

Commit

Permalink
Add support for more CSS units
Browse files Browse the repository at this point in the history
Implements support for ch, rem, vw, vh, vmin and vmax units of CSS
lengths. For now the units relative to the viewport are only computed
once, and they won't change when the window is resized, but only when
the page is reloaded.

See: https://www.toomanyatoms.com/software/mobilized_dillo.html
Authored-By: dogma
  • Loading branch information
rodarima committed Oct 3, 2024
1 parent 2e5081b commit e9e6626
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dillo-3.2.0 [Not released yet]
- Fix use-after-free on errors in TLS connection.
Patches: Rodrigo Arias Mallo
+- Add primitive support for SVG using the nanosvg.h library.
- Add support for ch, rem, vw, vh, vmin and vmax CSS units.
Patches: dogma, Rodrigo Arias Mallo
+- Avoid expensive search for multipart/form-data boundaries.
Patches: Xavier Del Campo Romero, Rodrigo Arias Mallo
Expand Down
1 change: 1 addition & 0 deletions dw/fltkplatform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ FltkFont::FltkFont (core::style::FontAttrs *attrs)
int xx, xy, xw, xh;
fl_text_extents("x", xx, xy, xw, xh);
xHeight = xh;
zeroWidth = (int) fl_width("0");
descent = fl_descent();
ascent = fl_height() - descent;
}
Expand Down
9 changes: 5 additions & 4 deletions dw/platform.hh
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ public:
* is defined, which holds more platform dependent data.
*
* Also, this method must fill the attributes "font" (when needed),
* "ascent", "descent", "spaceSidth" and "xHeight". If "tryEverything"
* is true, several methods should be used to use another font, when
* the requested font is not available. Passing false is typically done,
* if the caller wants to test different variations.
* "ascent", "descent", "spaceSidth", "zeroWidth" and "xHeight". If
* "tryEverything" is true, several methods should be used to use
* another font, when the requested font is not available. Passing
* false is typically done, if the caller wants to test different
* variations.
*/
virtual style::Font *createFont (style::FontAttrs *attrs,
bool tryEverything) = 0;
Expand Down
1 change: 1 addition & 0 deletions dw/style.hh
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ public:
int ascent, descent;
int spaceWidth;
int xHeight;
int zeroWidth;

static Font *create (Layout *layout, FontAttrs *attrs);
static bool exists (Layout *layout, const char *name);
Expand Down
18 changes: 18 additions & 0 deletions src/css.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ typedef enum {
millimeters. */
CSS_LENGTH_TYPE_EM,
CSS_LENGTH_TYPE_EX,
CSS_LENGTH_TYPE_CH,
CSS_LENGTH_TYPE_REM,
CSS_LENGTH_TYPE_VW,
CSS_LENGTH_TYPE_VH,
CSS_LENGTH_TYPE_VMIN,
CSS_LENGTH_TYPE_VMAX,
CSS_LENGTH_TYPE_PERCENTAGE,
CSS_LENGTH_TYPE_RELATIVE, /**< This does not exist in CSS but
is used in HTML */
Expand All @@ -104,6 +110,12 @@ inline CssLength CSS_CREATE_LENGTH (float v, CssLengthType t) {
case CSS_LENGTH_TYPE_MM:
case CSS_LENGTH_TYPE_EM:
case CSS_LENGTH_TYPE_EX:
case CSS_LENGTH_TYPE_CH:
case CSS_LENGTH_TYPE_REM:
case CSS_LENGTH_TYPE_VW:
case CSS_LENGTH_TYPE_VH:
case CSS_LENGTH_TYPE_VMIN:
case CSS_LENGTH_TYPE_VMAX:
case CSS_LENGTH_TYPE_PERCENTAGE:
case CSS_LENGTH_TYPE_RELATIVE:
l.f = v;
Expand Down Expand Up @@ -131,6 +143,12 @@ inline float CSS_LENGTH_VALUE (CssLength l) {
case CSS_LENGTH_TYPE_MM:
case CSS_LENGTH_TYPE_EM:
case CSS_LENGTH_TYPE_EX:
case CSS_LENGTH_TYPE_CH:
case CSS_LENGTH_TYPE_REM:
case CSS_LENGTH_TYPE_VW:
case CSS_LENGTH_TYPE_VH:
case CSS_LENGTH_TYPE_VMIN:
case CSS_LENGTH_TYPE_VMAX:
case CSS_LENGTH_TYPE_PERCENTAGE:
case CSS_LENGTH_TYPE_RELATIVE:
return l.f;
Expand Down
18 changes: 18 additions & 0 deletions src/cssparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,24 @@ bool CssParser::parseValue(CssPropertyName prop,
} else if (dStrAsciiCasecmp(tval, "ex") == 0) {
lentype = CSS_LENGTH_TYPE_EX;
nextToken();
} else if (dStrAsciiCasecmp(tval, "ch") == 0) {
lentype = CSS_LENGTH_TYPE_CH;
nextToken();
} else if (dStrAsciiCasecmp(tval, "rem") == 0) {
lentype = CSS_LENGTH_TYPE_REM;
nextToken();
} else if (dStrAsciiCasecmp(tval, "vw") == 0) {
lentype = CSS_LENGTH_TYPE_VW;
nextToken();
} else if (dStrAsciiCasecmp(tval, "vh") == 0) {
lentype = CSS_LENGTH_TYPE_VH;
nextToken();
} else if (dStrAsciiCasecmp(tval, "vmin") == 0) {
lentype = CSS_LENGTH_TYPE_VMIN;
nextToken();
} else if (dStrAsciiCasecmp(tval, "vmax") == 0) {
lentype = CSS_LENGTH_TYPE_VMAX;
nextToken();
} else {
ret = false;
}
Expand Down
26 changes: 26 additions & 0 deletions src/styleengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,32 @@ bool StyleEngine::computeValue (int *dest, CssLength value, Font *font) {
/* Doesn't need zoom as it is already applied to font->xHeight */
*dest = roundInt (CSS_LENGTH_VALUE(value) * font->xHeight);
return true;
case CSS_LENGTH_TYPE_CH:
*dest = roundInt (CSS_LENGTH_VALUE(value) * font->zeroWidth);
return true;
case CSS_LENGTH_TYPE_REM:
if (stack->size() < 2) {
*dest = 0;
} else {
dw::core::style::Style *root_style = stack->getRef (1)->style;
if (root_style)
*dest = roundInt (CSS_LENGTH_VALUE(value) * root_style->font->size);
else
*dest = 0;
}
return true;
case CSS_LENGTH_TYPE_VW:
*dest = roundInt (CSS_LENGTH_VALUE(value) * layout->getWidthViewport() / 100);
return true;
case CSS_LENGTH_TYPE_VH:
*dest = roundInt (CSS_LENGTH_VALUE(value) * layout->getHeightViewport() / 100);
return true;
case CSS_LENGTH_TYPE_VMIN:
*dest = roundInt (CSS_LENGTH_VALUE(value) * MIN(layout->getWidthViewport(), layout->getHeightViewport()) / 100);
return true;
case CSS_LENGTH_TYPE_VMAX:
*dest = roundInt (CSS_LENGTH_VALUE(value) * MAX(layout->getWidthViewport(), layout->getHeightViewport()) / 100);
return true;
case CSS_LENGTH_TYPE_NONE:
// length values other than 0 without unit are only allowed
// in special cases (line-height) and have to be handled
Expand Down

0 comments on commit e9e6626

Please sign in to comment.