PHPWord_Shared_Font::pointSizeToTwips
This commit is contained in:
parent
545cbc6e23
commit
be4b01b652
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
20
README.md
20
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));
|
||||
```
|
||||
|
||||
<a name="sections"></a>
|
||||
#### Sections
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue