|
|
View Full Version : Embedded fonts in LRF WORKING
igorsk 01-09-2007, 10:17 AM Well, after several evenings in IDA/OllyDbg I finally got it working. Due to several bugs in the Reader's LRF parser, embedded fonts only work for some specific combinations of parameters.
See the attached file for an example of such LRF. It has embedded Courier New font and a text string in Russian.
I have not yet found a way to generate such files with available converters. This one was generated by makelrf and then edited manually in a hex editor. So here are the technical details for the converter authors:
1. Font stream should added as a Font object (type 0x19). The stream must be either compressed or scrambled (or both), otherwise the parser will fail to load it.
2. Reference to the font object must be added to the root BookAtr object with the tag F5D8. It should be possible to add several fonts in this way, though I haven't tested it.
3. TextAtr object which sets the style for rendering the text, must specify the full TrueType font name (with tag F516), not the name from the Font object.
Alexander Turcic 01-09-2007, 10:34 AM Congrats igorsk! ;)
Btw, I remember OllyDebug very well ;) Do you know Softice? It's used to be even more powerful, alas it's not supported any longer.
obelix 01-09-2007, 10:52 AM Well, after several evenings in IDA/OllyDbg I finally got it working. Due to several bugs in the Reader's LRF parser, embedded fonts only work for some specific combinations of parameters.
See the attached file for an example of such LRF. It has embedded Courier New font and a text string in Russian.
I have not yet found a way to generate such files with available converters. This one was generated by makelrf and then edited manually in a hex editor. So here are the technical details for the converter authors:
1. Font stream should added as a Font object (type 0x19). The stream must be either compressed or scrambled (or both), otherwise the parser will fail to load it.
2. Reference to the font object must be added to the root BookAtr object with the tag F5D8. It should be possible to add several fonts in this way, though I haven't tested it.
3. TextAtr object which sets the style for rendering the text, must specify the full TrueType font name (with tag F516), not the name from the Font object.
Great (as usual)!
It works! I tried lrf files with embeded fonts taken from yahoo group and did see different fonts in Librie for Windows, but Reader did not recognize them and used default fonts instead. Now we know that embeded fonts really work for Reader also. Incredible! I'll include this to my lrs_to_lrf parser. Do you know correct lrs records to pass it to the parsers (to follow lrs standrads)?
igorsk 01-09-2007, 11:02 AM Do you know correct lrs records to pass it to the parsers (to follow lrs standrads)?
Add this to the BookStyle element:
<RegistFont fontname="Courier New" file="Courier New.ttf" encoding="TTF" fontfilename="Courier New.ttf"/>
LRS2LRF does produce a proper LRF from such LRS, but since it doesn't compress or scramble the font, Reader fails to display it.
I will also update LRF2LRS so that it correctly decompiles such files.
scotty1024 01-09-2007, 04:42 PM Excellent work igorsk! (I'm adding this to my parser as well)
This now begs the question: is it legal to embed a particular font?
Adobe has worked deals to license embedding fonts into PDF's but I seriously doubt Sony has done the same for LRF...
You may wish to check the license for any fonts you wish to embed prior to publishing any LRF document with those fonts embedded in it.
igorsk 01-09-2007, 05:27 PM You can check if the font allows embedding with Font properties extension:
http://www.microsoft.com/typography/TrueTypeProperty21.mspx
scotty1024 01-09-2007, 05:47 PM Probably a good warning for the parser to toss to the user during parsing. I'll be sure to check and warn.
obelix 01-10-2007, 09:12 AM Several fonts also work OK.
Lrs to Lrf parser with font support,
http://www.msh-tools.com/ebook/MSH_LRSParser.zip
example with 2 embedded fonts:
http://www.msh-tools.com/ebook/testfonts.zip
You can check if the font allows embedding with Font properties extension:
http://www.microsoft.com/typography/TrueTypeProperty21.mspx
It can be done in more simple way: GetFontData with zero arguments.
esperanc 02-04-2007, 04:24 PM Several fonts also work OK.
Lrs to Lrf parser with font support,
http://www.msh-tools.com/ebook/MSH_LRSParser.zip
example with 2 embedded fonts:
http://www.msh-tools.com/ebook/testfonts.zip
This is great stuff, but I´ve had some problems when embedding the 4 variants of the same font into a test book. I´ve embedded Palatino, Palatino Bold, Palatino Italic and Palatino Bold Italic into the same document and switched between them with Span tags. All worked, except for the Bold Italic one. Here´s the example files:
http://orion.lcg.ufrj.br/~esperanc/testfonts.zip
Incidentally, I´ve noticed that the lrf file generated with MSH_LRSParser duplicated all stop signs at the end of the sentences. Does anyone know why?
esperanc 02-11-2007, 09:09 AM I would love use font embedding to obtain real bold and italic text rather than the "fake" effect employed in the reader. Unfortunately, it seems that <Span> tags are processed incorrectly by MSH_lrsparser when the fontfacename attribute is used. The problem is that an extra period (".") appears just after the span.
See, for instance the following code:
<TextBlock blockstyle="211" objid="212" textstyle="210">
<P>
<Span fontweight="900"> No problem with other attributes </Span>
<Span fontfacename="Courier10 BT Roman"> Extra period when switching to Courier </Span>
<Span fontfacename="Swis721 BT Roman" fontweight="900"> Same thing when switching to Sans Serif </Span>
</P>
</TextBlock>
The result is shown in the Figure attached.
obelix 02-12-2007, 10:29 PM I would love use font embedding to obtain real bold and italic text rather than the "fake" effect employed in the reader. Unfortunately, it seems that <Span> tags are processed incorrectly by MSH_lrsparser when the fontfacename attribute is used. The problem is that an extra period (".") appears just after the span.
See, for instance the following code:
<TextBlock blockstyle="211" objid="212" textstyle="210">
<P>
<Span fontweight="900"> No problem with other attributes </Span>
<Span fontfacename="Courier10 BT Roman"> Extra period when switching to Courier </Span>
<Span fontfacename="Swis721 BT Roman" fontweight="900"> Same thing when switching to Sans Serif </Span>
</P>
</TextBlock>
The result is shown in the Figure attached.
Just converted your example. No periods. Hard to believe that parser adds something extra, its against principles of its operation. May be your device is doing it? What program are you using to see lrf preview?
Here is my example (both lrs and lrf) and the screenshoot:
esperanc 02-13-2007, 07:29 PM Just converted your example. No periods. Hard to believe that parser adds something extra, its against principles of its operation. May be your device is doing it? What program are you using to see lrf preview?
Here is my example (both lrs and lrf) and the screenshoot:
Thanks for your reply, Obelix. I discovered what went wrong: my textstyle had an attribute called empdotscode="0x002e", which caused the extra dot. I copied the textstyle from some other lrs I had converted from the example books in my reader. I have no idea of what exactly this attribute does other than causing this...
On the other hand, I still have the problem with multiple embedded fonts. Here´s the relevant code (see also the two complete example files attached)
<Main>
<Page evenheaderid="207" objid="209" oddheaderid="207" pagestyle="208">
<TextBlock blockstyle="211" objid="212" textstyle="210">
<P>
<Span fontfacename="Palatino Linotype">Some text written in Palatino Regular. </Span>
<Span fontfacename="Palatino Linotype Bold">Some text written in Palatino Bold. </Span>
<Span fontfacename="Palatino Linotype Bold Italic">Some text written in Palatino Bold Italic. </Span>
<Span fontfacename="Palatino Linotype Italic">Some text written in Palatino Italic. </Span>
</P>
</TextBlock>
</Page>
</Main>
<Template version="1.0">
</Template>
<Style>
<BookStyle>
<SetDefault empdotsfontname="Dutch801 Rm BT Roman" empdotsposition="before" emplineposition="before" emplinetype="solid" rubyadjust="none" rubyalign="start" rubyoverhang="none" setwaitprop="noreplay" />
<BookSetting bindingdirection="Lr" colordepth="24" dpi="1600" screenheight="800" screenwidth="600" />
<RegistFont encoding="TTF" file="c:\windows\fonts\pala.ttf" fontfilename="aaa" fontname="Palatino Linotype" objid="200" />
<RegistFont encoding="TTF" file="c:\windows\fonts\palab.ttf" fontfilename="aaa" fontname="Palatino Linotype Bold" objid="201" />
<RegistFont encoding="TTF" file="c:\windows\fonts\palabi.ttf" fontfilename="aaa" fontname="Palatino Linotype Bold Italic" objid="202" />
<RegistFont encoding="TTF" file="c:\windows\fonts\palai.ttf" fontfilename="aaa" fontname="Palatino Linotype Italic" objid="203" />
</BookStyle>
The result is that the first three embedded RegistFont work, but not the fourth. On the other hand, if smaller fonts are used (4 variants of Vera, for instance, all four fonts work). I think this has something to do with the size or the complexity of the fonts. Have any of you noticed this?
The result is that the first three embedded RegistFont work, but not the fourth. On the other hand, if smaller fonts are used (4 variants of Vera, for instance, all four fonts work). I think this has something to do with the size or the complexity of the fonts. Have any of you noticed this?
You are using the same fontfilename="aaa" for all the fonts.
igorsk 02-14-2007, 02:15 AM In Reader, "fontfilename" attribute is ignored, and even "fontname". It uses the actual font names from the TTF.
The Raven 03-17-2007, 01:19 PM Is the source code available for the LRStoLRF parser. I work on a Mac and would love to be able to run this utility on my machine.
Thanks for all your support....
Hello,
I have just bought PRS-500 and joined to forum.
Would somebody poin me to comprehensive (step-by-step) information how to install font on the reader. ARussian fonts would be especial helpful.
NatCh 03-21-2007, 10:32 AM Welcome to MobileRead, lmm!
Unfortunately, there's not really a step-by-step, guide. I was hoping someone would make a tool to do this, myself (not my type of programming, unfortunately), but it hasn't come to pass yet. About the closest we've got is the discussion in this thread (http://www.mobileread.com/forums/showthread.php?t=8051), which is long an kinda convoluted, but perhaps it will be of some help.
Hello,
I have just bought PRS-500 and joined to forum.
Would somebody poin me to comprehensive (step-by-step) information how to install font on the reader. ARussian fonts would be especial helpful.
http://www.the-ebook.org/forum/viewtopic.php?t=5913
Thank you,
It looks great! I'll give a trial.
NatCh 03-21-2007, 12:22 PM Nice, vvv, any chance one of those who read Russian could translate the instructions to English, for the Linguistically Challenged (like me)? BabelFish makes a pretty good hash of them .... :sad:
Honza 03-23-2007, 04:59 AM Nice, vvv, any chance one of those who read Russian could translate the instructions to English, for the Linguistically Challenged (like me)? BabelFish makes a pretty good hash of them .... :sad:
I don't know Russian so well, but I feel I just wrote the same thing in this post (http://www.mobileread.com/forums/showthread.php?p=61660#post61660) in English a few days ago. But, as igosk mentioned, this procedure works only with Reader without the firmware update. Does anybody know about updating fonts on the new firmware?
|