Better normalization for width of borders
This commit is contained in:
parent
70ad01550b
commit
4448bda721
|
|
@ -682,10 +682,14 @@ class Html
|
||||||
} else {
|
} else {
|
||||||
$which = '';
|
$which = '';
|
||||||
}
|
}
|
||||||
// normalization: in HTML 1px means tinest possible line width, so we cannot convert 1px -> 15 twips, coz line'd be bold, we use smallest twip instead
|
// Note - border width normalization:
|
||||||
$size = strtolower(trim($matches[1]));
|
// Width of border in Word is calculated differently than HTML borders, usually showing up too bold.
|
||||||
// BC change: up to ver. 0.17.0 incorrectly converted to points - Converter::cssToPoint($size)
|
// Smallest 1px (or 1pt) appears in Word like 2-3px/pt in HTML once converted to twips.
|
||||||
$size = ($size == '1px') ? 1 : Converter::cssToTwip($size);
|
// Therefore we need to normalize converted twip value to cca 1/2 of value.
|
||||||
|
// This may be adjusted, if better ratio or formula found.
|
||||||
|
// BC change: up to ver. 0.17.0 was $size converted to points - Converter::cssToPoint($size)
|
||||||
|
$size = Converter::cssToTwip($matches[1]);
|
||||||
|
$size = intval($size / 2);
|
||||||
// valid variants may be e.g. borderSize, borderTopSize, borderLeftColor, etc ..
|
// valid variants may be e.g. borderSize, borderTopSize, borderLeftColor, etc ..
|
||||||
$styles["border{$which}Size"] = $size; // twips
|
$styles["border{$which}Size"] = $size; // twips
|
||||||
$styles["border{$which}Color"] = trim($matches[2], '#');
|
$styles["border{$which}Color"] = trim($matches[2], '#');
|
||||||
|
|
@ -884,10 +888,10 @@ class Html
|
||||||
case 'baseline':
|
case 'baseline':
|
||||||
return 'top';
|
return 'top';
|
||||||
default:
|
default:
|
||||||
// @discuss - which one should apply:
|
// @discuss - which one should apply:
|
||||||
// - Word uses default vert. alignment: top
|
// - Word uses default vert. alignment: top
|
||||||
// - all browsers use default vert. alignment: middle
|
// - all browsers use default vert. alignment: middle
|
||||||
// Returning empty string means attribute wont be set so use Word default (top).
|
// Returning empty string means attribute wont be set so use Word default (top).
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -774,7 +774,7 @@ HTML;
|
||||||
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:pBdr/w:bottom';
|
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:pBdr/w:bottom';
|
||||||
$this->assertTrue($doc->elementExists($xpath));
|
$this->assertTrue($doc->elementExists($xpath));
|
||||||
$this->assertEquals('single', $doc->getElement($xpath)->getAttribute('w:val'));
|
$this->assertEquals('single', $doc->getElement($xpath)->getAttribute('w:val'));
|
||||||
$this->assertEquals(5 * 15, $doc->getElement($xpath)->getAttribute('w:sz'));
|
$this->assertEquals(intval(5 * 15 / 2), $doc->getElement($xpath)->getAttribute('w:sz'));
|
||||||
$this->assertEquals('lightblue', $doc->getElement($xpath)->getAttribute('w:color'));
|
$this->assertEquals('lightblue', $doc->getElement($xpath)->getAttribute('w:color'));
|
||||||
|
|
||||||
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:spacing';
|
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:spacing';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue