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 too 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.conf version)
<Patch>
patch_name = `ePub 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.conf version):
Spoiler:
Code:
# Firmware 3.2.0 (patch32lsb version)
<Patch>
patch_name = `ePub 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>
Edit: Here is the patches for firmware 3.3.0. The adjustable margins work with the new full-screen reading mode too. Unfortunately the way the stylesheet is stored makes it difficult to edit the replacement strings in the patch, be careful not to change the length of the replacement strings if you do attempt to edit them.
Patch for firmware 3.3.0 (kpg.conf version)
Spoiler:
Code:
# Firmware 3.3.0 (8eb9c1f8b2)
<Patch>
patch_name = `ePub adjustable top/bottom margin`
patch_enable = `yes`
# getReadingLineHeight() --> getReadingLeftMargin()
replace_bytes = 4E8BD0, 47 F7 CA E9, 2A F7 F8 E9
# QString.arg(double, ...) --> QString.arg(int64, ...)
replace_bytes = 4E8BD4, 20 22 4F F0 FF 33, 20 21 01 22 0A 23
replace_bytes = 4E8BDE, AD F8 04 20 00 93, 02 91 42 43 01 93
replace_bytes = 4E8BE8, 00 22 67 23 34 F7 36 EF, 00 23 00 93 29 F7 92 ED
#
# Set the value of the top/bottom margin to a multiple of readingLeftMargin,
# in pixels. Suggested values: 4px (Touch/Mini), 5px (Glo/Aura), 7px (Aura HD)
replace_int = 4E8BD6, 1, 5
#
# Modify stylesheet, only top margin adjustable: @page {margin:%1px 0 0 0 0}
#replace_xor_00 = BE8A20, `\x20\x00p\x00a\x00d\x00d\x00i\x00n\x00g\x00-\x00b\x00o\x00t\x00t\x00o\x00m\x00:\x00\x20\x00%\x001\x00e\x00m\x00\x20\x00!\x00i\x00m\x00p\x00o\x00r\x00t\x00a\x00n\x00t\x00;\x00\n\x00`, `}\x00\n\x00@\x00p\x00a\x00g\x00e\x00\x20\x00{\x00m\x00a\x00r\x00g\x00i\x00n\x00:\x00%\x001\x00p\x00x\x00\x20\x000\x00\x20\x000\x00\x20\x000\x00}\x00\n\x00b\x00o\x00d\x00y\x00\x20\x00{\x00`
#
# Modify stylesheet, top and bottom adjustable: @page {margin:%1px 0}
replace_xor_00 = BE8A20, `\x20\x00p\x00a\x00d\x00d\x00i\x00n\x00g\x00-\x00b\x00o\x00t\x00t\x00o\x00m\x00:\x00\x20\x00%\x001\x00e\x00m\x00\x20\x00!\x00i\x00m\x00p\x00o\x00r\x00t\x00a\x00n\x00t\x00;\x00\n\x00`, `}\x00\n\x00@\x00p\x00a\x00g\x00e\x00\x20\x00{\x00m\x00a\x00r\x00g\x00i\x00n\x00:\x00%\x001\x00p\x00x\x00\x20\x000\x00}\x00\n\x00b\x00o\x00d\x00y\x00\x20\x00{\x00\x20\x00\x20\x00\x20\x00\x20\x00`
#
</Patch>
Patch for firmware 3.3.0 (patch32lsb.conf version)
Spoiler:
Code:
# Firmware 3.3.0 (8eb9c1f8b2)
<Patch>
patch_name = `ePub adjustable top/bottom margin`
patch_enable = `yes`
# getReadingLineHeight() --> getReadingLeftMargin()
replace_bytes = 4E8BD0, 47 F7 CA E9, 2A F7 F8 E9
# QString.arg(double, ...) --> QString.arg(int64, ...)
replace_bytes = 4E8BD4, 20 22 4F F0 FF 33, 20 21 01 22 0A 23
replace_bytes = 4E8BDE, AD F8 04 20 00 93, 02 91 42 43 01 93
replace_bytes = 4E8BE8, 00 22 67 23 34 F7 36 EF, 00 23 00 93 29 F7 92 ED
#
# Set the value of the top/bottom margin to a multiple of readingLeftMargin,
# in pixels. Suggested values: 4px (Touch/Mini), 5px (Glo/Aura), 7px (Aura HD)
replace_int = 4E8BD6, 1, 5
#
# Modify stylesheet, only top margin adjustable: @page {margin:%1px 0 0 0 0}
#replace_string = BE8A20, `\x20\x00p\x00a\x00d\x00d\x00i\x00n\x00g\x00-\x00b\x00o\x00t\x00t\x00o\x00m\x00:\x00\x20\x00%\x001\x00e\x00m\x00\x20\x00!\x00i\x00m\x00p\x00o\x00r\x00t\x00a\x00n\x00t\x00;\x00\n\x00`, `}\x00\n\x00@\x00p\x00a\x00g\x00e\x00\x20\x00{\x00m\x00a\x00r\x00g\x00i\x00n\x00:\x00%\x001\x00p\x00x\x00\x20\x000\x00\x20\x000\x00\x20\x000\x00}\x00\n\x00b\x00o\x00d\x00y\x00\x20\x00{\x00`
#
# Modify stylesheet, top and bottom adjustable: @page {margin:%1px 0}
replace_string = BE8A20, `\x20\x00p\x00a\x00d\x00d\x00i\x00n\x00g\x00-\x00b\x00o\x00t\x00t\x00o\x00m\x00:\x00\x20\x00%\x001\x00e\x00m\x00\x20\x00!\x00i\x00m\x00p\x00o\x00r\x00t\x00a\x00n\x00t\x00;\x00\n\x00`, `}\x00\n\x00@\x00p\x00a\x00g\x00e\x00\x20\x00{\x00m\x00a\x00r\x00g\x00i\x00n\x00:\x00%\x001\x00p\x00x\x00\x20\x000\x00}\x00\n\x00b\x00o\x00d\x00y\x00\x20\x00{\x00\x20\x00\x20\x00\x20\x00\x20\x00`
#
</Patch>