forked from koreader/crengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Frans de Jonge edited this page Mar 11, 2018
·
1 revision
diff --git a/crengine/src/lvrend.cpp b/crengine/src/lvrend.cpp
index a6bd60f6..57535753 100755
--- a/crengine/src/lvrend.cpp
+++ b/crengine/src/lvrend.cpp
@@ -987,6 +987,7 @@ int styleToTextFmtFlags( const css_style_ref_t & style, int oldflags )
int lengthToPx( css_length_t val, int base_px, int base_em )
{
+ const int dpi = 96; // TODO get DPI
switch( val.type )
{
case css_val_px:
@@ -998,11 +999,16 @@ int lengthToPx( css_length_t val, int base_px, int base_em )
case css_val_percent:
return ( (base_px * val.value) / 100 );
case css_val_unspecified:
- case css_val_in: // 2.54 cm
+ case css_val_in: // 2.54 cm
+ return val.value * dpi;
case css_val_cm:
+ return val.value * 2.54 * dpi;
case css_val_mm:
+ return val.value * 2.54 * 1000 * dpi;
case css_val_pt: // 1/72 in
+ return ( (val.value * 72) / dpi );
case css_val_pc: // 12 pt
+ return ( (val.value * 12 * 72) / dpi );
case css_val_inherited:
default:
// not supported: treat as 0
@@ -2589,6 +2595,8 @@ void DrawDocument( LVDrawBuf & drawbuf, ldomNode * enode, int x0, int y0, int dx
void convertLengthToPx( css_length_t & val, int base_px, int base_em )
{
+ const int dpi = 96; // TODO get DPI
+
switch( val.type )
{
case css_val_inherited:
@@ -2604,12 +2612,19 @@ void convertLengthToPx( css_length_t & val, int base_px, int base_em )
case css_val_percent:
val = css_length_t ( (base_px * val.value) / 100 );
break;
- case css_val_unspecified:
case css_val_in: // 2.54 cm
+ val = css_length_t ( val.value * dpi );
+ break;
case css_val_cm:
+ val = css_length_t ( val.value * 2.54 * dpi );
+ break;
case css_val_mm:
+ val = css_length_t ( val.value * 2.54 * 1000 * dpi );
case css_val_pt: // 1/72 in
+ val = css_length_t ( ( (val.value * 72) / dpi ) );
case css_val_pc: // 12 pt
+ val = css_length_t ( (val.value * 12 * 72) / dpi );
+ case css_val_unspecified:
case css_val_color:
// not supported: use inherited value
val = css_length_t ( val.value );