Typography's Trimmable Feature
prepare opened this issue · 3 comments
Plan:
- List<Type2Instruction> could be unload after you create a glyph outline from it.
- Unload many openfont tables that are not need by user
- Optimize List<Type2Instruction>
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
- reduce memory usage.
- not affect the performance.
- still compat with CFF standard
in this version,
Instruction in compact form use space about 44% of original one
Typography's Trimmable Feature
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