Giter Club home page Giter Club logo

php-font-parser's Issues

Memory exceed issue

I am trying to get glyph paths of multi letters in one Ajax call.
Simply here is what I want:
[input] $text: "a sentence", $font: 'arial'
[output] array of glyphs

Here is my code:

// * VectorFont.php * //

    require_once("fontparse.php");
    class VectorFont {

    protected $font;

    public function loadFont($font)
    {
        $this->font = new \OTTTFont($font);
    }
    public function getGlyph($letter)
    {
        $data = null;
        if($this->font) {
            $data = $this->font->get_glyph($letter);
        }
        return $data;
    }
    }

// * test.php * //

    getGlyphs('multiple letters', 'arial'); // memory exceed error

    // receive multi-letter text as an input and return array of glyphs
    public function getGlyphs($text, $font)
    {
        $glyphs = array();
        $this->vectorFont = new VectorFont();
        $this->vectorFont->loadFont($font.'.ttf');
        for($i=0 ; $i<mb_strlen($text) ; $i++) {

            // avoid error that occurs if call "get_glyph" with same letter more than once
            $dupIndex = $this->findFirstDuplication(mb_substr($text, $i, 1), $text);

            if($dupIndex >= 0 && $dupIndex < $i) {
                // if duplicated letter existed previously, copy previous data 
                array_push($glyphs, $glyphs[$dupIndex]);

            } else {
                $glyph = $this->vectorFont->getGlyph(mb_substr($text, $i, 1));

                if($glyph) {
                    array_push($glyphs, $glyph);
                } else {
                    array_push($glyphs, "");
                }
            }
        }
        return $glyphs;
    }

First of all, an error occurs if call "get_glyph" with same letter more than once. But I can write work around to avoid this problem, so this is not a big problem

But, I can hardly fix the memory issue. I don't understand why memory usage exceeds the limit even though font object is loaded just once at first. Do you have an idea to fix this problem?

Font location

Is there a reason for the font directory? Coulnd't be useful to load and parse the installed fonts?

glyph fetcher should cache per font

the glyph fetcher currently caches on character, rather than on character per font, so using multiple fonts on the same run for the same character causes faulty runs.

Way to enhance speed for string input

When processing multiple glyphs, the processing speed is so slow and ,in my case, server's memory exceeds limit so cannot get desired result properly or quickly.
I hope this is a solution for this problem.

foreach ($text as $letter) {
    while($glyph) {
        if($glyph->letter == $letter) {
            echo $glyph->d;
        }
        $glyph = nextGlygh();
    }
}

Above algorithm makes server soooo busy because searching element in stdClass and looping over time allocates too much memory in the system. I don't know why the php creators wrote like this, but this is the nature of php just like you said.

$count = strlen($text);
$glyph = firstGlyph();
while($glyph && $count>0) {
    foreach ($text as $letter) {
        if($glyph->letter == $letter) {
            $cache[$letter] = $glyph->d;
            $count--;
        }
    }
    $glyph = nextGlygh();
}

foreach ($text as $letter) {
    echo $cache[$letter];
}

This algorithm is way faster and does not allocate wasteful memory. Hope this helps to enhance your library.

high ascii chars

hi

Re your sample code which looks for letter "g" ... what if I needed to check for a glyph much higher up, eg U+232B for example?

Thanks, Ian

Fatal error in glyph.php

I downloaded and tried to test a font but encountered errors in the font test. The first was an easy fix. There is a missing parenthesis on line 34. But it was followed up by this:
font header data:
header:
{version: OTTO, number of tables: 14, search range: 128, entry selector: 3, range shift: 96}
tables:
{tag: BASE, checkSum: 1063407546, offset: 4284, length: 52}
{tag: CFF , checkSum: 838456334, offset: 4336, length: 15280}
{tag: DSIG, checkSum: 2007147259, offset: 22056, length: 5744}
{tag: GPOS, checkSum: 28576472, offset: 19616, length: 1554}
{tag: GSUB, checkSum: 1843949587, offset: 21172, length: 812}
{tag: LINO, checkSum: -253362844, offset: 21984, length: 72}
{tag: OS/2, checkSum: 2041581385, offset: 336, length: 96}
{tag: cmap, checkSum: 2129153568, offset: 2308, length: 932}
{tag: head, checkSum: -603480306, offset: 236, length: 54}
{tag: hhea, checkSum: 117441355, offset: 292, length: 36}
{tag: hmtx, checkSum: 105393449, offset: 3240, length: 1012}
{tag: maxp, checkSum: 16601088, offset: 328, length: 6}
{tag: name, checkSum: 1654205279, offset: 432, length: 1874}
{tag: post, checkSum: -4718542, offset: 4252, length: 32}


Fatal error: Call to a member function computeBounds() on a non-object in D:\websites\vitt.easypic.se\fonttest\Font parser\OTF data\Glyph classes\glyph.php on line 31

This is on Windows IIS 7.5 using PHP 5.3+

Class 'Monolog\Formatter\LineFormatter' not found ?

Hi,

When I am running "fonttest.php", I am getting an error:
Fatal error: Class 'Monolog\Formatter\LineFormatter' not found in /www/image_module_testbed_new/fontparser/Font parser/OTF data/Glyph classes/glyphrules.php on line 44

Font header is nicely printed out. But "$data = $font->get_glyph($letter);" makes such error.
And I can hardly fix it by myself.. Please help

multiple consults fail after 1 letter

The following code fails after the first letter is retrieved:

$text = "After all this time...";
$letters = str_split($text);
print_r($letters);

foreach($letters as $letter) {
    $json = false;
    while($json === false && count($fonts)>0) {
        $font = new OTTTFont(array_pop($fonts));
        echo "font header data:\n" . $font->toString() . "\n";
        $data = $font->get_glyph($letter);
        if($data!==false) {
            $json = $data->toJSON();
        }
    }
}

The first letter is found, then the parser reports the font does not support "f". Splitting the string "fter all this time..." then finds the "f" but reports the font does not support "t", etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.