diff --git a/Classes/PHPWord/Shared/Font.php b/Classes/PHPWord/Shared/Font.php index be3cf1a8..ccb19bc7 100755 --- a/Classes/PHPWord/Shared/Font.php +++ b/Classes/PHPWord/Shared/Font.php @@ -77,4 +77,16 @@ class PHPWord_Shared_Font { return self::centimeterSizeToTwips($sizeInPixel / 37.795275591); } + + /** + * Calculate twip based on point size, used mainly for paragraph spacing + * + * @param int|float $sizeInPoint Size in point + * @return int|float Size (in twips) + */ + public static function pointSizeToTwips($sizeInPoint = 1) + { + return ($sizeInPoint * 20); + } + } diff --git a/README.md b/README.md index dc1a611a..bd44a446 100755 --- a/README.md +++ b/README.md @@ -73,6 +73,26 @@ $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('helloWorld.docx'); ``` +##### Measurement units + +The base length unit in Open Office XML is twip. Twip means "TWentieth of an Inch Point", i.e. 1 twip = 1/1440 inch. + +You can use PHPWord helper functions to convert inches, centimeters, or points to twips. + +``` +// Paragraph with 6 points space after +$PHPWord->addParagraphStyle('My Style', array( + 'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(6)) +); + +$section = $PHPWord->createSection(); +$sectionStyle = $section->getSettings(); +// half inch left margin +$sectionStyle->setMarginLeft(PHPWord_Shared_Font::inchSizeToTwips(.5)); +// 2 cm right margin +$sectionStyle->setMarginRight(PHPWord_Shared_Font::centimeterSizeToTwips(2)); +``` + #### Sections diff --git a/changelog.txt b/changelog.txt index a3752abd..8676eb9b 100755 --- a/changelog.txt +++ b/changelog.txt @@ -38,6 +38,7 @@ Changes in branch for release 0.7.1 : - Feature: (ivanlanin) GH-48 GH-86 - Paragraph: Hanging paragraph - Feature: (ivanlanin) GH-48 GH-86 - Section: Multicolumn and section break - QA: (Progi1984) - UnitTests +- Feature: (ivanlanin) - General: PHPWord_Shared_Font::pointSizeToTwips converter Changes in branch for release 0.7.0 : - Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found