Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typography's Trimmable Feature #187

Closed
prepare opened this issue Feb 1, 2020 · 3 comments
Closed

Typography's Trimmable Feature #187

prepare opened this issue Feb 1, 2020 · 3 comments
Labels

Comments

@prepare
Copy link
Member

prepare commented Feb 1, 2020

see verybadcat/CSharpMath#107

I copy this image from that link.

mem_usage

pic 1

@prepare prepare changed the title Unload unused object from Mem Reduce Memory Usage Feb 2, 2020
@prepare prepare changed the title Reduce Memory Usage Reduce Memory Usage on Cff Font Feb 2, 2020
@prepare
Copy link
Member Author

prepare commented Feb 2, 2020

Plan:

  1. List<Type2Instruction> could be unload after you create a glyph outline from it.
  2. Unload many openfont tables that are not need by user
  3. Optimize List<Type2Instruction>

@prepare
Copy link
Member Author

prepare commented Feb 2, 2020

Before I add unload features Trimmable features.
Today I push an optimization on CFF Instructions. (3)

(see : 8bcde3c)

and

I think the new compact form of CFF instructions will

  1. reduce memory usage.
  2. not affect the performance.
  3. still compat with CFF standard

in this version,
Instruction in compact form use space about 44% of original one

@prepare prepare changed the title Reduce Memory Usage on Cff Font Typography's Trimmable Feature Jun 28, 2020
@prepare prepare added the INFO label Jun 28, 2020
@prepare
Copy link
Member Author

prepare commented Jun 28, 2020

Typography's Trimmable Feature

trimmable_targets

pic 2: from pic1, the objects in red rect are the targets of the Trimmable feature

see Trimmable feature on latest master

This can be used with ttf, otf (cff) , svg, bitmap font.

After TrimDown(), the Typeface removes 'glyph-building instructions' of all kinds.
=>It can't be used for generating glyph outline output.

BUT It preserves the 'TextLayout information' (eg. GSUB, GPOS) =>.
the trimmed typeface can be used for text-layout process.

you can 'restore' the information again with RestoreUp()

Hope this will reduce memory usuage :)

using Typography.OpenFont;
using Typography.OpenFont.Trimmable;
 

//....
//...

    static void TestLoadAndReload(string filename)
        {

            //Trimmable feature tests:           
            //[A] read the font file as usual => get full information about the font 
            Typeface typeface = null;
            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                //read in full mode
                OpenFontReader openFontReader = new OpenFontReader();
                typeface = openFontReader.Read(fs);
            }

            //before
            bool hasColor1 = typeface.HasColorTable();
            bool hasSvg1 = typeface.HasSvgTable();
            bool hasCff1 = typeface.IsCffFont;
            TrimMode glyphMode1 = typeface.GetTrimMode();
            Glyph g1_1 = typeface.GetGlyph(1);

            //---------------------------------------------------------
            //[B] if you create paths from glyphs, or atlas from glyph 
            //   and you don't want any glyph-building-detail (eg. to reduce memory usuage)
            //   but you still want to use the typeface for text-layout
            //   you can trim it down
            RestoreTicket ticket = typeface.TrimDown();//***

            //[C] you can GetGlyph() but this is ANOTHER NEW GLYPH
            //without building instruction( eg. no cff,ttf,svg data,bitmap)
            //

            Glyph g1_2 = typeface.GetGlyph(1);

            //** if you cache the the old version of 'full-info' glyph**
            // the info is still cache on the old glyph and it can be used as 'full-info' glyph
            // TrimDown() DOES NOT go to delete that glyph.

            bool hasColor2 = typeface.HasColorTable();
            bool hasSvg2 = typeface.HasSvgTable();
            bool hasCff2 = typeface.IsCffFont;

            TrimMode glyphMode2 = typeface.GetTrimMode();
            //---------------------------------------------------------

            //[D] can we load glyph detail again?
            //yes=> this need 'ticket' from latest TrimDown()
            //if you don't have it, you can't restore it.           

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                typeface.RestoreUp(ticket, fs);
            }
        }

Trimmable test, FormTestTrimmableFeature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant