Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Sony Reader > Sony Reader Dev Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 01-09-2007, 11:17 AM   #1
igorsk
Wizard
igorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfolded
 
Posts: 3,443
Karma: 52235
Join Date: Sep 2006
Location: Belgium
Device: PRS-500/505/700, Kindle, Cybook Gen3, Words Gear
Embedded fonts in LRF WORKING

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.
Attached Files
File Type: zip rus2.zip (175.7 KB, 394 views)
igorsk is offline   Reply With Quote
Old 01-09-2007, 11:34 AM   #2
Alexander Turcic
Fully Converged
Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.Alexander Turcic ought to be getting tired of karma fortunes by now.
 
Alexander Turcic's Avatar
 
Posts: 17,107
Karma: 10995944
Join Date: Oct 2002
Location: Switzerland
Device: Sony PRS-650 / Nexus 7 / Kindle PW
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.
Alexander Turcic is offline   Reply With Quote
 
Enthusiast
Old 01-09-2007, 11:52 AM   #3
obelix
Connoisseur
obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.
 
Posts: 64
Karma: 1695
Join Date: Oct 2006
Quote:
Originally Posted by igorsk
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)?
obelix is offline   Reply With Quote
Old 01-09-2007, 12:02 PM   #4
igorsk
Wizard
igorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfolded
 
Posts: 3,443
Karma: 52235
Join Date: Sep 2006
Location: Belgium
Device: PRS-500/505/700, Kindle, Cybook Gen3, Words Gear
Quote:
Originally Posted by obelix
Do you know correct lrs records to pass it to the parsers (to follow lrs standrads)?
Add this to the BookStyle element:
Code:
<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.
igorsk is offline   Reply With Quote
Old 01-09-2007, 05:42 PM   #5
scotty1024
Banned
scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.
 
Posts: 1,300
Karma: 1479
Join Date: Jul 2006
Location: Peoples Republic of Washington
Device: Reader / iPhone / Librie / Kindle
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.
scotty1024 is offline   Reply With Quote
Old 01-09-2007, 06:27 PM   #6
igorsk
Wizard
igorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfolded
 
Posts: 3,443
Karma: 52235
Join Date: Sep 2006
Location: Belgium
Device: PRS-500/505/700, Kindle, Cybook Gen3, Words Gear
You can check if the font allows embedding with Font properties extension:
http://www.microsoft.com/typography/...roperty21.mspx
igorsk is offline   Reply With Quote
Old 01-09-2007, 06:47 PM   #7
scotty1024
Banned
scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.scotty1024 is no ebook tyro.
 
Posts: 1,300
Karma: 1479
Join Date: Jul 2006
Location: Peoples Republic of Washington
Device: Reader / iPhone / Librie / Kindle
Probably a good warning for the parser to toss to the user during parsing. I'll be sure to check and warn.
scotty1024 is offline   Reply With Quote
Old 01-10-2007, 10:12 AM   #8
obelix
Connoisseur
obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.
 
Posts: 64
Karma: 1695
Join Date: Oct 2006
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
obelix is offline   Reply With Quote
Old 01-11-2007, 10:28 AM   #9
vvv
Zealot
vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.
 
Posts: 137
Karma: 1936
Join Date: Aug 2006
Device: iLiad, Librie, REB1100, GEB2150, GEB1150, etc
Quote:
Originally Posted by igorsk
You can check if the font allows embedding with Font properties extension:
http://www.microsoft.com/typography/...roperty21.mspx
It can be done in more simple way: GetFontData with zero arguments.
vvv is offline   Reply With Quote
Old 02-04-2007, 05:24 PM   #10
esperanc
Member
esperanc began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Nov 2006
Device: Sony Reader
Quote:
Originally Posted by obelix
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 is offline   Reply With Quote
Old 02-11-2007, 10:09 AM   #11
esperanc
Member
esperanc began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Nov 2006
Device: Sony Reader
Spans with fontfacename

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:

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.
Attached Thumbnails
Click image for larger version

Name:	testspanfonts.PNG
Views:	319
Size:	18.2 KB
ID:	2838  
esperanc is offline   Reply With Quote
Old 02-12-2007, 11:29 PM   #12
obelix
Connoisseur
obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.obelix once ate a cherry pie in a record 7 seconds.
 
Posts: 64
Karma: 1695
Join Date: Oct 2006
Quote:
Originally Posted by esperanc
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:

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:
Attached Thumbnails
Click image for larger version

Name:	testfonts.gif
Views:	305
Size:	9.7 KB
ID:	2840  
Attached Files
File Type: zip testfonts_1.zip (2.6 KB, 257 views)
obelix is offline   Reply With Quote
Old 02-13-2007, 08:29 PM   #13
esperanc
Member
esperanc began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Nov 2006
Device: Sony Reader
Quote:
Originally Posted by obelix
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)

Code:
<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?
Attached Files
File Type: zip testfont.zip (1.13 MB, 276 views)
esperanc is offline   Reply With Quote
Old 02-13-2007, 09:04 PM   #14
vvv
Zealot
vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.vvv once ate a cherry pie in a record 7 seconds.
 
Posts: 137
Karma: 1936
Join Date: Aug 2006
Device: iLiad, Librie, REB1100, GEB2150, GEB1150, etc
Quote:
Originally Posted by esperanc
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.
vvv is offline   Reply With Quote
Old 02-14-2007, 03:15 AM   #15
igorsk
Wizard
igorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfoldedigorsk reads XML... blindfolded
 
Posts: 3,443
Karma: 52235
Join Date: Sep 2006
Location: Belgium
Device: PRS-500/505/700, Kindle, Cybook Gen3, Words Gear
In Reader, "fontfilename" attribute is ignored, and even "fontname". It uses the actual font names from the TTF.
igorsk is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded fonts, Calibre, and choice of fonts AlexBell ePub 8 05-30-2010 06:00 AM
iPad Embedded Fonts JSWolf Apple Devices 24 04-26-2010 02:41 PM
Embedded fonts in epub erik5000 ePub 7 12-08-2009 11:55 AM
ePub embedded fonts JSWolf Ectaco jetBook 9 09-14-2009 08:43 PM
Using embedded fonts with italics only sherman Calibre 2 06-27-2009 04:32 AM


All times are GMT -4. The time now is 03:15 PM.


MobileRead.com is a privately owned, operated and funded community.