| 1 |
""" |
| 2 |
Copyright (C) 2013 Mayank Jha <[email protected]> |
| 3 |
|
| 4 |
This library is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU Lesser General Public License as published |
| 6 |
by the Free Software Foundation; either version 2.1 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
""" |
| 17 |
""" |
| 18 |
Copyright (C) 2013 Mayank Jha <[email protected]> |
| 19 |
|
| 20 |
This library is free software; you can redistribute it and/or modify |
| 21 |
it under the terms of the GNU Lesser General Public License as published |
| 22 |
by the Free Software Foundation; either version 2.1 of the License, or |
| 23 |
(at your option) any later version. |
| 24 |
|
| 25 |
This program is distributed in the hope that it will be useful, |
| 26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
GNU General Public License for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU Lesser General Public License |
| 31 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 32 |
""" |
| 33 |
from fc.BitmapHandler import CreateSpriteSheet |
| 34 |
import shelve |
| 35 |
import fontforge |
| 36 |
import os |
| 37 |
class MockFont: |
| 38 |
ascent=0 |
| 39 |
descent=0 |
| 40 |
strokewidth=0 |
| 41 |
uwidth=0 |
| 42 |
upos=0 |
| 43 |
xHeight=0 |
| 44 |
glyphs = list() |
| 45 |
capHeight=0 |
| 46 |
normalglyphfile = "data/masterspritenormal.bmp" |
| 47 |
boldglyphfile = "data/masterspritebold.bmp" |
| 48 |
italicglyphfile = "data/masterspriteitalic.bmp" |
| 49 |
highresdocfile = "data/highres.png" |
| 50 |
def __init__(self,fontpath,pixelsize,glyphrange): |
| 51 |
font = fontforge.open(fontpath) |
| 52 |
self.ascent = font.ascent |
| 53 |
self.descent = font.descent |
| 54 |
self.upos = font.upos |
| 55 |
self.uwidth = font.uwidth |
| 56 |
self.xHeight = font.xHeight |
| 57 |
self.capHeight = font.capHeight |
| 58 |
self.weight = font.weight |
| 59 |
|
| 60 |
CreateSpriteSheet(pixelsize,font,glyphrange,"normal") |
| 61 |
font = fontforge.open(fontpath) |
| 62 |
|
| 63 |
CreateSpriteSheet(pixelsize,font,glyphrange,"bold") |
| 64 |
font = fontforge.open(fontpath) |
| 65 |
|
| 66 |
CreateSpriteSheet(pixelsize,font,glyphrange,"italic") |
| 67 |
|
| 68 |
bashcommand = "hb-view --output-format=\"png\" --output-file=\"data/highres.png\" --font-size=160 --text-file=\"" |
| 69 |
bashcommand+="docs/doc.txt\" \""+fontpath+"\"" |
| 70 |
os.system(str(bashcommand)) |
| 71 |
|
| 72 |
def main(): |
| 73 |
mock_font = shelve.open("data/mockfile.mcy") |
| 74 |
mock_font["font"] = MockFont("../unittests/lohit.ttf",100,(0x900,0x97f)) |
| 75 |
mock_font.close() |
| 76 |
|
| 77 |
if __name__ =='__main__':main() |
| 78 |
""" |
| 79 |
explanation--> |
| 80 |
|
| 81 |
"../unittests/lohit.ttf" is the path where the font file is stored |
| 82 |
so all you need to do is change the path of the font file, for making |
| 83 |
your own mockfonts. |
| 84 |
|
| 85 |
""" |