Code:
<Patch>
patch_name = `ePub fixed/adjustable top/bottom margins`
patch_enable = `yes`
# patch_group = `ePub padding-bottom alternatives`
#
## 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 = 488A28, C9 B0, CB B0
replace_bytes = 488A2C, 02 AF, 04 AF
# Save this value for the third stack argument of the following function call
replace_bytes = 488DC0, AD F8 04 20, 02 92 01 92
# getReadingLineHeight(...) --> getReadingLeftMargin(...)
replace_bytes = 488E14, AC F7 8A E8, 8C F7 F6 EC
# (Setup call to QString.arg)
replace_bytes = 488E18, 20 22 4F F0 FF 33, 00 23 01 22 0A 21
replace_bytes = 488E1E, 07 F1 70 0A, 00 93 01 91
replace_bytes = 488E22, AD F8 04 20 00 93, 42 43 92 08 01 3A
replace_bytes = 488E28, 50 46 67 23, B8 BF 00 22
replace_bytes = 488E2C, 00 22 49 46, 20 A8 49 46
# QString.arg(double, ...) --> QString.arg(int64, ...)
replace_bytes = 488E30, 98 F7 48 E9, 8C F7 46 E8
#
# (There wasn't room to load sl above)
# mov r1,sl; --> adds r1,sp,#128
replace_bytes = 488E34, 51 46, 20 A9
# (Remember to pop scratch space if necessary)
#
# padding-bottom: %1em !important;\n
# --> }@page{margin:%1px 00px %1px}body{
find_base_address = `\x20padding-bottom: %1em !important;\n`
replace_string = 0000, `\x20padding-bottom: %1em !important;\n`, `}@page{margin:%1px 00px %1px}body{`
#
#
# *** 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:
# (Leave commented out for an adjustable top margin.)
replace_string = 000E, `%1`, `00`
#
# Optional replacement value: Uncomment for a FIXED BOTTOM MARGIN size in px,
# default 00px. Replacement value is margin size, two digits:
# (Leave commented out for an adjustable bottom margin.)
replace_string = 0018, `%1`, `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
replace_string = 0013, `00`, `02`
#
base_address = 000000
#
# 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/Aura2ed), 43 (AuraHD/H2O/GloHD), 56 (Aura One)
replace_int = 488E1A, 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 (with custom or disabled footer, all devices)
replace_int = 488E26, 1, 0
</Patch>