View Single Post
Old 11-10-2015, 06:51 AM   #110
GeoffR
Wizard
GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.GeoffR ought to be getting tired of karma fortunes by now.
 
GeoffR's Avatar
 
Posts: 3,821
Karma: 19162882
Join Date: Nov 2012
Location: Te Riu-a-Māui
Device: Kobo Glo
New `ePub fixed/adjustable top/bottom margins` patch

Here is a new `ePub fixed/adjustable top/bottom margins` patch if you want to try it out. The changes only affect the adjustable margins.

* The adjustable margin size is now calculated to quarter-pixel accuracy. This allows a closer match between the size of the adjustable top/bottom margins and the left/right margins set by the slider on the Glo/Aura and AuraHD/H2O/GloHD devices. (e.g. 30 quarter-pixels = 7.5px is a better approximation for 1% of the Glo's 758px screen width than 7px or 8px which could be set in the old patch.)

* Option to subtract a fixed number of pixels from the adjustable top/bottom margin to compensate for the built-in top margin that can't be removed from normal reading mode (fullScreenReading=false)

The old patch calculated the top/bottom margin as A * B where A is the size (in % of screen width) of the left/right margin set by the slider; and B the number of pixels (step-size) set in the patch.

The new patch calculates the top/bottom margin as A * B / 4 - C (rounded towards zero, or set to zero if the result is negative) where A and B are as before but B in quarter-pixels; and C is the size of the device's built-in top margin (use zero for full-screen mode) set in the patch.

As before, the final margins can be affected by the book's stylesheet. You might want to remove the body left/right margins set in the book's CSS stylesheet and any page margins set in the book's Adobe XPGT stylesheet.

Firmware 3.18.0 only, paste into libnickel.so.1.0.0.patch:
Spoiler:
Code:
<Patch>
patch_name = `ePub fixed/adjustable top/bottom margins`
patch_enable = `yes`
#
# This patch sets the @page margin sizes in epubs, overriding any @page margin
# set in the book's CSS stylesheet (but not in the XPGT stylesheet, see below).
#
# By default the top and bottom margins are set to be adjustable, their size
# similar to the left/right margin size set by the adjustment slider. There
# are options to set the top and/or bottom margin to a fixed size instead.
#
# Note that @page margins are seperate from (and overlap) both the body margins
# set in the book and the left/right margins set from the adjustment slider,
# and are added to any page margins set in the Adobe XPGT stylesheet if the
# book has one (e.g. page-template.xpgt). For this reason you might want to
# consider using the Modify ePub Calibre plugin to remove any body margins and
# XPGT stylesheet margins before sideloading the book, or perhaps enabling the
# `Ignore ePub Adobe XPGT stylesheet (page-template.xpgt)` patch.
#
# Also note that a side-effect of this patch is that the body padding-bottom is
# removed from the built-in stylesheet, which means that there will no longer
# be a blank line added automatically at the end of chapters.
#
# See at the bottom of the patch for replacement values that can be used to
# tune the size of the margins to suit different devices and reading modes.
#
#
# Push an extra 8 bytes of scratch space onto the stack
replace_bytes = 45EAD2, BD B0, BF B0
replace_bytes = 45EAD8, 02 AF, 04 AF
# Save this value for the third stack argument of our later function call
replace_bytes = 45EE3A, AD F8 04 20, 02 92 01 92
# getReadingLineHeight(...) --> getReadingLeftMargin(...)
replace_bytes = 45EE88, B6 F7 A8 EA, 9A F7 62 E8 
# QString.arg(double, ...) --> QString.arg(int64, ...)
replace_bytes = 45EE8C, 20 22 4F F0 FF 33, 00 23 01 22 0A 21
replace_bytes = 45EE92, 07 F1 50 0A, 00 93 01 91
replace_bytes = 45EE96, AD F8 04 20 00 93, 42 43 92 08 01 3A
replace_bytes = 45EE9C, 50 46 29 46, B8 BF 00 22
replace_bytes = 45EEA0, 00 22 67 23, 18 A8 29 46
replace_bytes = 45EEA4, A4 F7 66 EC, 99 F7 1C EC
# mov r1,sl; --> adds r1,sp,#96
replace_bytes = 45EEAA, 51 46, 18 A9
# (Remember to pop scratch space if necessary)
#
#      padding-bottom: %1em !important;\n
# --> }@page{margin:%1px 00px %1px}body{
replace_string = B4FDC0, `\x20\0p\0a\0d\0d\0i\0n\0g\0-\0b\0o\0t\0t\0o\0m\0:\0 \0%\01\0e\0m\0 \0!\0i\0m\0p\0o\0r\0t\0a\0n\0t\0;\0\n\0`, `}\0@\0p\0a\0g\0e\0{\0m\0a\0r\0g\0i\0n\0:\0%\01\0p\0x\0 \00\00\0p\0x\0 \0%\01\0p\0x\0}\0b\0o\0d\0y\0{\0`
#
#
# *** Replacement values start here, don't change anything above ***
#
# Optional replacement value: Uncomment for a FIXED TOP MARGIN size in px,
# default 25px. Replacement value is margin size, two digits separated by \0
# (Leave commented out for an adjustable top margin.)
#replace_string = B4FDDC, `%\01`, `2\05`
#
# Optional replacement value: Uncomment for a FIXED BOTTOM MARGIN size in px,
# default 00px. Replacement value is margin size, two digits separated by \0
# (Leave commented out for an adjustable bottom margin.)
#replace_string = B4FDF0, `%\01`, `0\00`
#
# Optional replacement value: Uncomment to set the minimum LEFT/RIGHT MARGIN
# size in px, default 15px. (This margin will overlap the left/right margin
# set with the adjustment slider, not add to it.) Replacement value is margin
# size, two digits separated by \0
#replace_string = B4FDE6, `0\00`, `1\05`
#
# Replacement value: Sets the step-size of the ADJUSTABLE top/bottom margin
# (if any) in quarter-pixels. These suggested values should be very close to
# the 1% step size of the left/right margins set by the slider. Larger values
# will make the top/bottom margins larger than the left/right margins.
# Suggested values: 24 (Touch/Mini), 30 (Glo/Aura), 43 (AuraHD/H2O/GloHD)
replace_int = 45EE8E, 1, 30
#
# Replacement value: Set this to the size of the device's built-in top margin,
# in pixels. This value is subtracted from the adjustable top/bottom margin
# (if any) to compensate for any unremovable built-in top margin.
# Suggested values are:
#   0 For full-screen reading mode (fullScreenReading=true, all devices)
#  15 for normal reading mode (Glo/GloHD, not sure for other devices)
replace_int = 45EE9A, 1, 0
</Patch>

Last edited by GeoffR; 11-10-2015 at 06:55 AM. Reason: corrected patch comments
GeoffR is offline   Reply With Quote