-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmapchar.monkey
More file actions
108 lines (94 loc) · 4.27 KB
/
bitmapchar.monkey
File metadata and controls
108 lines (94 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#rem monkeydoc module fontmachine.bitmapchar
This module contains the BitMapChar class.
This class represent a character in a BitmapFont.
#end
Import bitmapcharmetrics
'Import mojo.graphics
Import mojo2.graphics
#rem monkeydoc
This class represents a font character and provides methods to load and unload the character images on dynamic fonts, and provide methods to get the location of the char in the packed texture on packed fonts.
Any character in any font, is an instance of this class.
Beaware that this font represent a character layer. That is, each character is a Face character, a Border character or a Shadow character.
#end
Class BitMapChar
#rem monkeydoc
This field contains the drawing metrics information of the character. That is, width, height, space to next character, etc.
#END
Field drawingMetrics:= new BitMapCharMetrics
#rem monkeydoc
This field contains the character image on dynamic fonts.
#END
Field image:Image
#rem monkeydoc
This field contains the texture index on packed fonts. (advanced use)
#END
Field packedFontIndex:int
#rem monkeydoc
This field contains the X and Y offset of the character in the packed texture, on non dynamic fonts.
#END
field packedPosition:drawingpoint.DrawingPoint = new drawingpoint.DrawingPoint
#rem monkeydoc
This field contains the width and height offset of the character in the packed texture, on non dynamic fonts.
#END
Field packedSize:drawingpoint.DrawingPoint = new drawingpoint.DrawingPoint
#rem monkeydoc
This method will force a dynamic font to load the character image to VRam.
#END
Method LoadCharImage()
'if imageResourceName = null Then return
If CharImageLoaded() = False Then
Print("Handle set 1")
image = Image.Load(imageResourceName)
image.SetHandle(-Self.drawingMetrics.drawingOffset.x, -Self.drawingMetrics.drawingOffset.y)
drawingMetrics.drawingOffset.Set(-image.HandleX, -image.HandleX)
image.SetHandle(0, 0)
imageResourceNameBackup = imageResourceName
imageResourceName = ""
endif
End Method
#rem monkeydoc
This method will return true or false if the character image has been loaded to VRam on dynamic fonts.
Notice that this method will return always FALSE for packed fonts.
#end
Method CharImageLoaded:Bool()
if image = null And imageResourceName <> "" then Return False Else Return true
End Method
Method SetImageResourceName(value:String)
imageResourceName = value
End Method
#rem monkeydoc
This method will force a dynamic font to unload the character image from VRam.
#end
Method UnloadCharImage()
if CharImageLoaded() = True Then
image.Discard()
image = null
imageResourceName = imageResourceNameBackup
imageResourceNameBackup = ""
EndIf
End Method
Method DefineKerningPair(secondChar:Int, amount:Int)
If KParis.Contains(secondChar) Then KParis.Remove(secondChar)
KParis.Add(secondChar, amount)
End
Method GetKerningAmountForChar:Int(char:Int)
If KParis.Contains(char) Then
Return KParis.Get(char)
Else
'Print "Kerning applied."
Return 0
EndIf
End
Private
Field imageResourceNameBackup:string
Field imageResourceName:String = ""
Field KParis:= New IntMap<Int>
End Class
#rem
footer:This FontMachine library is released under the MIT license:
[quote]Copyright (c) 2011 Manel Ibáñez
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[/quote]
#end