Patches & Hyphen Dicts: c.f., autopatch.sh ;).

----

Enable Full-Screen Reading:

Edit .kobo\Kobo eReader.conf

Add:

[FeatureSettings]
fullScreenReading=true

And then check out the Reading Settings UI.

NOTE: RIP since FW 4.12 ;'(

----

As for quality dithering, this may help (in Reading?):

highQualityDithering=true

NOTE: Not sure this actually does anything...

If you want to kill the Quick Turn thingy:

disableQuickTurn=true

(Also of potential interest: readingColumnCount, disableForcedGC16, disableRegal)

To kill the stupid swipe to unlock on the Forma: (in PowerOptions):

UnlockEnabled=false

NOTE: Of potential interest, the Dev section:
      (Some of this might be available via the UI after entering "devmodeon" in the Search bar (this brings back Kindle memories ;)), c.f., https://www.mobileread.com/forums/showpost.php?p=3795567&postcount=5)
[DeveloperSettings]
EnableDebugServices=true
EnableInspector=true
ForceWifiOn=false
ShowWidget=true

NOTE: And the Feats section:
[FeatureSettings]
Screenshots=false
ShowLayoutRectangles=true

NOTE: And, possibly, in the App section:
[ApplicationPreferences]
Debugging=true

----

kePub output: Copy a (preferrably small) DRM-free kepub to reference.kepub.epub in .config/calibre/plugins

And set margins to 0 in the output's Page Setup! (To avoid applying margins to the body element, which shifts everything to the right. [apparently a kepub bug/spec violation])

----

kobo_extra.css at the USB root:

# Nerf stupid page margins
@page {margin: 0;}
div, p {widows:1; orphans:1;}

# Might want to go w/ this instead, if the null margins are too extreme/unbalanced
@page {margin: 10px 0 0 0}

# Optionally:
body {orphans: 1; widows: 1;}

# And to make sure we don't apply padding/margin to the body, which screws up kepubs:
# NOTE: May be overkill/already fixed/handled by a patch
body { margin: 0 0 0 0 !important; padding: 0 0 0 0 !important; }

# Fix monospace (w/ a real custom font, instead of Dark Courier):
# NOTE: Now also handled by a patch.
@font-face {font-family: monospace; font-weight: normal; font-style: normal; src: url("res:///fonts/normal/Dark Courier")}
@font-face {font-family: monospace; font-weight: bold; font-style: normal; src: url("res:///fonts/bold/Dark Courier")}
@font-face {font-family: monospace; font-weight: normal; font-style: italic; src: url("res:///fonts/italic/Dark Courier")}
@font-face {font-family: monospace; font-weight: bold; font-style: italic; src: url("res:///fonts/bolditalic/Dark Courier")}

----

Speaking of fonts, if the UI and the ACCESS (KePub) reader mangles some styles with custom fonts, make sure the Panose stuff is sane (OS/2 > Panose).
Keep the usual Kindle Line-height tweaks in mind, that might also help  w/ the line-height < 1.0 issue...
c.f., http://www.mobileread.com/forums/showpost.php?p=2866441&postcount=218 for the line-height thing,
and https://www.mobileread.com/forums/showpost.php?p=3606469&postcount=2 & https://www.mobileread.com/forums/showpost.php?p=3608181&postcount=9 for the Panose tweaks.
Don't forget about ttfautohint if a TTF font has broken bytecode...

Also, supposedly kerning has to be old-style for the ACCESS renderer to make use of it...
Although a quick check didn't yield definitive results on that front (stuff might even be unkerned by default...)
Might require ligatures & stuff to be enabled?

Other random notes:
* ACCESS really doesn't like unhinted fonts (TTF or CFF)
* RMSDK deals fairly well with unhinted CFF, and only slightly less badly than ACCESS with unhinted TTF
* ACCESS may not care too much about the naming scheme, but RMSDK does (better fix it for nametable-from-filename anyways)
* RMSDK doesn't appear to care too much about the Panose stuff, but ACCESS does.
Fun, right? :D.

You should be able to automate a lot of that stuff w/ gftools:
* fix-vertical-metrics for the line-heights & co.
* fix-weightclass in case the OS/2 wieghts are borked
* More generally, nametable-from-filename which will handle all the OS/2 & TTF names shenanigans based on the filename (Family-Style).
* Based on list-panose, it should be fairly easy to set every field to 0 (or the right values) via fontTools, c.f., fix-panose.py in this folder.

e.g., for Bookerly:
fonts=("${(@f)$(ls -1 ./Bookerly-*.ttf)}")

for font in "${fonts[@]}" ; do
	gftools fix-vertical-metrics -a 802 -d -198 -l 0 "${font}"
	mv -v "${font%.*}.fix.ttf" "${font}"
	gftools nametable-from-filename "${font}"
	mv -v "${font}.fix" "${font}"
	#gftools fix-isfixedpitch --fonts "${font}"
	#mv -v "${font}.fix" "${font}"
	~/SVN/Configs/trunk/Kindle/Kobo_Hacks/Patches/fix-panose.py "${font}"
	mv -v "${font}.fix" "${font}"
done

----

Speaking of fonts, quick recap to rebuild the latest Literata sources...

# Install fontmake & gftools:
pip install -U --user fontmake
pip install -U --user git+https://github.com/googlefonts/gftools

# Make sure that ends up in $PATH:
export PATH="${PATH}:${HOME}/.local/bin"

# Clone Literata (https://github.com/googlefonts/literata)

# Patch line-heights (Literata 2):
sed -e 's/value = -308;/value = -200;/g' -i *.glyphs
sed -e 's/value = 308;/value = 200;/g' -i *.glyphs
sed -e 's/value = 1177;/value = 800;/g' -i *.glyphs
# Patch line-heights (Literata 3):
sed -e 's/value = -308;/value = -200;/g' -i sources-glyphs/*.glyphs
sed -e 's/value = 308;/value = 200;/g' -i sources-glyphs/*.glyphs
sed -e 's/value = 1177;/value = 800;/g' -i sources-glyphs/*.glyphs
sed -e 's:<integer>-308</integer>:<integer>-200</integer>:g' -i *.ufo/fontinfo.plist
sed -e 's:<integer>308</integer>:<integer>200</integer>:g' -i *.ufo/fontinfo.plist
sed -e 's:<integer>1177</integer>:<integer>800</integer>:g' -i *.ufo/fontinfo.plist

# Thinner Medium (Literata 2):
sed -e 's/interpolationWeight = 480;/interpolationWeight = 440;/' -i *.glyphs
sed -e 's/"D537FF15-C70F-4B12-AACC-84E5BB5FCF97" = 0.26667;/"D537FF15-C70F-4B12-AACC-84E5BB5FCF97" = 0.13334;/' -i Literata-Italic.glyphs
sed -e 's/"4181654C-020A-47A3-85ED-5DF79C071187" = 0.26667;/"4181654C-020A-47A3-85ED-5DF79C071187" = 0.13334;/' -i Literata.glyphs
sed -e 's/UUID0 = 0.73333;/UUID0 = 0.86667;/' -i *.glyphs

NOTE: This still leaves the Panose stuff to tweak if you want to use it in Kobo's KePub renderer.
      But since its hinting pretty much mangles it anyway, don't bother.
      Thanks, Monotype iType... (I guess?).

# Fix some erroneous stylenames (Literata 3):
sed -e 's:<instance name="Literata 7pt SemiBold Italic" familyname="Literata" stylename="7pt Medium Italic" filename="instance_ufo/Literata-7ptMediumItalic.ufo">:<instance name="Literata 7pt Medium Italic" familyname="Literata" stylename="7pt Medium Italic" filename="instance_ufo/Literata-7ptMediumItalic.ufo">:' -i _Literata-Italic.designspace
sed -e 's:<instance name="Literata 36pt SemiBold Italic" familyname="Literata" stylename="36pt Medium Italic" filename="instance_ufo/Literata-36ptMediumItalic.ufo">:<instance name="Literata 36pt Medium Italic" familyname="Literata" stylename="36pt Medium Italic" filename="instance_ufo/Literata-36ptMediumItalic.ufo">:' -i _Literata-Italic.designspace
sed -e 's:<instance name="Literata 72pt SemiBold Italic" familyname="Literata" stylename="72pt Medium Italic" filename="instance_ufo/Literata-72ptMediumItalic.ufo">:<instance name="Literata 72pt Medium Italic" familyname="Literata" stylename="72pt Medium Italic" filename="instance_ufo/Literata-72ptMediumItalic.ufo">:' -i _Literata-Italic.designspace
sed -e 's/custom = "12 pt Regular";/custom = "12pt Regular";/' -i sources-glyphs/*.glyphs

# Rename (Literata 3):
sed -e 's/familyName = Literata;/familyName = Lit3rata;/g' -i sources-glyphs/*.glyphs
sed -e 's/familyname="Literata/familyname="Lit3rata/g' -i *.designspace
sed -e 's/stylemapfamilyname="Literata/stylemapfamilyname="Lit3rata/g' -i *.designspace
sed -e 's/familyname="Lit3rata 12pt"/familyname="Lit3rata"/g' -i *.designspace
sed -e 's/stylemapfamilyname="Lit3rata 12pt/stylemapfamilyname="Lit3rata/g' -i *.designspace
sed -e 's:<string>Literata</string>:<string>Lit3rata</string>:g' -i *.ufo/fontinfo.plist

# TEST
# Rename (Literata 3):
sed -e 's/familyName = Literata;/familyName = Literata;/g' -i sources-glyphs/*.glyphs
sed -e 's/familyname="Literata/familyname="Literata/g' -i *.designspace
sed -e 's/stylemapfamilyname="Literata/stylemapfamilyname="Literata/g' -i *.designspace
sed -e 's/familyname="Literata 12pt"/familyname="Literata"/g' -i *.designspace
sed -e 's/stylemapfamilyname="Literata 12pt/stylemapfamilyname="Literata/g' -i *.designspace
sed -e 's:<string>Literata</string>:<string>Literata</string>:g' -i *.ufo/fontinfo.plist



# Fix file & style names for CRe (Literata 3):
#sed -re 's/(instance name=")Literata [[:digit:]]{1,2}?pt ([[:alpha:] ]*?")/\1Lit3rata \2/g' -i *.designspace
sed -re 's/(instance name=")Literata( [[:digit:]]{1,2}?pt [[:alpha:] ]*?")/\1Lit3rata\2/g' -i *.designspace
sed -re 's/(instance name=")Literata( [[:alpha:]]*?")/\1Lit3rata\2/g' -i *.designspace

sed -re 's/(stylename=")[[:digit:]]{1,2}?pt ([[:alpha:] ]*?")/\1\2/g' -i *.designspace
sed -e 's:filename="instance_ufo/Literata:filename="instance_ufo/Lit3rata:g' -i *.designspace
sed -re 's:<string>[[:digit:]]{1,2}?pt ([[:alpha:] ]*?)</string>:<string>\1</string>:g' -i *.ufo/fontinfo.plist

# TEST
#sed -re 's/(instance name=")Literata [[:digit:]]{1,2}?pt ([[:alpha:] ]*?")/\1Lit3rata \2/g' -i *.designspace
sed -re 's/(instance name=")Literata( [[:digit:]]{1,2}?pt [[:alpha:] ]*?")/\1Literata\2/g' -i *.designspace
sed -re 's/(instance name=")Literata( [[:alpha:]]*?")/\1Literata\2/g' -i *.designspace
sed -re 's/(stylename=")[[:digit:]]{1,2}?pt ([[:alpha:] ]*?")/\1\2/g' -i *.designspace
sed -e 's:filename="instance_ufo/Literata:filename="instance_ufo/Literata:g' -i *.designspace
sed -re 's:<string>[[:digit:]]{1,2}?pt ([[:alpha:] ]*?)</string>:<string>\1</string>:g' -i *.ufo/fontinfo.plist



#sed -re 's/"[[:digit:]]{1,2}?pt ([[:alpha:] ]*?)";/"\1";/g' -i sources-glyphs/*.glyphs

# Rebuild (Literata 2):
fontmake -g Literata.glyphs -i
fontmake -g Literata-Italic.glyphs -i

# Apply the same gftools tweak as the release builds (we probably don't need 'em w/ HB/FT, though):
otfs=("${(@f)$(ls -1 instance_otf/*.otf)}")
ttfs=("${(@f)$(ls -1 instance_ttf/*.ttf)}")

for font in "${otfs[@]}" "${ttfs[@]}" ; do
	gftools fix-dsig -f "${font}"
	if [[ "${font}" == *.ttf ]] ; then
		gftools fix-nonhinting "${font}" "${font}.fix"
		mv "${font}.fix" "${font}"
	fi
done

rm -v instance_*tf/*backup*.*tf

# Rebuild (Literata 3) [Go grab a drink, it'll take a while]:
rm -rf ../fonts/static
mkdir -p ../fonts/static/{otf,ttf}
#fontmake -m static-roman.designspace -i -o otf --output-dir ../fonts/static/otf/
#fontmake -m static-italic.designspace -i -o otf --output-dir ../fonts/static/otf/
#rm -rf instance_ufo
fontmake -m static-roman.designspace -i -o ttf --output-dir ../fonts/static/ttf/
fontmake -m static-italic.designspace -i -o ttf --output-dir ../fonts/static/ttf/
rm -rf instance_ufo

# Apply the same gftools tweak as the release builds (we probably don't need 'em w/ HB/FT, though):
otfs=("${(@f)$(ls -1 ../fonts/static/otf/*.otf)}")
ttfs=("${(@f)$(ls -1 ../fonts/static/ttf/*.ttf)}")

for font in "${otfs[@]}" "${ttfs[@]}" ; do
	gftools fix-dsig -f "${font}"
	if [[ "${font}" == *.ttf ]] ; then
		gftools fix-nonhinting "${font}" "${font}.fix"
		mv -v "${font}.fix" "${font}"
	fi

	# Fix !Regular Italics having a bogus FONT_SUBFAMILY_NAME nameID (Regular instead of Italic)
	# NOTE: This probably means much of our careful stylename trickery earlier is actually unneeded,
	#       since this would fix it, too...
	# Start by stripping the optical size from the filename to make gftools happy...
	tmp_font="$(echo "${font}" | sed -re 's:Lit3rata[[:digit:]]{1,2}pt-:Lit3rata-:')"
	mv -v "${font}" "${tmp_font}"
	gftools nametable-from-filename "${tmp_font}"
	mv -v "${tmp_font}.fix" "${font}"
	rm -fv "${tmp_font}"

	# Setup Panose for Kobo...
	/usr/local/bin/fix-panose.py "${font}"
	mv -v "${font}.fix" "${font}"
done

rm -v ../fonts/static/*tf/*backup*.*tf

# Literata 2:
NOTE: The Regular weight is nice enough (especially at high dpi), but eReaders usually prefer Medium weights ;).
(I'm fairly sure both Caecilia & Bookerly ship as Medium weights).
I settled for Medium on the H2O (265dpi) and my phone (402dpi, but OLED), and for Regular on the Forma (300dpi).

# Literata 3:
NOTE: Pretty happy with 12pt (Text) Regular. I'll probably keep using Medium on Android.

NOTE: I would also tend to prefer the OTF variant to avoid a Cubic to Quadratic conversion (AA on the TTF variant might be *ever* so slightly darker, though).

----

Same deal w/ Adobe's Source Serif Pro

# Install AFDKO
pip install --user -U afdko --pre
# Huh.
chmod -cvR a+x ${HOME}/.local/lib/python3.7/site-packages/psautohint/autohintexe
find ${HOME}/.local/bin/ -type f \! -perm /u+x -exec chmod a+x '{}' \+

# Make sure that ends up in *front* of $PATH, to avoid a conflict with the Transifex client...
export PATH="${HOME}/.local/bin:${PATH}"

# Clone it (https://github.com/adobe-fonts/source-serif-pro)

# Patch line-heights:
sed -e 's/1036;/800;/g' -i familyTables.fea familyOS2.fea
sed -e 's#<integer>1036</integer>#<integer>800</integer>#g' -i */*/*/*/*.ufo/fontinfo.plist
sed -e 's/-335;/-200;/g' -i familyTables.fea familyOS2.fea
sed -e 's/335;/200;/g' -i familyOS2.fea
sed -e 's#<integer>-335</integer>#<integer>-200</integer>#g' -i */*/*/*/*.ufo/fontinfo.plist
sed -e 's#<integer>335</integer>#<integer>200</integer>#g' -i */*/*/*/*.ufo/fontinfo.plist

# Rebuild:
./build.sh
