CustomTypeface errors


#1
  1. I tried some fonts exported on windows using the FontSerializer GUI, it works on windows
  2. I moved the code to MAC, and i get a crash like that:
#0	0xffff088c in __memcpy
#1	0x003dae6c in juce::MemoryInputStream::read at juce_MemoryInputStream.cpp:74
#2	0x003da14f in juce::GZIPDecompressorInputStream::read at juce_GZIPDecompressorInputStream.cpp:224
#3	0x003f6663 in juce::BufferedInputStream::ensureBuffered at juce_BufferedInputStream.cpp:127
#4	0x003f682a in juce::BufferedInputStream::read at juce_BufferedInputStream.cpp:149
#5	0x003a5daf in juce::InputStream::readByte at juce_InputStream.cpp:38
#6	0x0041baf3 in juce::InputStream::readString at juce_InputStream.cpp:165
#7	0x0041bc9a in juce::BufferedInputStream::readString at juce_BufferedInputStream.cpp:199
#8	0x004839e1 in juce::CustomTypeface::CustomTypeface at juce_Typeface.cpp:150
#9	0x00286e04 in getBuiltInFont at CtrlrUtilities.cpp:496

i built the FontSerializer on the mac, and whenever i want to export a font i get a crash, this time

#1	0x003abbc5 in juce::MacTypeface::getOutlineForGlyph at juce_mac_Fonts.mm:221
#2	0x000eba11 in juce::CustomTypeface::addGlyphsFromOtherTypeface at juce_Typeface.cpp:296
#3	0x0000c2ff in MainComponent::exportFonts at MainComponent.cpp:175
#4	0x0000ca9d in MainComponent::buttonClicked at MainComponent.cpp:130
#5	0x002c2d22 in juce::ListenerList<juce::Button::Listener, juce::Array<juce::Button::Listener*, juce::DummyCriticalSection> >::callChecked<juce::Component::BailOutChecker, juce::Button*> at juce_ListenerList.h:181
#6	0x002166b0 in juce::Button::sendClickMessage at juce_Button.cpp:384

the code that does that

String fontName=cbFonts->getText();//T("Arial.ttf");

	Font font(fontName , 16.0f, Font::plain);
	// copy the font-properties to a CustomTypeface
    CustomTypeface customTypeface;
    customTypeface.setCharacteristics(fontName, font.getAscent(),font.isBold(), font.isItalic(), ' ');
    // Here's the important part: copy all glyphs to a new instance of CustomTypeface
	if (font.getTypeface())
	{
		customTypeface.addGlyphsFromOtherTypeface( *font.getTypeface(), 0, 256);
	}
	else 
	{

		Logger::writeToLog ("Can't fetch typeface");

	}
	MemoryOutputStream str;
	customTypeface.writeToStream(str);
	uint8 *p=(uint8*)str.getData();

is this a bug in my code, or did something change in the MAC/Font handling routines and we should update our code.


#2

The first problem looks like a bug in your code - I can’t really see how you’d get that unless you give it a duff InputStream to read from…?

In the second one, perhaps you’re requesting glyphs that don’t exist, and it might just need a bit of extra checking, e.g.

[code] bool getOutlineForGlyph (int glyphNumber, Path& path)
{
jassert (path.isEmpty()); // we might need to apply a transform to the path, so this must be empty

    CGPathRef pathRef = CTFontCreatePathForGlyph (ctFontRef, (CGGlyph) glyphNumber, &renderingTransform);
    
    if (pathRef == 0)
        return false;

[/code]

?


#3

the first part is a embedded piece of const char * (jucer style) data,


extern const char *lcd_data;
const int lcd_dataSize = 29121;

and a function to transform in to a Font()
Font getBuiltInFont(const char *fontData, const int fontDataSize)
{
	MemoryInputStream is(fontData, fontDataSize, false);
	CustomTypeface *newTypeface = new CustomTypeface(is);
	Font myFont(newTypeface);
	return (myFont);
}

this stuff works fine on Windows, no assertions/warnings this crash happens on OSX only.


#4

I think it must be because of slightly different memcpy behaviour on the different machines - I’ll tidy that up, thanks.