/**
  */
 public function testUpdate()
 {
     $style1 = new FontStyle();
     $style2 = new FontStyle(8, FontStyle::FONT_COURIER, FontStyle::FONT_STYLE_BOLD, FontStyle::HORIZONTAL_ALIGN_MIDDLE, FontStyle::VERTICAL_ALIGN_CENTRAL);
     $style1->update($style2);
     $this->assertSame(8, $style1->getSize());
     $this->assertSame(FontStyle::FONT_COURIER, $style1->getName());
     $this->assertSame(FontStyle::FONT_STYLE_BOLD, $style1->getStyle());
     $this->assertSame(FontStyle::HORIZONTAL_ALIGN_MIDDLE, $style1->getHAlign());
     $this->assertSame(FontStyle::VERTICAL_ALIGN_CENTRAL, $style1->getVAlign());
     // test independence of style1 and style2
     $style1->setSize(12);
     $this->assertSame(12, $style1->getSize());
     $this->assertSame(8, $style2->getSize());
 }
示例#2
0
 /**
  * @param string $text
  * @param AnchorPath $p
  * @param FontStyle $fontStyle
  *
  * @return mixed[]
  * @throws \Exception
  */
 private function preparePathText($text, AnchorPath $p, ZendAbstractFont $font, FontStyle $fontStyle)
 {
     $fontScale = $fontStyle->getSize() / (double) $font->getUnitsPerEm();
     // split text into encoded characters and widths
     $chars = [];
     $widthSum = 0;
     foreach (TextUtils::getCodes($text) as $code) {
         $char = $font->encodeString(html_entity_decode('&#' . $code . ';', ENT_NOQUOTES, 'UTF-8'), 'UTF-8');
         $width = $font->widthForGlyph($font->glyphNumberForCharacter($code));
         $widthSum += $width;
         $chars[] = [$char, $fontScale * $width];
     }
     // compute start position
     switch ($fontStyle->getHAlign()) {
         case FontStyle::HORIZONTAL_ALIGN_MIDDLE:
             $startPos = ($p->getLen() - $fontScale * $widthSum) / 2.0;
             break;
         case FontStyle::HORIZONTAL_ALIGN_RIGHT:
             $startPos = $p->getLen() - $fontScale * $widthSum;
             break;
         case FontStyle::HORIZONTAL_ALIGN_LEFT:
         default:
             $startPos = 0;
     }
     // compute vertical shift
     switch ($fontStyle->getVAlign()) {
         case FontStyle::VERTICAL_ALIGN_TOP:
             $yShift = $fontScale * ($font->getAscent() - $font->getDescent());
             break;
         case FontStyle::VERTICAL_ALIGN_CENTRAL:
             $yShift = 0.5 * $fontScale * $font->getAscent();
             break;
         case FontStyle::VERTICAL_ALIGN_BOTTOM:
             $yShift = $fontScale * $font->getDescent();
             break;
         case FontStyle::VERTICAL_ALIGN_BASE:
         default:
             $yShift = 0;
     }
     return [$chars, $startPos, $yShift];
 }
示例#3
0
 /**
  * @param SimpleXMLElement $element
  * @param FontStyle $fontStyle
  */
 private function addFontStyle(SimpleXMLElement $element, FontStyle $fontStyle)
 {
     $element->addAttribute("font-family", $fontStyle->getName() . ', sans-serif');
     $element->addAttribute("font-size", $fontStyle->getSize());
     switch ($fontStyle->getStyle()) {
         case FontStyle::FONT_STYLE_BOLD:
             $element->addAttribute("font-weight", 'bold');
             break;
         case FontStyle::FONT_STYLE_ITALIC:
             $element->addAttribute("font-style", 'italic');
             break;
         case FontStyle::FONT_STYLE_BOLD_ITALIC:
             $element->addAttribute("font-weight", 'bold');
             $element->addAttribute("font-style", 'italic');
             break;
     }
     switch ($fontStyle->getHAlign()) {
         case FontStyle::HORIZONTAL_ALIGN_LEFT:
             $element->addAttribute("text-anchor", "start");
             break;
         case FontStyle::HORIZONTAL_ALIGN_MIDDLE:
             $element->addAttribute("text-anchor", "middle");
             break;
         case FontStyle::HORIZONTAL_ALIGN_RIGHT:
             $element->addAttribute("text-anchor", "end");
             break;
     }
     switch ($fontStyle->getVAlign()) {
         case FontStyle::VERTICAL_ALIGN_TOP:
             $element->addAttribute("alignment-baseline", "text-before-edge");
             break;
         case FontStyle::VERTICAL_ALIGN_CENTRAL:
             $element->addAttribute("alignment-baseline", "central");
             break;
         case FontStyle::VERTICAL_ALIGN_BASE:
             $element->addAttribute("alignment-baseline", "alphabetic");
             break;
         case FontStyle::VERTICAL_ALIGN_BOTTOM:
             $element->addAttribute("alignment-baseline", "text-after-edge");
             break;
     }
 }