king514jy / purepdf

Automatically exported from code.google.com/p/purepdf
0 stars 0 forks source link

Embedding fonts fails with Type Coercion error. Static references a problem? #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to embed fonts using the example provided.
2. Compile and run.

My sample code is attached. Key elements are:

[Embed(source = '../../../../../bin/fonts/times.ttf', mimeType = 
'application/octet-stream')]
public static var My_Times_New_Roman__Regular:Class;

FontsResourceFactory.getInstance().registerFont("My_Times_New_Roman__Regular", 
ByteArray(new My_Times_New_Roman__Regular()));

Throws runtime error:

[Fault] exception, information=TypeError: Error #1034: Type Coercion failed: 
cannot convert 
jcfx.prinkk.ondesign.pdfexporter::PdfFonts_My_Times_New_Roman__Regular@acabce1 
to flash.utils.ByteArray.

What version of the product are you using? On what operating system?

PurePdf 0.71.20100506
Flex 4.6.0, Air 3.1
FlashDevelop 4.0.1 on Win7 x64

Please provide any additional information below.

The only thing I can think of that might be causing this are the static 
modifiers, but I can't imagine why?

Original issue reported on code.google.com by jcfxj...@gmail.com on 30 Jan 2012 at 8:00

Attachments:

GoogleCodeExporter commented 8 years ago
Oh, and I tried it first without the explicit cast to ByteArray() - same result.

Original comment by jcfxj...@gmail.com on 30 Jan 2012 at 8:00

GoogleCodeExporter commented 8 years ago
I've found a workaround for this. Instead of casting to ByteArray, cast the 
font class to ByteArrayAsset:

FontsResourceFactory.getInstance().registerFont("My_Times_New_Roman__Regular.ttf
", ByteArrayAsset(new My_Times_New_Roman__Regular()));

(Also, the registered font name needs the .ttf extension, although this is not 
what was causing the error).

Hope this is useful,

Jude Fisher / JcFx.Eu

Original comment by jcfxj...@gmail.com on 31 Jan 2012 at 1:01