mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
loadFont(lineHeight = 1)
This commit is contained in:
parent
0efa534315
commit
fdf22f5da7
@ -121,14 +121,15 @@ class Loader:
|
|||||||
ModelPool.releaseModel(modelPath)
|
ModelPool.releaseModel(modelPath)
|
||||||
|
|
||||||
# font loading funcs
|
# font loading funcs
|
||||||
def loadFont(self, modelPath, priority = 0, faceIndex = 0):
|
def loadFont(self, modelPath, priority = 0, faceIndex = 0,
|
||||||
|
lineHeight = None):
|
||||||
"""loadFont(self, string)
|
"""loadFont(self, string)
|
||||||
|
|
||||||
This loads a special model that will be sent to a TextNode as
|
This loads a special model as a TextFont object, for rendering
|
||||||
a "font"--this is a model generated with egg-mkfont (or
|
text with a TextNode. A font file must be either a special
|
||||||
ttf2egg) that consists of a flat hierarchy, with one node per
|
egg file (or bam file) generated with egg-mkfont, or a
|
||||||
each letter of the font. The TextNode will assemble these
|
standard font file (like a TTF file) that is supported by
|
||||||
letters together, given a string.
|
FreeType.
|
||||||
"""
|
"""
|
||||||
Loader.notify.debug("Loading font: %s" % (modelPath))
|
Loader.notify.debug("Loading font: %s" % (modelPath))
|
||||||
if phaseChecker:
|
if phaseChecker:
|
||||||
@ -145,21 +146,31 @@ class Loader:
|
|||||||
if node == None:
|
if node == None:
|
||||||
# If we couldn't load the model, at least return an
|
# If we couldn't load the model, at least return an
|
||||||
# empty font.
|
# empty font.
|
||||||
return StaticTextFont(PandaNode("empty"))
|
font = StaticTextFont(PandaNode("empty"))
|
||||||
|
else:
|
||||||
# Create a temp node path so you can adjust priorities
|
# Create a temp node path so you can adjust priorities
|
||||||
nodePath = hidden.attachNewNode(node)
|
nodePath = NodePath(node)
|
||||||
nodePath.adjustAllPriorities(priority)
|
nodePath.adjustAllPriorities(priority)
|
||||||
# Now create the text font from the node
|
# Now create the text font from the node
|
||||||
font = StaticTextFont(node)
|
font = StaticTextFont(node)
|
||||||
|
|
||||||
# And remove the node path.
|
|
||||||
nodePath.removeNode()
|
|
||||||
else:
|
else:
|
||||||
# Otherwise, it must be a new-style, dynamic font. Maybe
|
# Otherwise, it must be a new-style, dynamic font. Maybe
|
||||||
# it's just a TTF file or something.
|
# it's just a TTF file or something.
|
||||||
font = DynamicTextFont(fn, faceIndex)
|
font = DynamicTextFont(fn, faceIndex)
|
||||||
|
|
||||||
|
if lineHeight != None:
|
||||||
|
# If the line height is specified, it overrides whatever
|
||||||
|
# the font itself thinks the line height should be. This
|
||||||
|
# should be called last, since some of the other
|
||||||
|
# parameters can cause the line height to be reset to its
|
||||||
|
# default.
|
||||||
|
|
||||||
|
# temporary try..except for old Pandas.
|
||||||
|
try:
|
||||||
|
font.setLineHeight(lineHeight)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return font
|
return font
|
||||||
|
|
||||||
# texture loading funcs
|
# texture loading funcs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user