コード例 #1
0
 /**
  */
 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|FontStyle $fontStyle
  *
  * @return ZendAbstractFont
  * @throws \Exception
  */
 protected function getZendFont(FontStyle $fontStyle)
 {
     if (!isset($this->fontMap[$fontStyle->getName()][$fontStyle->getStyle()])) {
         throw new InvalidArgumentException('unsupported font: ' . $fontStyle->getName() . '/' . $fontStyle->getStyle());
     }
     return ZendFont::fontWithName($this->fontMap[$fontStyle->getName()][$fontStyle->getStyle()]);
 }
コード例 #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;
     }
 }