private function readString($name)
 {
     $font = $this->font;
     $size = $font->readUInt16();
     $this->data["{$name}Size"] = $size;
     $this->data[$name] = Font::UTF16ToUTF8($font->read($size));
 }
Ejemplo n.º 2
0
 function __construct(Boundary $bound, $text = NULL, Font $font = NULL, Color $color = NULL, $align = self::ALIGN_LEFT_TOP)
 {
     parent::__construct($bound, $color);
     $this->text($text) or $this->text = '';
     $this->font($font) or $this->font = Font::getDefault();
     $this->align($align) or $this->align = self::ALIGN_LEFT_TOP;
 }
Ejemplo n.º 3
0
 function __construct($bounds)
 {
     $this->bound = Boundary::copyOrDefault($bounds);
     $this->title = ['text' => 'Диаграмма', 'color' => Color::getDefault(), 'font' => Font::getDefault(), 'margin' => ['top' => 10, 'bottom' => 10]];
     $this->values = ['bgcolors' => [Color::getDefault()], 'fgcolors' => [Color::getDefault()], 'font' => Font::getDefault(), 'labels' => TRUE];
     $this->bgcolor = new Color(255, 255, 255);
 }
 /**
  * save the current font as single svg files in a directory (counterpart of generateFromDir)
  *
  * @param  string $dir directory path
  * @return static      this
  */
 public function saveGlyphsToDir($dir)
 {
     $fontOptions = $this->font->getOptions();
     $svgTemplate = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . "\n" . '<svg' . "\n" . '	version="1.1"' . "\n" . '	id="Layer_1"' . "\n" . '	xmlns="http://www.w3.org/2000/svg"' . "\n" . '	xmlns:xlink="http://www.w3.org/1999/xlink"' . "\n" . '	x="0px"' . "\n" . '	y="0px"' . "\n" . '	width="%%%WIDTH%%%px"' . "\n" . '	height="512px"' . "\n" . '	viewBox="0 0 %%%WIDTH%%% 512"' . "\n" . '	enable-background="new 0 0 512 512"' . "\n" . '	xml:space="preserve"' . "\n" . '>' . "\n" . '	<g id="Grid">' . "\n" . '		<rect x="0" fill="none" stroke="#A9CCDB" stroke-miterlimit="10" width="512" height="512"/>' . "\n";
     for ($i = 32; $i < 512; $i += 32) {
         $color = 'A9CCDB';
         if ($i === 448) {
             $color = 'FF0000';
         }
         $svgTemplate .= '		<line fill="none" stroke="#' . $color . '" stroke-miterlimit="10" x1="0" y1="' . $i . '" x2="512" y2="' . $i . '"/>' . "\n";
     }
     for ($i = 32; $i < 512; $i += 32) {
         $svgTemplate .= '		<line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="' . $i . '" y1="0" x2="' . $i . '" y2="512"/>' . "\n";
     }
     $svgTemplate .= '	</g>' . "\n" . '	<path d="%%%PATH%%%"/>' . "\n" . '</svg>' . "\n";
     if (!is_dir($dir)) {
         throw new \InvalidArgumentException('$dir must be a writable directory');
     }
     foreach ($this->font->getGlyphs() as $glyph) {
         $targetPath = $dir . DIRECTORY_SEPARATOR . (empty($glyph['name']) ? 'icon' : preg_replace('([^a-z0-9]+)i', '-', $glyph['name'])) . '-x' . static::unicodeToHex($glyph['char']) . '.svg';
         if (isset($this->mapping[$glyph['char']])) {
             if (!copy($this->mapping[$glyph['char']]['path'], $targetPath)) {
                 throw new \Exception('unable to copy "' . $this->mapping[$glyph['char']]['path'] . '" to "' . $targetPath . '"');
             }
         } else {
             $glyphDocument = Document::createFromPath($glyph['path'], $fontOptions['horiz-adv-x'], $fontOptions['units-per-em']);
             if (file_put_contents($targetPath, str_replace(array('%%%PATH%%%', '%%%WIDTH%%%'), array($glyphDocument->getPath(512 / $fontOptions['units-per-em'], null, 'vertical', true, 0, -64), empty($glyph['width']) ? 512 : $glyph['width'] * 512 / $fontOptions['units-per-em']), $svgTemplate)) === false) {
                 throw new \Exception('unable to write to "' . $targetPath . '"');
             }
         }
     }
     return $this;
 }
Ejemplo n.º 5
0
    protected function _parse()
    {
        $font = $this->getFont();
        $data = array();

        $tableOffset = $font->pos();

        $data = $font->unpack(self::$header_format);

        $records = array();
        for ($i = 0; $i < $data["count"]; $i++) {
            $record = new Font_Table_name_Record();
            $record_data = $font->unpack(Font_Table_name_Record::$format);
            $record->map($record_data);

            $records[] = $record;
        }

        $names = array();
        foreach ($records as $record) {
            $font->seek($tableOffset + $data["stringOffset"] + $record->offset);
            $s = $font->read($record->length);
            $record->string = Font::UTF16ToUTF8($s);
            $names[$record->nameID] = $record;
        }

        $data["records"] = $names;

        $this->data = $data;
    }
 private function buildDataToInsert($year, $subgroupId, $fontId, $typeId, $varietyId, $originId, $destinyId)
 {
     $font = new Font();
     $font->setId($fontId);
     $type = new CoffeType();
     $type->setId($typeId);
     $variety = new Variety();
     $variety->setId($varietyId);
     $origin = new Country();
     $origin->setId($originId);
     $destiny = new Country();
     $destiny->setId($destinyId);
     $subgroup = new Subgroup();
     $subgroup->setId($subgroupId);
     return new Data($year, $subgroup, $font, $type, $variety, $origin, $destiny);
 }
function CreateButtonAppearance($doc, $button_down)
{
    // Create a button appearance stream ------------------------------------
    $build = new ElementBuilder();
    $writer = new ElementWriter();
    $writer->Begin($doc->GetSDFDoc());
    // Draw background
    $element = $build->CreateRect(0, 0, 101, 37);
    $element->SetPathFill(true);
    $element->SetPathStroke(false);
    $element->GetGState()->SetFillColorSpace(ColorSpace::CreateDeviceGray());
    $element->GetGState()->SetFillColor(new ColorPt(0.75, 0.0, 0.0));
    $writer->WriteElement($element);
    // Draw 'Submit' text
    $writer->WriteElement($build->CreateTextBegin());
    $text = "Submit";
    $element = $build->CreateTextRun($text, Font::Create($doc->GetSDFDoc(), Font::e_helvetica_bold), 12.0);
    $element->GetGState()->SetFillColor(new ColorPt(0.0, 0.0, 0.0));
    if ($button_down) {
        $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 33.0, 10.0);
    } else {
        $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 30.0, 13.0);
    }
    $writer->WriteElement($element);
    $writer->WriteElement($build->CreateTextEnd());
    $stm = $writer->End();
    // Set the bounding box
    $stm->PutRect("BBox", 0, 0, 101, 37);
    $stm->PutName("Subtype", "Form");
    return $stm;
}
Ejemplo n.º 8
0
 /**
  * Output the text 
  * @access private
  */
 function _done()
 {
     if (!$this->_font) {
         return false;
     }
     parent::_done();
     $this->_font->_write($this->_fillLeft(), $this->_fillTop(), $this->_text);
 }
Ejemplo n.º 9
0
  protected function _encode(){
    if (empty($this->data)) {
      Font::d("  >> Table is empty");
      return 0;
    }

    return $this->getFont()->pack($this->def, $this->data);
  }
Ejemplo n.º 10
0
Archivo: test.php Proyecto: dns/libcaca
 function __construct()
 {
     parent::__construct();
     $this->startTime = gettimeofday(true);
     $message = " --- POWERED BY LIBCACA --- OLDSCHOOL TEXT EFFECTS ARE 100% PURE WIN";
     $this->scroll = new Canvas(strlen($message), 1);
     $this->scroll->setColorAnsi(AnsiColor::WHITE, AnsiColor::TRANSPARENT);
     $this->scroll->putStr(0, 0, $message);
     $fontList = Font::getList();
     $f = new Font($fontList[1]);
     $w = $f->getWidth() * strlen($message);
     $h = $f->getHeight();
     $this->image = imagecreatetruecolor($w, $h);
     imagealphablending($this->image, false);
     imagesavealpha($this->image, true);
     $this->d = new Dither($this->image);
     $f->Render($this->scroll, $this->image);
 }
Ejemplo n.º 11
0
 /**
  * Place watermark on the page if it is not licensed version
  * 
  * @param pdfWriter {@link PdfWriter}
  * @throws DocumentException
  */
 private static function showTestMode($pdfDocument, $pdfWriter)
 {
     if (self::isLicensed()) {
         return;
     }
     $font = new Font();
     $font->setFontSize(25);
     $font->setFontColor("#B5B5B5");
     $font->setFont($pdfWriter);
     $text = "WebORB PDF Gen Evaluation Copy";
     $width = $pdfWriter->GetStringWidth($text);
     $center["x"] = $pdfDocument->width / 2;
     if ($width / 2 > $center["x"]) {
         $width = $center["x"] * 2;
     }
     $center["y"] = $pdfDocument->height / 2;
     $pdfWriter->Rotate(45, $center["x"], $center["y"]);
     $pdfWriter->SetXY($center["x"] - $width / 2, $center["y"]);
     $pdfWriter->Cell($width, 36, $text, 0, 0, "C");
     $pdfWriter->Rotate(0, $center["x"], $center["y"]);
 }
Ejemplo n.º 12
0
 function &create($typeface, $encoding, $font_resolver, &$error_message)
 {
     $font = new Font();
     $font->underline_position = 0;
     $font->underline_thickness = 0;
     $font->ascender;
     $font->descender;
     $font->char_widths = array();
     $font->bbox = array();
     global $g_last_assigned_font_id;
     $g_last_assigned_font_id++;
     $font->name = "font" . $g_last_assigned_font_id;
     // Get and load the metrics file
     $afm = $font_resolver->get_afm_mapping($typeface);
     if (!$font->_parse_afm($afm, $typeface, $encoding)) {
         $error_message = $font->error_message();
         $dummy = null;
         return $dummy;
     }
     return $font;
 }
 function &get_type1($name, $encoding)
 {
     if (!isset($this->fonts[$name][$encoding])) {
         global $g_font_resolver;
         $font =& Font::create($name, $encoding, $g_font_resolver, $this->error_message);
         if (is_null($font)) {
             $dummy = null;
             return $dummy;
         }
         $this->fonts[$name][$encoding] = $font;
     }
     return $this->fonts[$name][$encoding];
 }
Ejemplo n.º 14
0
 public function Load()
 {
     parent::$PAGE_TITLE = __(HOME_PAGE_TITLE);
     // Welcome message
     $small_img = new Picture("img/logo_16x16.png", 16, 16, 0, Picture::ALIGN_ABSMIDDLE);
     $title_header = new Object($small_img, __(WELCOME));
     $welcome_box = new Box($title_header, true, Box::STYLE_SECOND, Box::STYLE_SECOND, "", "welcome_box", 600);
     $welcome_obj = new Object(__(WELCOME_MSG));
     list($strAdminLogin, $strAdminPasswd, $strAdminRights) = getWspUserRightsInfo("admin");
     $quickstart_obj = new Object(new Picture("img/quickstart_128.png", 64, 64), "<br/>", __(QUICKSTART));
     $quickstart_link = new Link("http://www.website-php.com/" . $this->getLanguage() . "/quick-start.html", Link::TARGET_BLANK, $quickstart_obj);
     $quickstart_box = new RoundBox(3, "quickstart_box", 120, 120);
     $quickstart_box->setValign(RoundBox::VALIGN_CENTER);
     $quickstart_box->setContent($quickstart_link);
     $tutorial_obj = new Object(new Picture("img/tutorials_128.png", 64, 64), "<br/>", __(TUTORIALS));
     $tutorial_link = new Link("http://www.website-php.com/" . $this->getLanguage() . "/tutorials.html", Link::TARGET_BLANK, $tutorial_obj);
     $tutorial_box = new RoundBox(3, "tutorial_box", 120, 120);
     $tutorial_box->setValign(RoundBox::VALIGN_CENTER);
     $tutorial_box->setContent($tutorial_link);
     $connect_obj = new Object(new Picture("img/wsp-admin/admin_128.png", 64, 64), "<br/>", __(CONNECT));
     $connect_link = new Link("wsp-admin/connect.html", Link::TARGET_BLANK, $connect_obj);
     $connect_box = new RoundBox(3, "connect_box", 120, 120);
     $connect_box->setValign(RoundBox::VALIGN_CENTER);
     $connect_box->setContent($connect_link);
     $icon_table = new Table();
     $icon_table->setDefaultAlign(RowTable::ALIGN_CENTER)->setDefaultValign(RowTable::VALIGN_TOP);
     $icon_row = $icon_table->addRowColumns($quickstart_box, "&nbsp;", $tutorial_box, "&nbsp;", $connect_box);
     $icon_row->setColumnWidth(5, 120);
     if ($strAdminLogin == "admin" && $strAdminPasswd == sha1("admin")) {
         $finalize = new Font(__(FINALIZE_INSTALL));
         $finalize->setFontColor("red");
         $finalize->setFontWeight(Font::FONT_WEIGHT_BOLD);
         $welcome_obj->add("<br/>", $finalize, "<br/>", __(CONNECT_DEFAULT_PASSWD), "<br/>");
     }
     $welcome_obj->add("<br/>", $icon_table);
     $welcome_box->setContent($welcome_obj);
     // Footer
     $this->render = new Template($welcome_box);
 }
Ejemplo n.º 15
0
 /**
  * @param Font $font
  * @param string $text
  * @param int $color
  * @param int $spacing
  * @throws FontException
  */
 public function __construct(Font $font, $text, $color, $spacing = 1)
 {
     $cw = $font->getWidth();
     $ch = $font->getHeight();
     // no support for UTF-8 or newlines!
     $num_chars = strlen($text);
     $full_width = $cw * $num_chars + ($num_chars - 1) * $spacing;
     $full_height = $ch;
     $pixels = array_fill(0, $full_width * $full_height, 0);
     for ($i = 0; $i < $num_chars; ++$i) {
         $char = ord($text[$i]);
         $cox = ($cw + $spacing) * $i;
         $char_pixels = $font->getPixelsForCharacter($char);
         for ($y = 0; $y < $ch; ++$y) {
             for ($x = 0; $x < $cw; ++$x) {
                 if ($char_pixels[$y * $cw + $x]) {
                     $pixels[$full_width * $y + $cox + $x] = $color;
                 }
             }
         }
     }
     parent::__construct($full_width, $full_height, $pixels);
 }
 function encode($entry_offset)
 {
     Font::d("\n==== {$this->tag} ====");
     $data = $this->font_table;
     $font = $this->font;
     $table_offset = $font->pos();
     $table_length = $data->encode();
     $font->seek($table_offset);
     $table_data = $font->read($table_length);
     $font->seek($entry_offset);
     $font->write($this->tag, 4);
     $font->writeUInt32(self::computeChecksum($table_data));
     $font->writeUInt32($table_offset);
     $font->writeUInt32($table_length);
     Font::d("Bytes written = {$table_length}");
     $font->seek($table_offset + $table_length);
 }
Ejemplo n.º 17
0
function AddCoverPage($doc)
{
    // Here we dynamically generate cover page (please see ElementBuilder
    // sample for more extensive coverage of PDF creation API).
    $page = $doc->PageCreate(new Rect(0.0, 0.0, 200.0, 200.0));
    $builder = new ElementBuilder();
    $writer = new ElementWriter();
    $writer->Begin($page);
    $font = Font::Create($doc->GetSDFDoc(), Font::e_helvetica);
    $writer->WriteElement($builder->CreateTextBegin($font, 12.0));
    $element = $builder->CreateTextRun("My PDF Collection");
    $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 50.0, 96.0);
    $element->GetGState()->SetFillColorSpace(ColorSpace::CreateDeviceRGB());
    $element->GetGState()->SetFillColor(new ColorPt(1.0, 0.0, 0.0));
    $writer->WriteElement($element);
    $writer->WriteElement($builder->CreateTextEnd());
    $writer->End();
    $doc->PagePushBack($page);
    // Alternatively we could import a PDF page from a template PDF document
    // (for an example please see PDFPage sample project).
    // ...
}
Ejemplo n.º 18
0
    /**
     * Output the text 
     * @access private
     */
    function _done()
    {
        if (!$this->_font) {
            return false;
        }
        
        if (!is_a($this->_parent, "Image_Graph_Layout")) {
            $this->_setCoords(
                $this->_parent->_fillLeft(),
                $this->_parent->_fillTop(),
                $this->_parent->_fillRight(),
                $this->_parent->_fillTop() + $this->_font->height($this->_text)
            );
        }               
        
        parent::_done();

        $this->_font->_write(
            ($this->_left + $this->_right - $this->_font->width($this->_text)) / 2, 
            ($this->_top + $this->_bottom - $this->_font->height($this->_text)) / 2, 
            $this->_text
        );
    }
Ejemplo n.º 19
0
/**
 * Installs a new font family
 *
 * This function maps a font-family name to a font.  It tries to locate the
 * bold, italic, and bold italic versions of the font as well.  Once the
 * files are located, ttf versions of the font are copied to the fonts
 * directory.  Changes to the font lookup table are saved to the cache.
 *
 * @param string $fontname the font-family name
 * @param string $normal the filename of the normal face font subtype
 * @param string $bold   the filename of the bold face font subtype
 * @param string $italic the filename of the italic face font subtype
 * @param string $bold_italic the filename of the bold italic face font subtype
 */
function install_font_family($fontname, $normal, $bold = null, $italic = null, $bold_italic = null)
{
    Font_Metrics::init();
    // Check if the base filename is readable
    if (!is_readable($normal)) {
        throw new DOMPDF_Exception("Unable to read '{$normal}'.");
    }
    $dir = dirname($normal);
    $basename = basename($normal);
    $last_dot = strrpos($basename, '.');
    if ($last_dot !== false) {
        $file = substr($basename, 0, $last_dot);
        $ext = strtolower(substr($basename, $last_dot));
    } else {
        $file = $basename;
        $ext = '';
    }
    if (!in_array($ext, array(".ttf", ".otf"))) {
        throw new DOMPDF_Exception("Unable to process fonts of type '{$ext}'.");
    }
    // Try $file_Bold.$ext etc.
    $path = "{$dir}/{$file}";
    $patterns = array("bold" => array("_Bold", "b", "B", "bd", "BD"), "italic" => array("_Italic", "i", "I"), "bold_italic" => array("_Bold_Italic", "bi", "BI", "ib", "IB"));
    foreach ($patterns as $type => $_patterns) {
        if (!isset(${$type}) || !is_readable(${$type})) {
            foreach ($_patterns as $_pattern) {
                if (is_readable("{$path}{$_pattern}{$ext}")) {
                    ${$type} = "{$path}{$_pattern}{$ext}";
                    break;
                }
            }
            if (is_null(${$type})) {
                echo "Unable to find {$type} face file.\n";
            }
        }
    }
    $fonts = compact("normal", "bold", "italic", "bold_italic");
    $entry = array();
    // Copy the files to the font directory.
    foreach ($fonts as $var => $src) {
        if (is_null($src)) {
            $entry[$var] = DOMPDF_FONT_DIR . mb_substr(basename($normal), 0, -4);
            continue;
        }
        // Verify that the fonts exist and are readable
        if (!is_readable($src)) {
            throw new DOMPDF_Exception("Requested font '{$src}' is not readable");
        }
        $dest = DOMPDF_FONT_DIR . basename($src);
        if (!is_writeable(dirname($dest))) {
            throw new DOMPDF_Exception("Unable to write to destination '{$dest}'.");
        }
        echo "Copying {$src} to {$dest}...\n";
        if (!copy($src, $dest)) {
            throw new DOMPDF_Exception("Unable to copy '{$src}' to '{$dest}'");
        }
        $entry_name = mb_substr($dest, 0, -4);
        echo "Generating Adobe Font Metrics for {$entry_name}...\n";
        $font_obj = Font::load($dest);
        $font_obj->saveAdobeFontMetrics("{$entry_name}.ufm");
        $entry[$var] = $entry_name;
    }
    // Store the fonts in the lookup table
    Font_Metrics::set_font_family($fontname, $entry);
    // Save the changes
    Font_Metrics::save_font_families();
}
Ejemplo n.º 20
0
 /**
  * Gets the font of the element.
  *
  * If not font has been set, the parent font is propagated through it's
  * children.
  *
  * @param array $options Font options
  *
  * @return array An associated array used for canvas
  * @access private
  */
 function _getFont($options = false)
 {
     if ($options === false && $this->_defaultFontOptions !== false) {
         return $this->_defaultFontOptions;
     }
     if ($options === false) {
         $saveDefault = true;
     } else {
         $saveDefault = false;
     }
     if ($options === false) {
         $options = $this->_fontOptions;
     } else {
         $options = array_merge($this->_fontOptions, $options);
     }
     if ($this->_font == null) {
         $result = $this->_parent->_getFont($options);
     } else {
         $result = $this->_font->_getFont($options);
     }
     if (isset($result['size']) && isset($result['size_rel'])) {
         $result['size'] += $result['size_rel'];
         unset($result['size_rel']);
     }
     if ($saveDefault) {
         $this->_defaultFontOptions = $result;
     }
     return $result;
 }
 static function register_font($style, $remote_file)
 {
     $fontname = mb_strtolower($style["family"]);
     $families = Font_Metrics::get_font_families();
     $entry = array();
     if (isset($families[$fontname])) {
         $entry = $families[$fontname];
     }
     $local_file = DOMPDF_FONT_DIR . md5($remote_file);
     $cache_entry = $local_file;
     $local_file .= ".ttf";
     $style_string = Font_Metrics::get_type("{$style['weight']} {$style['style']}");
     if (!isset($entry[$style_string])) {
         $entry[$style_string] = $cache_entry;
         Font_Metrics::set_font_family($fontname, $entry);
         // Download the remote file
         if (!is_file($local_file)) {
             file_put_contents($local_file, file_get_contents($remote_file));
         }
         $font = Font::load($local_file);
         if (!$font) {
             return false;
         }
         $font->parse();
         $font->saveAdobeFontMetrics("{$cache_entry}.ufm");
         // Save the changes
         Font_Metrics::save_font_families();
     }
     return true;
 }
Ejemplo n.º 22
0
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */
$fontfile = null;
if (isset($_GET["fontfile"])) {
    $fontfile = basename($_GET["fontfile"]);
    $fontfile = "../fonts/{$fontfile}";
}
if (!file_exists($fontfile)) {
    return;
}
$name = isset($_GET["name"]) ? $_GET["name"] : null;
if (isset($_POST["subset"])) {
    $subset = $_POST["subset"];
    ob_start();
    require_once "../classes/Font.php";
    $font = Font::load($fontfile);
    $font->parse();
    $font->setSubset($subset);
    $font->reduce();
    $new_filename = basename($fontfile);
    $new_filename = substr($new_filename, 0, -4) . "-subset." . substr($new_filename, -3);
    header("Content-Type: font/truetype");
    header("Content-Disposition: attachment; filename=\"{$new_filename}\"");
    $tmp = tempnam(sys_get_temp_dir(), "fnt");
    $font->open($tmp, Font_Binary_Stream::modeWrite);
    $font->encode(array("OS/2"));
    $font->close();
    ob_end_clean();
    readfile($tmp);
    unlink($tmp);
    return;
 public function getUTF16()
 {
     return Font::UTF8ToUTF16($this->string);
 }
Ejemplo n.º 24
0
 /**
  * Note: the koefficient is just a magic number; I'll need to examine the
  * imagefttext behavior more closely
  */
 function stringwidth($string, $name, $encoding, $size)
 {
     $font = $this->_font_factory->getTrueType($name, $encoding);
     return Font::points($size, $font->stringwidth($string)) * 1.25;
 }
Ejemplo n.º 25
0
  $stream->w($type, $data);
  $stream->seek(0);
  $new_data = $stream->r($type);
  
  if ($new_data !== $data) {
    echo "NOT OK \t $data \t => $new_data<br />";
  }
  else {
    echo "OK $type<br />";
  }
}*/
// font RW
$filename = "../fonts/DejaVuSansMono.ttf";
$filename_out = "{$filename}.2.ttf";
Font::$debug = true;
$font = Font::load($filename);
$font->parse();
$font->setSubset("(.apbiI,mn");
$font->reduce();
$font->open($filename_out, Font_Binary_Stream::modeWrite);
$font->encode(array("OS/2"));
?>

File size: <?php 
echo number_format(filesize($filename_out), 0, ".", " ");
?>
 bytes
Memory: <?php 
echo memory_get_peak_usage(true) / 1024;
?>
KB
Ejemplo n.º 26
0
 /**
  * if the font is not loaded then load it and make the required object
  * else just make it the current font
  * the encoding array can contain 'encoding'=> 'none','WinAnsiEncoding','MacRomanEncoding' or 'MacExpertEncoding'
  * note that encoding='none' will need to be used for symbolic fonts
  * and 'differences' => an array of mappings between numbers 0->255 and character names.
  *
  */
 function selectFont($fontName, $encoding = '', $set = true)
 {
     $ext = substr($fontName, -4);
     if ($ext === '.afm' || $ext === '.ufm') {
         $fontName = substr($fontName, 0, mb_strlen($fontName) - 4);
     }
     if (!isset($this->fonts[$fontName])) {
         $this->addMessage("selectFont: selecting - {$fontName} - {$encoding}, {$set}");
         // load the file
         $this->openFont($fontName);
         if (isset($this->fonts[$fontName])) {
             $this->numObj++;
             $this->numFonts++;
             $font =& $this->fonts[$fontName];
             //$this->numFonts = md5($fontName);
             $pos = strrpos($fontName, '/');
             //      $dir = substr($fontName,0,$pos+1);
             $name = substr($fontName, $pos + 1);
             $options = array('name' => $name, 'fontFileName' => $fontName);
             if (is_array($encoding)) {
                 // then encoding and differences might be set
                 if (isset($encoding['encoding'])) {
                     $options['encoding'] = $encoding['encoding'];
                 }
                 if (isset($encoding['differences'])) {
                     $options['differences'] = $encoding['differences'];
                 }
             } else {
                 if (mb_strlen($encoding, '8bit')) {
                     // then perhaps only the encoding has been set
                     $options['encoding'] = $encoding;
                 }
             }
             $fontObj = $this->numObj;
             $this->o_font($this->numObj, 'new', $options);
             $font['fontNum'] = $this->numFonts;
             // if this is a '.afm' font, and there is a '.pfa' file to go with it ( as there
             // should be for all non-basic fonts), then load it into an object and put the
             // references into the font object
             $basefile = $fontName;
             $fbtype = '';
             if (file_exists("{$basefile}.pfb")) {
                 $fbtype = 'pfb';
             } elseif (file_exists("{$basefile}.ttf")) {
                 $fbtype = 'ttf';
             }
             $fbfile = "{$basefile}.{$fbtype}";
             //      $pfbfile = substr($fontName,0,strlen($fontName)-4).'.pfb';
             //      $ttffile = substr($fontName,0,strlen($fontName)-4).'.ttf';
             $this->addMessage('selectFont: checking for - ' . $fbfile);
             // OAR - I don't understand this old check
             // if  (substr($fontName, -4) ===  '.afm' &&  strlen($fbtype)) {
             if ($fbtype) {
                 $adobeFontName = isset($font['PostScriptName']) ? $font['PostScriptName'] : $font['FontName'];
                 //        $fontObj = $this->numObj;
                 $this->addMessage("selectFont: adding font file - {$fbfile} - {$adobeFontName}");
                 // find the array of font widths, and put that into an object.
                 $firstChar = -1;
                 $lastChar = 0;
                 $widths = array();
                 $cid_widths = array();
                 foreach ($font['C'] as $num => $d) {
                     if (intval($num) > 0 || $num == '0') {
                         if (!$font['isUnicode']) {
                             // With Unicode, widths array isn't used
                             if ($lastChar > 0 && $num > $lastChar + 1) {
                                 for ($i = $lastChar + 1; $i < $num; $i++) {
                                     $widths[] = 0;
                                 }
                             }
                         }
                         $widths[] = $d;
                         if ($font['isUnicode']) {
                             $cid_widths[$num] = $d;
                         }
                         if ($firstChar == -1) {
                             $firstChar = $num;
                         }
                         $lastChar = $num;
                     }
                 }
                 // also need to adjust the widths for the differences array
                 if (isset($options['differences'])) {
                     foreach ($options['differences'] as $charNum => $charName) {
                         if ($charNum > $lastChar) {
                             if (!$font['isUnicode']) {
                                 // With Unicode, widths array isn't used
                                 for ($i = $lastChar + 1; $i <= $charNum; $i++) {
                                     $widths[] = 0;
                                 }
                             }
                             $lastChar = $charNum;
                         }
                         if (isset($font['C'][$charName])) {
                             $widths[$charNum - $firstChar] = $font['C'][$charName];
                             if ($font['isUnicode']) {
                                 $cid_widths[$charName] = $font['C'][$charName];
                             }
                         }
                     }
                 }
                 if ($font['isUnicode']) {
                     $font['CIDWidths'] = $cid_widths;
                 }
                 $this->addMessage('selectFont: FirstChar = ' . $firstChar);
                 $this->addMessage('selectFont: LastChar = ' . $lastChar);
                 $widthid = -1;
                 if (!$font['isUnicode']) {
                     // With Unicode, widths array isn't used
                     $this->numObj++;
                     $this->o_contents($this->numObj, 'new', 'raw');
                     $this->objects[$this->numObj]['c'] .= '[' . implode(' ', $widths) . ']';
                     $widthid = $this->numObj;
                 }
                 $missing_width = 500;
                 $stemV = 70;
                 if (isset($font['MissingWidth'])) {
                     $missing_width = $font['MissingWidth'];
                 }
                 if (isset($font['StdVW'])) {
                     $stemV = $font['StdVW'];
                 } elseif (isset($font['Weight']) && preg_match('!(bold|black)!i', $font['Weight'])) {
                     $stemV = 120;
                 }
                 // load the pfb file, and put that into an object too.
                 // note that pdf supports only binary format type 1 font files, though there is a
                 // simple utility to convert them from pfa to pfb.
                 if (!$this->isUnicode || $fbtype !== 'ttf' || empty($this->stringSubsets)) {
                     $data = file_get_contents($fbfile);
                 } else {
                     require_once dirname(__FILE__) . "/php-font-lib/classes/font.cls.php";
                     $this->stringSubsets[$fontName][] = 32;
                     // Force space if not in yet
                     $subset = $this->stringSubsets[$fontName];
                     sort($subset);
                     // Load font
                     $font_obj = Font::load($fbfile);
                     $font_obj->parse();
                     // Define subset
                     $font_obj->setSubset($subset);
                     $font_obj->reduce();
                     // Write new font
                     $tmp_name = "{$fbfile}.tmp." . sprintf("%u", crc32(implode($subset)));
                     $font_obj->open($tmp_name, Font_Binary_Stream::modeWrite);
                     $font_obj->encode(array("OS/2"));
                     $font_obj->close();
                     // Parse the new font to get cid2gid and widths
                     $font_obj = Font::load($tmp_name);
                     // Find Unicode char map table
                     $subtable = null;
                     foreach ($font_obj->getData("cmap", "subtables") as $_subtable) {
                         if ($_subtable["platformID"] == 0 || $_subtable["platformID"] == 3 && $_subtable["platformSpecificID"] == 1) {
                             $subtable = $_subtable;
                             break;
                         }
                     }
                     if ($subtable) {
                         $glyphIndexArray = $subtable["glyphIndexArray"];
                         $hmtx = $font_obj->getData("hmtx");
                         unset($glyphIndexArray[0xffff]);
                         $cidtogid = str_pad('', max(array_keys($glyphIndexArray)) * 2 + 1, "");
                         $font['CIDWidths'] = array();
                         foreach ($glyphIndexArray as $cid => $gid) {
                             if ($cid >= 0 && $cid < 0xffff && $gid) {
                                 $cidtogid[$cid * 2] = chr($gid >> 8);
                                 $cidtogid[$cid * 2 + 1] = chr($gid & 0xff);
                             }
                             $width = $font_obj->normalizeFUnit(isset($hmtx[$gid]) ? $hmtx[$gid][0] : $hmtx[0][0]);
                             $font['CIDWidths'][$cid] = $width;
                         }
                         $font['CIDtoGID'] = base64_encode(gzcompress($cidtogid));
                         $font['CIDtoGID_Compressed'] = true;
                         $data = file_get_contents($tmp_name);
                     } else {
                         $data = file_get_contents($fbfile);
                     }
                     $font_obj->close();
                     unlink($tmp_name);
                 }
                 // create the font descriptor
                 $this->numObj++;
                 $fontDescriptorId = $this->numObj;
                 $this->numObj++;
                 $pfbid = $this->numObj;
                 // determine flags (more than a little flakey, hopefully will not matter much)
                 $flags = 0;
                 if ($font['ItalicAngle'] != 0) {
                     $flags += pow(2, 6);
                 }
                 if ($font['IsFixedPitch'] === 'true') {
                     $flags += 1;
                 }
                 $flags += pow(2, 5);
                 // assume non-sybolic
                 $list = array('Ascent' => 'Ascender', 'CapHeight' => 'CapHeight', 'MissingWidth' => 'MissingWidth', 'Descent' => 'Descender', 'FontBBox' => 'FontBBox', 'ItalicAngle' => 'ItalicAngle');
                 $fdopt = array('Flags' => $flags, 'FontName' => $adobeFontName, 'StemV' => $stemV);
                 foreach ($list as $k => $v) {
                     if (isset($font[$v])) {
                         $fdopt[$k] = $font[$v];
                     }
                 }
                 if ($fbtype === 'pfb') {
                     $fdopt['FontFile'] = $pfbid;
                 } else {
                     if ($fbtype === 'ttf') {
                         $fdopt['FontFile2'] = $pfbid;
                     }
                 }
                 $this->o_fontDescriptor($fontDescriptorId, 'new', $fdopt);
                 // embed the font program
                 $this->o_contents($this->numObj, 'new');
                 $this->objects[$pfbid]['c'] .= $data;
                 // determine the cruicial lengths within this file
                 if ($fbtype === 'pfb') {
                     $l1 = strpos($data, 'eexec') + 6;
                     $l2 = strpos($data, '00000000') - $l1;
                     $l3 = mb_strlen($data, '8bit') - $l2 - $l1;
                     $this->o_contents($this->numObj, 'add', array('Length1' => $l1, 'Length2' => $l2, 'Length3' => $l3));
                 } else {
                     if ($fbtype == 'ttf') {
                         $l1 = mb_strlen($data, '8bit');
                         $this->o_contents($this->numObj, 'add', array('Length1' => $l1));
                     }
                 }
                 // tell the font object about all this new stuff
                 $tmp = array('BaseFont' => $adobeFontName, 'MissingWidth' => $missing_width, 'Widths' => $widthid, 'FirstChar' => $firstChar, 'LastChar' => $lastChar, 'FontDescriptor' => $fontDescriptorId);
                 if ($fbtype === 'ttf') {
                     $tmp['SubType'] = 'TrueType';
                 }
                 $this->addMessage("adding extra info to font.({$fontObj})");
                 foreach ($tmp as $fk => $fv) {
                     $this->addMessage("{$fk} : {$fv}");
                 }
                 $this->o_font($fontObj, 'add', $tmp);
             } else {
                 $this->addMessage('selectFont: pfb or ttf file not found, ok if this is one of the 14 standard fonts');
             }
             // also set the differences here, note that this means that these will take effect only the
             //first time that a font is selected, else they are ignored
             if (isset($options['differences'])) {
                 $font['differences'] = $options['differences'];
             }
         }
     }
     if ($set && isset($this->fonts[$fontName])) {
         // so if for some reason the font was not set in the last one then it will not be selected
         $this->currentBaseFont = $fontName;
         // the next lines mean that if a new font is selected, then the current text state will be
         // applied to it as well.
         $this->currentFont = $this->currentBaseFont;
         $this->currentFontNum = $this->fonts[$this->currentFont]['fontNum'];
         //$this->setCurrentFont();
     }
     return $this->currentFontNum;
     //return $this->numObj;
 }
Ejemplo n.º 27
0
 function encode($tags = array())
 {
     if (!self::$raw) {
         $tags = array_merge(array("head", "hhea", "cmap", "hmtx", "maxp", "glyf", "loca", "name", "post"), $tags);
     } else {
         $tags = array_keys($this->directory);
     }
     $num_tables = count($tags);
     $n = 16;
     // @todo
     Font::d("Tables : " . implode(", ", $tags));
     /** @var Font_Table_Directory_Entry[] $entries */
     $entries = array();
     foreach ($tags as $tag) {
         if (!isset($this->directory[$tag])) {
             Font::d("  >> '{$tag}' table doesn't exist");
             continue;
         }
         $entries[$tag] = $this->directory[$tag];
     }
     $this->header->data["numTables"] = $num_tables;
     $this->header->encode();
     $directory_offset = $this->pos();
     $offset = $directory_offset + $num_tables * $n;
     $this->seek($offset);
     $i = 0;
     foreach ($entries as $entry) {
         $entry->encode($directory_offset + $i * $n);
         $i++;
     }
 }
Ejemplo n.º 28
0
function CreateTestAnnots($doc)
{
    $ew = new ElementWriter();
    $eb = new ElementBuilder();
    $first_page = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $doc->PagePushBack($first_page);
    $ew->Begin($first_page, ElementWriter::e_overlay, false);
    // begin writing to this page
    $ew->End();
    // save changes to the current page
    //
    // Test of a free text annotation.
    //
    $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(10.0, 400.0, 160.0, 570.0));
    $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!");
    $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true);
    $txtannot->SetQuaddingFormat(0);
    $first_page->AnnotPushBack($txtannot);
    $txtannot->RefreshAppearance();
    $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(100.0, 100.0, 350.0, 500.0));
    $txtannot->SetContentRect(new Rect(200.0, 200.0, 350.0, 500.0));
    $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!");
    $txtannot->SetCalloutLinePoints(new Point(200.0, 300.0), new Point(150.0, 290.0), new Point(110.0, 110.0));
    $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true);
    $txtannot->SetEndingStyle(LineAnnot::e_ClosedArrow);
    $txtannot->SetColor(new ColorPt(0.0, 1.0, 0.0));
    $txtannot->SetQuaddingFormat(1);
    $first_page->AnnotPushBack($txtannot);
    $txtannot->RefreshAppearance();
    $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(400.0, 10.0, 550.0, 400.0));
    $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!");
    $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true);
    $txtannot->SetColor(new ColorPt(0.0, 0.0, 1.0));
    $txtannot->SetOpacity(0.2);
    $txtannot->SetQuaddingFormat(2);
    $first_page->AnnotPushBack($txtannot);
    $txtannot->RefreshAppearance();
    $page = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $doc->PagePushBack($page);
    $ew->Begin($page, ElementWriter::e_overlay, false);
    // begin writing to this page
    $eb->Reset();
    // Reset the GState to default
    $ew->End();
    // save changes to the current page
    //Create a Line annotation...
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(250.0, 250.0, 400.0, 400.0));
    $line->SetStartPoint(new Point(350.0, 270.0));
    $line->SetEndPoint(new Point(260.0, 370.0));
    $line->SetStartStyle(LineAnnot::e_Square);
    $line->SetEndStyle(LineAnnot::e_Circle);
    $line->SetColor(new ColorPt(0.3, 0.5, 0.0), 3);
    $line->SetContents("Dashed Captioned");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 2.0, 0.0, 0.0, array(2.0, 2.0)));
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(347.0, 377.0, 600.0, 600.0));
    $line->SetStartPoint(new Point(385.0, 410.0));
    $line->SetEndPoint(new Point(540.0, 555.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_OpenArrow);
    $line->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetContents("Inline Caption");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Inline);
    $line->SetLeaderLineExtensionLength(-4.0);
    $line->SetLeaderLineLength(-12.0);
    $line->SetLeaderLineOffset(2.0);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(10.0, 400.0, 200.0, 600.0));
    $line->SetStartPoint(new Point(25.0, 426.0));
    $line->SetEndPoint(new Point(180.0, 555.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_Square);
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $line->SetContents("Offset Caption");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->SetTextHOffset(-60);
    $line->SetTextVOffset(10);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(200.0, 10.0, 400.0, 70.0));
    $line->SetStartPoint(new Point(220.0, 25.0));
    $line->SetEndPoint(new Point(370.0, 60.0));
    $line->SetStartStyle(LineAnnot::e_Butt);
    $line->SetEndStyle(LineAnnot::e_OpenArrow);
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetContents("Regular Caption");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(200.0, 70.0, 400.0, 130.0));
    $line->SetStartPoint(new Point(220.0, 111.0));
    $line->SetEndPoint(new Point(370.0, 78.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_Diamond);
    $line->SetContents("Circle to Diamond");
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(10.0, 100.0, 160.0, 200.0));
    $line->SetStartPoint(new Point(15.0, 110.0));
    $line->SetEndPoint(new Point(150.0, 190.0));
    $line->SetStartStyle(LineAnnot::e_Slash);
    $line->SetEndStyle(LineAnnot::e_ClosedArrow);
    $line->SetContents("Slash to CArrow");
    $line->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 1.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(270.0, 270.0, 570.0, 433.0));
    $line->SetStartPoint(new Point(300.0, 400.0));
    $line->SetEndPoint(new Point(550.0, 300.0));
    $line->SetStartStyle(LineAnnot::e_RClosedArrow);
    $line->SetEndStyle(LineAnnot::e_ROpenArrow);
    $line->SetContents("ROpen & RClosed arrows");
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(195.0, 395.0, 205.0, 505.0));
    $line->SetStartPoint(new Point(200.0, 400.0));
    $line->SetEndPoint(new Point(200.0, 500.0));
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(55.0, 299.0, 150.0, 301.0));
    $line->SetStartPoint(new Point(55.0, 300.0));
    $line->SetEndPoint(new Point(155.0, 300.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_Circle);
    $line->SetContents("Caption that's longer than its line.");
    $line->SetColor(new ColorPt(1.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(300.0, 200.0, 390.0, 234.0));
    $line->SetStartPoint(new Point(310.0, 210.0));
    $line->SetEndPoint(new Point(380.0, 220.0));
    $line->SetColor(new ColorPt(0.0, 0.0, 0.0), 3);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $page3 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page3);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page3);
    $circle = Circle::Create($doc->GetSDFDoc(), new Rect(300.0, 300.0, 390.0, 350.0));
    $circle->SetColor(new ColorPt(0.0, 0.0, 0.0), 3);
    $circle->RefreshAppearance();
    $page3->AnnotPushBack($circle);
    $circle = Circle::Create($doc->GetSDFDoc(), new Rect(100.0, 100.0, 200.0, 200.0));
    $circle->SetColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $circle->SetInteriorColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $circle->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 3.0, 0.0, 0.0, array(2.0, 4.0)));
    $circle->SetPadding(2.0);
    $circle->RefreshAppearance();
    $page3->AnnotPushBack($circle);
    $sq = Square::Create($doc->GetSDFDoc(), new Rect(10.0, 200.0, 80.0, 300.0));
    $sq->SetColor(new ColorPt(0.0, 0.0, 0.0), 3);
    $sq->RefreshAppearance();
    $page3->AnnotPushBack($sq);
    $sq = Square::Create($doc->GetSDFDoc(), new Rect(500.0, 200.0, 580.0, 300.0));
    $sq->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $sq->SetInteriorColor(new ColorPt(0.0, 1.0, 1.0), 3);
    $sq->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 6.0, 0.0, 0.0, array(4.0, 2.0)));
    $sq->SetPadding(4.0);
    $sq->RefreshAppearance();
    $page3->AnnotPushBack($sq);
    $poly = Polygon::Create($doc->GetSDFDoc(), new Rect(5.0, 500.0, 125.0, 590.0));
    $poly->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $poly->SetInteriorColor(new ColorPt(1.0, 1.0, 0.0), 3);
    $poly->SetVertex(0, new Point(12.0, 510.0));
    $poly->SetVertex(1, new Point(100.0, 510.0));
    $poly->SetVertex(2, new Point(100.0, 555.0));
    $poly->SetVertex(3, new Point(35.0, 544.0));
    $poly->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 4.0, 0.0, 0.0));
    $poly->SetPadding(4.0);
    $poly->RefreshAppearance();
    $page3->AnnotPushBack($poly);
    $poly = PolyLine::Create($doc->GetSDFDoc(), new Rect(400.0, 10.0, 500.0, 90.0));
    $poly->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $poly->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $poly->SetVertex(0, new Point(405.0, 20.0));
    $poly->SetVertex(1, new Point(440.0, 40.0));
    $poly->SetVertex(2, new Point(410.0, 60.0));
    $poly->SetVertex(3, new Point(470.0, 80.0));
    $poly->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 2.0, 0.0, 0.0));
    $poly->SetPadding(4.0);
    $poly->SetStartStyle(LineAnnot::e_RClosedArrow);
    $poly->SetEndStyle(LineAnnot::e_ClosedArrow);
    $poly->RefreshAppearance();
    $page3->AnnotPushBack($poly);
    $lk = Link::Create($doc->GetSDFDoc(), new Rect(5.0, 5.0, 55.0, 24.0));
    //$lk->SetColor( new ColorPt(0.0,1.0,0.0), 3.0 );
    $lk->RefreshAppearance();
    $page3->AnnotPushBack($lk);
    $page4 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page4);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page4);
    $ew->Begin($page4);
    $font = Font::Create($doc->GetSDFDoc(), Font::e_helvetica);
    $element = $eb->CreateTextBegin($font, 16.0);
    $element->SetPathFill(true);
    $ew->WriteElement($element);
    $element = $eb->CreateTextRun("Some random text on the page", $font, 16.0);
    $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 100.0, 500.0);
    $ew->WriteElement($element);
    $ew->WriteElement($eb->CreateTextEnd());
    $ew->End();
    $hl = HighlightAnnot::Create($doc->GetSDFDoc(), new Rect(100.0, 490.0, 150.0, 515.0));
    $hl->SetColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $hl->RefreshAppearance();
    $page4->AnnotPushBack($hl);
    $sq = Squiggly::Create($doc->GetSDFDoc(), new Rect(100.0, 450.0, 250.0, 600.0));
    //$sq->SetColor( new ColorPt(1.0,0.0,0.0), 3 );
    $sq->SetQuadPoint(0, new QuadPoint(new Point(122.0, 455.0), new Point(240.0, 545.0), new Point(230.0, 595.0), new Point(101.0, 500.0)));
    $sq->RefreshAppearance();
    $page4->AnnotPushBack($sq);
    $cr = Caret::Create($doc->GetSDFDoc(), new Rect(100.0, 40.0, 129.0, 69.0));
    $cr->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $cr->SetSymbol("P");
    $cr->RefreshAppearance();
    $page4->AnnotPushBack($cr);
    $page5 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page5);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page5);
    global $input_path;
    $fs = FileSpec::Create($doc->GetSDFDoc(), $input_path . "butterfly.png", false);
    $page6 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page6);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page6);
    for ($ipage = 0; $ipage < 2; ++$ipage) {
        for ($iann = 0; $iann < 100; $iann++) {
            if (!($iann > FileAttachment::e_Tag)) {
                $fa = FileAttachment::Create($doc->GetSDFDoc(), new Rect(50.0 + 50.0 * (double) $iann, 100.0, 70.0 + 50.0 * (double) $iann, 120.0), $fs, $iann);
                if ($ipage) {
                    $fa->SetColor(new ColorPt(1.0, 1.0, 0.0));
                }
                $fa->RefreshAppearance();
                if ($ipage == 0) {
                    $page5->AnnotPushBack($fa);
                } else {
                    $page6->AnnotPushBack($fa);
                }
            }
            if ($iann > Text::e_Note) {
                break;
            }
            $txt = Text::Create($doc->GetSDFDoc(), new Rect(10.0 + (double) $iann * 50.0, 200.0, 30.0 + (double) $iann * 50.0, 220.0));
            $txt->SetIcon($iann);
            $txt->SetContents($txt->GetIconName());
            if ($ipage) {
                $txt->SetColor(new ColorPt(1.0, 1.0, 0.0));
            }
            $txt->RefreshAppearance();
            if ($ipage == 0) {
                $page5->AnnotPushBack($txt);
            } else {
                $page6->AnnotPushBack($txt);
            }
        }
    }
    $txt = Text::Create($doc->GetSDFDoc(), new Rect(10.0, 20.0, 30.0, 40.0));
    $txt->SetIcon("UserIcon");
    $txt->SetContents("User defined icon, unrecognized by appearance generator");
    $txt->SetColor(new ColorPt(0.0, 1.0, 0.0));
    $txt->RefreshAppearance();
    $page6->AnnotPushBack($txt);
    $ink = Ink::Create($doc->GetSDFDoc(), new Rect(100.0, 400.0, 200.0, 550.0));
    $ink->SetColor(new ColorPt(0.0, 0.0, 1.0));
    $ink->SetPoint(1, 3, new Point(220.0, 505.0));
    $ink->SetPoint(1, 0, new Point(100.0, 490.0));
    $ink->SetPoint(0, 1, new Point(120.0, 410.0));
    $ink->SetPoint(0, 0, new Point(100.0, 400.0));
    $ink->SetPoint(1, 2, new Point(180.0, 490.0));
    $ink->SetPoint(1, 1, new Point(140.0, 440.0));
    $ink->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 3.0, 0.0, 0.0));
    $ink->RefreshAppearance();
    $page6->AnnotPushBack($ink);
    $page7 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page7);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page7);
    $snd = Sound::Create($doc->GetSDFDoc(), new Rect(100.0, 500.0, 120.0, 520.0));
    $snd->SetColor(new ColorPt(1.0, 1.0, 0.0));
    $snd->SetIcon(Sound::e_Speaker);
    $snd->RefreshAppearance();
    $page7->AnnotPushBack($snd);
    $snd = Sound::Create($doc->GetSDFDoc(), new Rect(200.0, 500.0, 220.0, 520.0));
    $snd->SetColor(new ColorPt(1.0, 1.0, 0.0));
    $snd->SetIcon(Sound::e_Mic);
    $snd->RefreshAppearance();
    $page7->AnnotPushBack($snd);
    $page8 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page8);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page8);
    for ($ipage = 0; $ipage < 2; ++$ipage) {
        $px = 5;
        $py = 520;
        for ($istamp = RubberStamp::e_Approved; $istamp <= RubberStamp::e_Draft; $istamp = $istamp + 1) {
            $st = RubberStamp::Create($doc->GetSDFDoc(), new Rect(1.0, 1.0, 100.0, 100.0));
            $st->SetIcon($istamp);
            $st->SetContents($st->GetIconName());
            $st->SetRect(new Rect((double) $px, (double) $py, (double) $px + 100.0, (double) $py + 25.0));
            $py -= 100;
            if ($py < 0) {
                $py = 520;
                $px += 200;
            }
            if ($ipage == 0) {
                //$page7->AnnotPushBack( $st );
            } else {
                $page8->AnnotPushBack($st);
                $st->RefreshAppearance();
            }
        }
    }
    $st = RubberStamp::Create($doc->GetSDFDoc(), new Rect(400.0, 5.0, 550.0, 45.0));
    $st->SetIcon("UserStamp");
    $st->SetContents("User defined stamp");
    $page8->AnnotPushBack($st);
    $st->RefreshAppearance();
}
Ejemplo n.º 29
0
 /**
  * @param string $family
  * @param array $styles
  * @param integer[] $color
  * @return boolean
  */
 public function startStyleEmulation($family, array $styles, array $color)
 {
     $need_emulate = in_array('bold', $styles) && Font::isBuiltinUnicodeFont($family);
     if (!$need_emulate) {
         return false;
     } else {
         $this->pdf->setDrawColorArray($color);
         $this->pdf->setTextRenderingMode($this->pdf->GetLineWidth() * 0.1);
         return true;
     }
 }
Ejemplo n.º 30
0
 /**
  * @param Font $font
  *
  * @return Font
  */
 private function setFontParameters(Font $font)
 {
     $parameters = $this->extractHeadlineParameters($font->getFileCollection());
     $font->setSignature($parameters['signature'])->setHardBlank($parameters['hard_blank'])->setHeight($parameters['height'])->setMaxLength($parameters['max_length'])->setOldLayout($parameters['old_layout'])->setCommentLines($parameters['comment_lines'])->setPrintDirection($parameters['print_direction'])->setFullLayout($parameters['full_layout']);
     return $font;
 }