From 70c04baf9ce199a488ebd3c714da8af360831273 Mon Sep 17 00:00:00 2001 From: Ochi Wolfe Date: Sat, 31 Aug 2013 23:18:24 +0200 Subject: [PATCH] - Removed "guessing char" method for determining per-font Y-offset - Instead added "setBaselineOffset" script function to set a common baseline for all fonts - Now using text_path instead of show_text pycairo function for subpixel-precise text positioning - Updated autoShrink logic - Increased size of some special characters - Small updates to font.confs and default chains --- .../fonts/AnonymousPro-Bold/font.conf | 2 +- TextureCreator/fonts/AnonymousPro/font.conf | 2 +- TextureCreator/fonts/DejaVu-Bold/font.conf | 2 +- TextureCreator/fonts/DejaVu/font.conf | 70 ++++++++----------- TextureCreator/fonts/EnvyCodeR/font.conf | 1 - TextureCreator/fonts/FreeFont/font.conf | 1 - TextureCreator/fonts/FreeSerif/font.conf | 11 +-- .../fonts/Liberation-Bold/font.conf | 2 +- TextureCreator/fonts/Liberation/font.conf | 2 +- TextureCreator/fonts/Luxi-Bold/font.conf | 2 +- TextureCreator/fonts/Luxi/font.conf | 2 +- TextureCreator/fonts/Monofur/font.conf | 1 - TextureCreator/fonts/ProFont/font.conf | 2 +- TextureCreator/lib/TexturePainter.py | 64 ++++++++--------- TextureCreator/scripts/_default1024.chain | 3 +- TextureCreator/scripts/_default512.chain | 3 +- .../{_init1024.script => _init.script} | 3 +- TextureCreator/scripts/_init512.script | 11 --- 18 files changed, 78 insertions(+), 106 deletions(-) rename TextureCreator/scripts/{_init1024.script => _init.script} (88%) delete mode 100644 TextureCreator/scripts/_init512.script diff --git a/TextureCreator/fonts/AnonymousPro-Bold/font.conf b/TextureCreator/fonts/AnonymousPro-Bold/font.conf index 4de6073..a4225ef 100644 --- a/TextureCreator/fonts/AnonymousPro-Bold/font.conf +++ b/TextureCreator/fonts/AnonymousPro-Bold/font.conf @@ -1,2 +1,2 @@ +offset 2 0 abs abs scale 0.8125 cellHeight -offset 2 1 abs abs diff --git a/TextureCreator/fonts/AnonymousPro/font.conf b/TextureCreator/fonts/AnonymousPro/font.conf index 4de6073..a4225ef 100644 --- a/TextureCreator/fonts/AnonymousPro/font.conf +++ b/TextureCreator/fonts/AnonymousPro/font.conf @@ -1,2 +1,2 @@ +offset 2 0 abs abs scale 0.8125 cellHeight -offset 2 1 abs abs diff --git a/TextureCreator/fonts/DejaVu-Bold/font.conf b/TextureCreator/fonts/DejaVu-Bold/font.conf index 10312bf..8b13789 100644 --- a/TextureCreator/fonts/DejaVu-Bold/font.conf +++ b/TextureCreator/fonts/DejaVu-Bold/font.conf @@ -1 +1 @@ -offset -1 -1 abs abs + diff --git a/TextureCreator/fonts/DejaVu/font.conf b/TextureCreator/fonts/DejaVu/font.conf index 2bf81e9..78053d3 100644 --- a/TextureCreator/fonts/DejaVu/font.conf +++ b/TextureCreator/fonts/DejaVu/font.conf @@ -1,41 +1,29 @@ -offset -1 -1 abs abs - -charOffset ⚠ 0 -4 1 1 -charOffset ▲ 0 -4 1 1 -charOffset ◀ 0 -4 1 1 -charOffset ▼ 0 -4 1 1 -charOffset ▶ 0 -4 1 1 -charOffset ○ 0 -4 1 1 -charOffset ◔ 0 -4 1 1 -charOffset ◑ 0 -4 1 1 -charOffset ◕ 0 -4 1 1 -charOffset ● 0 -4 1 1 -charOffset ↑ 1 -4 1 1 -charOffset ← 1 -4 1 1 -charOffset ↓ 1 -4 1 1 -charOffset → 1 -4 1 1 -charOffset ↺ 1 0 1 1 -charOffset ↻ 1 0 1 1 -charOffset ☐ 1 -5 1 1 -charOffset ☑ 1 -5 1 1 -charOffset ☒ 1 -5 1 1 -charOffset ✔ 1 0 1 1 -charOffset ✘ 1 0 1 1 -charOffset ⚀ 1 -4 1 1 -charOffset ⚁ 1 -4 1 1 -charOffset ⚂ 1 -4 1 1 -charOffset ⚃ 1 -4 1 1 -charOffset ⚄ 1 -4 1 1 -charOffset ⚅ 1 -4 1 1 -charOffset ☺ 0 -1 1 1 -charOffset ☹ 0 -1 1 1 -charOffset ♪ 1 0 1 1 -charOffset ♫ 1 0 1 1 -charOffset ♠ 1 0 1 1 -charOffset ♣ 1 0 1 1 -charOffset ♥ 0 0 1 1 -charOffset ♦ 1 0 1 1 -charOffset ↕ 1 0 1 1 -charOffset ↔ 1 0 1 1 -charOffset ♀ 1 0 1 1 -charOffset ♂ 0 0 1 1 +charSettings ⚠ 0 -5 1 1 +charSettings ▲ 0 -5 1 1 +charSettings ◀ 0 -5 1 1 +charSettings ▼ 0 -5 1 1 +charSettings ▶ 0 -5 1 1 +charSettings ○ 0 -5 1 1 +charSettings ◔ 0 -5 1 1 +charSettings ◑ 0 -5 1 1 +charSettings ◕ 0 -5 1 1 +charSettings ● 0 -5 1 1 +charSettings ↑ 0 -5 1 1 +charSettings ← 0 -5 1 1 +charSettings ↓ 0 -5 1 1 +charSettings → 0 -5 1 1 +charSettings ↕ 0 -5 1 1 +charSettings ↔ 0 -5 1 1 +charSettings ↺ 0 -6 1 1 +charSettings ↻ 0 -6 1 1 +charSettings ☐ 0 -4 1.1 1.1 +charSettings ☑ 0 -4 1.08 1.08 +charSettings ☒ 0 -4 1.15 1.15 +charSettings ⚀ 0 -3 1.1 1.1 +charSettings ⚁ 0 -3 1.1 1.1 +charSettings ⚂ 0 -3 1.1 1.1 +charSettings ⚃ 0 -3 1.1 1.1 +charSettings ⚄ 0 -3 1.1 1.1 +charSettings ⚅ 0 -3 1.1 1.1 +charSettings ✔ 0 -3 1 1 +charSettings ✘ 0 -3 1 1 diff --git a/TextureCreator/fonts/EnvyCodeR/font.conf b/TextureCreator/fonts/EnvyCodeR/font.conf index 9e2fe2e..82ecdfa 100644 --- a/TextureCreator/fonts/EnvyCodeR/font.conf +++ b/TextureCreator/fonts/EnvyCodeR/font.conf @@ -1,2 +1 @@ scale 0.8125 cellHeight -offset 0 -1 abs abs diff --git a/TextureCreator/fonts/FreeFont/font.conf b/TextureCreator/fonts/FreeFont/font.conf index e6c7605..8cb71ca 100644 --- a/TextureCreator/fonts/FreeFont/font.conf +++ b/TextureCreator/fonts/FreeFont/font.conf @@ -1,2 +1 @@ scale 0.6875 cellHeight -offset 0 4 abs abs diff --git a/TextureCreator/fonts/FreeSerif/font.conf b/TextureCreator/fonts/FreeSerif/font.conf index 0a78c9b..411cca0 100644 --- a/TextureCreator/fonts/FreeSerif/font.conf +++ b/TextureCreator/fonts/FreeSerif/font.conf @@ -1,7 +1,8 @@ -offset 0 0 abs abs scale 0.625 cellHeight -charOffset ℹ 0 -1 1 1 -charOffset ∡ 0 -4 1 1 -charOffset ⌛ -1 0 1 1 -charOffset ⌚ -1 0 1 1 +charSettings ℹ 0 -2 1.1 1.1 +charSettings ❌ 0 -4 1 1 +charSettings ⌖ 0 0 1.3 1.3 +charSettings ∡ 0 -7 1.2 1.2 +charSettings ⌛ 0 0 1.2 1.2 +charSettings ⌚ 0 -3 1.1 1.1 diff --git a/TextureCreator/fonts/Liberation-Bold/font.conf b/TextureCreator/fonts/Liberation-Bold/font.conf index de33559..8b13789 100644 --- a/TextureCreator/fonts/Liberation-Bold/font.conf +++ b/TextureCreator/fonts/Liberation-Bold/font.conf @@ -1 +1 @@ -offset -1 1 abs abs + diff --git a/TextureCreator/fonts/Liberation/font.conf b/TextureCreator/fonts/Liberation/font.conf index de33559..8b13789 100644 --- a/TextureCreator/fonts/Liberation/font.conf +++ b/TextureCreator/fonts/Liberation/font.conf @@ -1 +1 @@ -offset -1 1 abs abs + diff --git a/TextureCreator/fonts/Luxi-Bold/font.conf b/TextureCreator/fonts/Luxi-Bold/font.conf index 10312bf..8b13789 100644 --- a/TextureCreator/fonts/Luxi-Bold/font.conf +++ b/TextureCreator/fonts/Luxi-Bold/font.conf @@ -1 +1 @@ -offset -1 -1 abs abs + diff --git a/TextureCreator/fonts/Luxi/font.conf b/TextureCreator/fonts/Luxi/font.conf index 10312bf..8b13789 100644 --- a/TextureCreator/fonts/Luxi/font.conf +++ b/TextureCreator/fonts/Luxi/font.conf @@ -1 +1 @@ -offset -1 -1 abs abs + diff --git a/TextureCreator/fonts/Monofur/font.conf b/TextureCreator/fonts/Monofur/font.conf index b64b544..4610684 100644 --- a/TextureCreator/fonts/Monofur/font.conf +++ b/TextureCreator/fonts/Monofur/font.conf @@ -1,2 +1 @@ scale 0.875 cellHeight -offset 0 -2 abs abs diff --git a/TextureCreator/fonts/ProFont/font.conf b/TextureCreator/fonts/ProFont/font.conf index e4ed900..f060135 100644 --- a/TextureCreator/fonts/ProFont/font.conf +++ b/TextureCreator/fonts/ProFont/font.conf @@ -1,2 +1,2 @@ -scale 0.875 cellHeight offset 2 0 abs abs +scale 0.875 cellHeight diff --git a/TextureCreator/lib/TexturePainter.py b/TextureCreator/lib/TexturePainter.py index c3cc09c..a3ab758 100644 --- a/TextureCreator/lib/TexturePainter.py +++ b/TextureCreator/lib/TexturePainter.py @@ -27,11 +27,12 @@ SCRIPTS_DIR = "scripts" class GridConfig: def __init__(self, args): - self.imageSize = (args[0], args[1]) - self.cellSize = (32, 64) - self.begin = (32, 44) - self.spacing = (40, 72) - self.cellCount = (25, 14) + self.imageSize = (args[0], args[1]) + self.cellSize = (32, 64) + self.begin = (32, 44) + self.spacing = (40, 72) + self.cellCount = (25, 14) + self.baselineOffset = 18.0 class CharConfig: def __init__(self, args): @@ -44,10 +45,9 @@ class FontConfig: def __init__(self, fontConfPath): self.offsetX = 0 self.offsetY = 0 - self.offsetXUnit = "" - self.offsetYUnit = "" + self.offsetXUnit = "abs" + self.offsetYUnit = "abs" self.perCharConfigs = {} - self.guessingChar = "X" self.scale = 0.75 self.scaleUnit = "cellHeight" self.autoShrink = False @@ -59,19 +59,16 @@ class FontConfig: while fontConf.more(): if fontConf.getCmd() == "offset": - [self.offsetX, self.offsetY, self.offsetXUnit, self.offsetYUnit] = fontConf.getArgs([int, int, str, str]) + [self.offsetX, self.offsetY, self.offsetXUnit, self.offsetYUnit] = fontConf.getArgs([float, float, str, str]) elif fontConf.getCmd() == "scale": [self.scale, self.scaleUnit] = fontConf.getArgs([float, str]) - - elif fontConf.getCmd() == "guessingChar": - self.guessingChar = fontConf.getArgs([unicode])[0] elif fontConf.getCmd() == "enableAutoShrink": self.autoShrink = True - elif fontConf.getCmd() == "charOffset": - args = fontConf.getArgs([unicode, int, int, float, float]) + elif fontConf.getCmd() == "charSettings": + args = fontConf.getArgs([unicode, float, float, float, float]) self.perCharConfigs[args[0]] = CharConfig(args[1:]) def getCharConfig(self, char): @@ -134,6 +131,10 @@ class TexturePainter: elif script.getCmd() == "setCellCount": self.gridConfig.cellCount = script.getArgs([int, int]) + elif script.getCmd() == "setBaselineOffset": + args = script.getArgs([float, str]) + self.gridConfig.baselineOffset = args[0] * self.convertScaleUnit(args[1]) + elif script.getCmd() == "drawLineBetweenCells": self.lineBetweenCells(*[int(arg) for arg in script.getArgs([int, int, int, int, int, int, int, int, int])]) @@ -234,37 +235,28 @@ class TexturePainter: self.cairoContext.set_font_size(self.fontSize) self.fontExtents = FontExtents(self.cairoContext) - self.fontExtents.update(self.fontConfig.guessingChar) - - self.guessedYOffset = self.fontExtents.ySize / 2 def jumpToCell(self, x, y): self.currentCol = int(x) self.currentRow = int(y) def drawChar(self, char): - fontSizeX = self.fontSize - fontSizeY = self.fontSize - - if self.fontConfig.autoShrink: - self.cairoContext.set_font_size(1) - self.fontExtents.update(char) - - if self.fontExtents.xSize > 0: - widthGuess = self.gridConfig.cellSize[0] / self.fontExtents.xSize - if widthGuess < self.fontSize: - fontSizeX = widthGuess - charConfig = self.fontConfig.getCharConfig(char) - fontSizeX *= charConfig.scaleX - fontSizeY *= charConfig.scaleY + fontSizeX = self.fontSize * charConfig.scaleX + fontSizeY = self.fontSize * charConfig.scaleY self.cairoContext.set_font_matrix(cairo.Matrix(xx = fontSizeX, yy = fontSizeY)) self.fontExtents.update(char) - xOffset = -self.fontExtents.xAdvance / 2 - yOffset = self.guessedYOffset + if self.fontConfig.autoShrink: + if self.fontExtents.xSize > self.gridConfig.cellSize[0]: + fontSizeX *= self.gridConfig.cellSize[0] / self.fontExtents.xSize + self.cairoContext.set_font_matrix(cairo.Matrix(xx = fontSizeX, yy = fontSizeY)) + self.fontExtents.update(char) + + xOffset = -self.fontExtents.xAdvance / 2.0 + yOffset = self.gridConfig.baselineOffset xOffset += self.fontConfig.offsetX * self.convertScaleUnit(self.fontConfig.offsetXUnit) yOffset += self.fontConfig.offsetY * self.convertScaleUnit(self.fontConfig.offsetYUnit) @@ -276,8 +268,10 @@ class TexturePainter: y = self.gridConfig.begin[1] + self.currentRow * self.gridConfig.spacing[1] + yOffset self.cairoContext.move_to(x, y) - self.cairoContext.show_text(char) - + + self.cairoContext.text_path(char) + self.cairoContext.fill() + self.currentCol += 1 if self.currentCol >= self.gridConfig.cellCount[0]: self.currentRow += 1 diff --git a/TextureCreator/scripts/_default1024.chain b/TextureCreator/scripts/_default1024.chain index 13deb20..761ba70 100644 --- a/TextureCreator/scripts/_default1024.chain +++ b/TextureCreator/scripts/_default1024.chain @@ -1,6 +1,7 @@ +init 1024 1024 1.0 1.0 setOutputNameSuffix -1024 -runScript _init1024.script +runScript _init.script runScript _basic.script runScript _extended.script runScript _special.script diff --git a/TextureCreator/scripts/_default512.chain b/TextureCreator/scripts/_default512.chain index e8d49a4..19a52de 100644 --- a/TextureCreator/scripts/_default512.chain +++ b/TextureCreator/scripts/_default512.chain @@ -1,6 +1,7 @@ +init 1024 1024 0.5 0.5 setOutputNameSuffix -512 -runScript _init512.script +runScript _init.script runScript _basic.script runScript _extended.script runScript _special.script diff --git a/TextureCreator/scripts/_init1024.script b/TextureCreator/scripts/_init.script similarity index 88% rename from TextureCreator/scripts/_init1024.script rename to TextureCreator/scripts/_init.script index 3351b53..9084ca8 100644 --- a/TextureCreator/scripts/_init1024.script +++ b/TextureCreator/scripts/_init.script @@ -1,4 +1,3 @@ -init 1024 1024 1.0 1.0 jumpToCell 0 0 setCellSize 32 64 @@ -6,6 +5,8 @@ setCellOffset 32 44 setCellSpacing 40 72 setCellCount 25 14 +setBaselineOffset 18 abs + # Un-comment the "debugGrid" line to draw a # positioning helper grid in the textures. #drawDebugGrid diff --git a/TextureCreator/scripts/_init512.script b/TextureCreator/scripts/_init512.script deleted file mode 100644 index 45bbc2b..0000000 --- a/TextureCreator/scripts/_init512.script +++ /dev/null @@ -1,11 +0,0 @@ -init 1024 1024 0.5 0.5 -jumpToCell 0 0 - -setCellSize 32 64 -setCellOffset 32 44 -setCellSpacing 40 72 -setCellCount 25 14 - -# Un-comment the "debugGrid" line to draw a -# positioning helper grid in the textures. -#drawDebugGrid