Bug in CustomTypeFace


#1

It seems the CustomTypeface serialization is not a 1:1 process.
In the attached image, top half show standard Arial font from system (not using custom L&F)
Bottom half shows with Arial glyph serialized from CustomTypeface and then loaded in a custom L&F.

The other code doesn’t change, but it seem the baseline is lower on the bottom half, and the text “touch” the bottom rectangle.


#2

Also, I think the CustomTypeface(InputStream &) should be CustomTypeface(const InputStream &).
This force to have an object elsewhere, while the constructor don’t need the reference anymore after execution.


#3

Did you call setCharacteristics() to make sure it had it the correct ascent before saving it?

I think you may be a little bit muddled there… It would be impossible to read from a const InputStream.


#4

I have no idea about the ascent (what is the good value ?). The code does this:

// Saving
CustomTypeface customTypeface;
customTypeface.addGlyphsFromOtherTypeface (*font.getTypeface(), 0, glyphCount);
customTypeface.writeToStream (*stream);

// Loading 
const Typeface::Ptr getTypefaceForFont (const Font& font)
{
[...]
   MemoryStream ins(...);
   return new CustomTypeface tf(ins);
}

So nothing strange in there, I’m not dealing with the generated stream in anyway.


#5

Yes, sorry… it’s late. I’ve read it as a MemoryBlock.


#6

If you’re copying glyphs from another typeface, then you’d need to also copy its ascent value for the result to look the same.


#7

Is there any reason why it’s not done dynamically ?
I mean, you can’t add glyphs with different ascent anyway with the current interface, as there is no way to set the input ascent.
So it’s probably better if addGlyphsFromOtherTypeface called setCharacteristics from the first given typeface (first glyph added) ?


#8

Yes, I guess it probably could do that automatically.