Horus fonts / bitmaps tools updated
This commit is contained in:
+21
-5
@@ -3,12 +3,16 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from PyQt4 import Qt, QtGui
|
from PyQt4 import Qt, QtGui
|
||||||
|
import glob
|
||||||
|
|
||||||
try:
|
try:
|
||||||
app = Qt.QApplication(sys.argv)
|
app = Qt.QApplication(sys.argv)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
for f in glob.glob("fonts/*.ttf"):
|
||||||
|
id = QtGui.QFontDatabase.addApplicationFont(f)
|
||||||
|
|
||||||
chars = u""" !"#$%&'()*+,-./0123456789:;<=>?°ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz~ ≥→←↑↓ △Ⓘ"""
|
chars = u""" !"#$%&'()*+,-./0123456789:;<=>?°ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz~ ≥→←↑↓ △Ⓘ"""
|
||||||
|
|
||||||
def getCharWidth(fontsize, metrics, index):
|
def getCharWidth(fontsize, metrics, index):
|
||||||
@@ -18,7 +22,15 @@ def getCharWidth(fontsize, metrics, index):
|
|||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
rect = metrics.boundingRect(chars[index])
|
rect = metrics.boundingRect(chars[index])
|
||||||
return rect.width()
|
return rect.width() + 1
|
||||||
|
|
||||||
|
def getFontTopBottom(fontsize, metrics):
|
||||||
|
top, bottom = 0, 0
|
||||||
|
for i, c in enumerate(chars):
|
||||||
|
rect = metrics.boundingRect(chars[i])
|
||||||
|
top = min(top, rect.top())
|
||||||
|
bottom = max(bottom, rect.bottom())
|
||||||
|
return top, bottom
|
||||||
|
|
||||||
def getFontWidth(fontsize, metrics):
|
def getFontWidth(fontsize, metrics):
|
||||||
width = 0
|
width = 0
|
||||||
@@ -28,11 +40,15 @@ def getFontWidth(fontsize, metrics):
|
|||||||
|
|
||||||
def createFontBitmap(filename, fontname, fontsize, foreground, background, coordsfile=True):
|
def createFontBitmap(filename, fontname, fontsize, foreground, background, coordsfile=True):
|
||||||
coords = [ ]
|
coords = [ ]
|
||||||
|
# font = QtGui.QFont(QtGui.QFontDatabase.applicationFontFamilies(id)[0])
|
||||||
font = QtGui.QFont(fontname)
|
font = QtGui.QFont(fontname)
|
||||||
font.setPointSize(fontsize)
|
font.setPixelSize(fontsize)
|
||||||
|
font.setHintingPreference(QtGui.QFont.PreferNoHinting)
|
||||||
metrics = QtGui.QFontMetrics(font)
|
metrics = QtGui.QFontMetrics(font)
|
||||||
width = getFontWidth(fontsize, metrics)
|
width = getFontWidth(fontsize, metrics)
|
||||||
image = QtGui.QImage(width, fontsize+4, QtGui.QImage.Format_RGB32)
|
top, bottom = getFontTopBottom(fontsize, metrics)
|
||||||
|
print top, bottom
|
||||||
|
image = QtGui.QImage(width, fontsize+1, QtGui.QImage.Format_RGB32)
|
||||||
image.fill(background)
|
image.fill(background)
|
||||||
painter = QtGui.QPainter()
|
painter = QtGui.QPainter()
|
||||||
painter.begin(image)
|
painter.begin(image)
|
||||||
@@ -48,7 +64,7 @@ def createFontBitmap(filename, fontname, fontsize, foreground, background, coord
|
|||||||
painter.drawPoint(width, fontsize);
|
painter.drawPoint(width, fontsize);
|
||||||
else:
|
else:
|
||||||
rect = metrics.boundingRect(c)
|
rect = metrics.boundingRect(c)
|
||||||
painter.drawText(width-rect.left(), fontsize+1, c)
|
painter.drawText(width-rect.left(), fontsize-2, c) # fontsize-bottom+1 -17 / 7
|
||||||
width += getCharWidth(fontsize, metrics, i)
|
width += getCharWidth(fontsize, metrics, i)
|
||||||
coords.append(width)
|
coords.append(width)
|
||||||
painter.end()
|
painter.end()
|
||||||
@@ -62,4 +78,4 @@ def createFontBitmap(filename, fontname, fontsize, foreground, background, coord
|
|||||||
return coords
|
return coords
|
||||||
|
|
||||||
if len(sys.argv) == 4:
|
if len(sys.argv) == 4:
|
||||||
createFontBitmap(sys.argv[3], sys.argv[1], int(sys.argv[2]), QtGui.QColor(0x00, 0x00, 0x00), QtGui.QColor(0xFF, 0xFF, 0xFF))
|
createFontBitmap(sys.argv[3], sys.argv[1], float(sys.argv[2]), QtGui.QColor(0x00, 0x00, 0x00), QtGui.QColor(0xFF, 0xFF, 0xFF))
|
||||||
|
|||||||
+18
-1
@@ -36,7 +36,7 @@ if what == "1bit":
|
|||||||
value += 1 << z
|
value += 1 << z
|
||||||
f.write("0x%02x," % value)
|
f.write("0x%02x," % value)
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
elif what == "16bits":
|
elif what == "4/4/4/4":
|
||||||
colors = []
|
colors = []
|
||||||
f.write("%d,%d,\n" % (width, height))
|
f.write("%d,%d,\n" % (width, height))
|
||||||
for y in range(height):
|
for y in range(height):
|
||||||
@@ -44,6 +44,14 @@ elif what == "16bits":
|
|||||||
pixel = image.pixel(x, y)
|
pixel = image.pixel(x, y)
|
||||||
f.write("0x%1x%1x%1x%1x," % (Qt.qAlpha(pixel)/16, Qt.qRed(pixel)/16, Qt.qGreen(pixel)/16, Qt.qBlue(pixel)/16))
|
f.write("0x%1x%1x%1x%1x," % (Qt.qAlpha(pixel)/16, Qt.qRed(pixel)/16, Qt.qGreen(pixel)/16, Qt.qBlue(pixel)/16))
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
elif what == "5/6/5":
|
||||||
|
colors = []
|
||||||
|
f.write("%d,%d,\n" % (width, height))
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
pixel = image.pixel(x, y)
|
||||||
|
f.write("0x%04x," % (((Qt.qRed(pixel) >> 3) << 11) + ((Qt.qGreen(pixel) >> 2) << 5) + ((Qt.qBlue(pixel) >> 3) << 0)))
|
||||||
|
f.write("\n")
|
||||||
elif what == "4bits":
|
elif what == "4bits":
|
||||||
colors = []
|
colors = []
|
||||||
writeSize(f, width, height)
|
writeSize(f, width, height)
|
||||||
@@ -62,6 +70,15 @@ elif what == "4bits":
|
|||||||
value -= 1<<(4+i)
|
value -= 1<<(4+i)
|
||||||
f.write("0x%02x," % value)
|
f.write("0x%02x," % value)
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
elif what == "8bits":
|
||||||
|
colors = []
|
||||||
|
writeSize(f, width, height)
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
value = Qt.qGray(image.pixel(x, y))
|
||||||
|
value = 0x0f - (value >> 4)
|
||||||
|
f.write("0x%02x," % value)
|
||||||
|
f.write("\n")
|
||||||
elif what == "03x05":
|
elif what == "03x05":
|
||||||
for y in range(0, height, 5):
|
for y in range(0, height, 5):
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
|
|||||||
Reference in New Issue
Block a user