Quantcast
Channel: MobileRead Forums - Kobo Developer's Corner
Viewing all articles
Browse latest Browse all 1565

Adjustable top/bottom margin patch testing

$
0
0
Here is a patch to make the top and/or bottom margins adjustable in epubs. I.e. when you use the slider to adjust the left/right margins, the top/bottom margins change too. Please treat this as experimental for now, I have tested it a little on my Glo and it seems to work without problems, but I am still learning ARM assembly and I might have overlooked something, so more testing and feedback would be good.

The patch works by modifying the epub reader's built-in stylesheet. The original stylesheet looks like this:

Code:

@font-face { font-family: -ua-default; font-style: normal; font-weight: normal; src: url('res:///fonts/normal/%1') }
@font-face { font-family: -ua-default; font-style: italic; font-weight: normal; src: url('res:///fonts/italic/%1') }
@font-face { font-family: -ua-default; font-style: italic; font-weight: bold; src: url('res:///fonts/bolditalic/%1') }
@font-face { font-family: -ua-default; font-style: normal; font-weight: bold; src: url('res:///fonts/bold/%1') }
body, p { font-family: -ua-default !important; }
body {
 text-align: %1 !important;
 line-height: %1em !important;
 padding-bottom: %1em !important;
 -kobo-font-sharpness: %1;
 -kobo-font-thickness: %1;
}

Each "%1" is a variable. Originally "padding-bottom: %1" got the same value as "line-height: %1". The patch replaces the body{padding bottom:%1em} with a @page{margin:%1 0}, and supplies it with the value of readingLeftMargin(x2) in place of readingLineHeight.

(One side effect of this is that the epub reader no longer adds any padding at the end of a chapter, I don't know if this is important or not?)

(Edit: Another side effect seems to be that any @page margins set in the epub itself will not take effect)

You can change how much the top/bottom margins increase by editing the replacement string in the patch. I have used units of pt which seems about right on my Glo, but feedback about how it suits other devices would be useful.

This patch should work okay on its own, but it is probably better in combination with the custom margins and footer patches. If you choose to make the bottom margin adjustable, then you will probably want to modify your footer so that there is not to much margin between the top of the page number and the bottom of the text. Hopefully we can find good combinations of footer and bottom margin size to look good on the different devices.

Patch for firmware 3.2.0 (kpg.exe version, yes I have tested it with kpg.exe ths time :-)
Spoiler:
Code:

# Firmware 3.2.0 (kpg.exe version)
<Patch>
patch_name = `ePub stylesheet Adjustable top/bottom margin`
patch_enable = `yes`
# getReadingLineHeight() --> getReadingLeftMargin()
replace_bytes = 8C2F48, FA F4 D6 E8, D3 F4 62 EC
# QString.arg(double, ...) --> QString.arg(uint64, ...)
replace_bytes = 8C2F4E, FF 33, 0A 23
replace_bytes = 8C2F54, 00 93, 01 93
replace_bytes = 8C2F5A, CD F8 04 80, CD F8 08 80
replace_bytes = 8C2F62, 00 22 67 23, 00 23 00 93
replace_bytes = 8C2F6A, E0 F4 2E EC, F3 F4 CE EB
#
# Top/bottom margin scale: 2xreadingLeftMargin
replace_bytes = 8C2F4C, 4F F0, 02 18
#
# Top/bottom margin scale: 1xreadingLeftMargin
#replace_bytes = 8C2F4C, 4F F0, 02 46
#
# Modify stylesheet: top margin example:
replace_xor_00 = 1181F4C, `\x20padding-bottom: %1em !important;\n\x00`, `}\n@page {margin:%1pt 0 0 0}\nbody {\x00`
#
# Top and bottom margin example:
#replace_xor_00 = 1181F4C, `\x20padding-bottom: %1em !important;\n\x00`, `}\n@page {margin:%1pt 0}\nbody {\x00`
#
</Patch>



Patch for firmware 3.2.0 (patch32lsb version):
Spoiler:
Code:

# Firmware 3.2.0 (patch32lsb version)
<Patch>
patch_name = `ePub stylesheet Adjustable top/bottom margin`
patch_enable = `yes`
# getReadingLineHeight() --> getReadingLeftMargin()
replace_bytes = 8C2F48, FA F4 D6 E8, D3 F4 62 EC
# QString.arg(double, ...) --> QString.arg(uint64, ...)
replace_bytes = 8C2F4E, FF 33, 0A 23
replace_bytes = 8C2F54, 00 93, 01 93
replace_bytes = 8C2F5A, CD F8 04 80, CD F8 08 80
replace_bytes = 8C2F62, 00 22 67 23, 00 23 00 93
replace_bytes = 8C2F6A, E0 F4 2E EC, F3 F4 CE EB
#
# Top/bottom margin scale: 2xreadingLeftMargin
replace_bytes = 8C2F4C, 4F F0, 02 18
#
# Top/bottom margin scale: 1xreadingLeftMargin
#replace_bytes = 8C2F4C, 4F F0, 02 46
#
# Modify stylesheet: top margin example:
replace_string = 1181F4C, ` padding-bottom: %1em !important;\n`, `}\n@page {margin:%1pt 0 0 0}\nbody {`
#
# Top and bottom margin example:
#replace_string = 1181F4C, ` padding-bottom: %1em !important;\n`, `}\n@page {margin:%1pt 0}\nbody {`
#
</Patch>


Viewing all articles
Browse latest Browse all 1565

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>