@@ -22,6 +22,11 @@ class Font_Glyph_Outline_Simple extends Font_Glyph_Outline {
22
22
23
23
function parse (){
24
24
$ data = parent ::parse ();
25
+
26
+ if (!$ this ->size ) {
27
+ return ;
28
+ }
29
+
25
30
$ font = $ this ->getFont ();
26
31
27
32
$ noc = $ data ["numberOfContours " ];
@@ -108,4 +113,73 @@ function parse(){
108
113
$ this ->table = null ;
109
114
return $ this ->data = $ data ;
110
115
}
116
+
117
+ public function getSVGPath (){
118
+ $ path = "" ;
119
+
120
+ $ points = $ this ->data ["points " ];
121
+ $ length = count ($ points );
122
+ $ firstIndex = 0 ;
123
+ $ count = 0 ;
124
+
125
+ for ($ i = 0 ; $ i < $ length ; $ i ++) {
126
+ $ count ++;
127
+
128
+ if ($ points [$ i ]["endOfContour " ]) {
129
+ $ path .= $ this ->addContourToPath ($ points , $ firstIndex , $ count );
130
+ $ firstIndex = $ i + 1 ;
131
+ $ count = 0 ;
132
+ }
133
+ }
134
+
135
+ return $ path ;
136
+ }
137
+
138
+ protected function addContourToPath ($ points , $ startIndex , $ count ) {
139
+ $ offset = 0 ;
140
+ $ path = "" ;
141
+
142
+ while ($ offset < $ count ) {
143
+ $ point_m1 = $ points [ ($ offset == 0 ) ? ($ startIndex +$ count -1 ) : $ startIndex +($ offset -1 )%$ count ];
144
+ $ point = $ points [ $ startIndex + $ offset %$ count ];
145
+ $ point_p1 = $ points [ $ startIndex + ($ offset +1 )%$ count ];
146
+ $ point_p2 = $ points [ $ startIndex + ($ offset +2 )%$ count ];
147
+
148
+ if ($ offset == 0 ) {
149
+ $ path .= "M {$ point ['x ' ]}, {$ point ['y ' ]} " ;
150
+ }
151
+
152
+ if ($ point ["onCurve " ] && $ point_p1 ["onCurve " ]) {
153
+ $ path .= "Q {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]} " ;
154
+ $ offset ++;
155
+ }
156
+ else if ($ point ["onCurve " ] && !$ point_p1 ["onCurve " ] && $ point_p2 ["onCurve " ]){
157
+ $ path .= "Q {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]}, {$ point_p2 ['x ' ]}, {$ point_p2 ['y ' ]} " ;
158
+ $ offset += 2 ;
159
+ }
160
+ else if ($ point ["onCurve " ] && !$ point_p1 ["onCurve " ] && !$ point_p2 ["onCurve " ]){
161
+ $ path .= "Q {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]}, " .$ this ->midValue ($ point_p1 ['x ' ], $ point_p2 ['x ' ]).", " .$ this ->midValue ($ point_p1 ['y ' ], $ point_p2 ['y ' ])." " ;
162
+ $ offset += 2 ;
163
+ }
164
+ else if (!$ point ["onCurve " ] && !$ point_p1 ["onCurve " ]) {
165
+ $ path .= "Q {$ point ['x ' ]}, {$ point ['y ' ]}, " .$ this ->midValue ($ point ['x ' ], $ point_p1 ['x ' ]).", " .$ this ->midValue ($ point ['y ' ], $ point_p1 ['y ' ])." " ;
166
+ $ offset ++;
167
+ }
168
+ else if (!$ point ["onCurve " ] && $ point_p1 ["onCurve " ]) {
169
+ $ path .= "Q {$ point ['x ' ]}, {$ point ['y ' ]}, {$ point_p1 ['x ' ]}, {$ point_p1 ['y ' ]} " ;
170
+ $ offset ++;
171
+ }
172
+ else {
173
+ break ;
174
+ }
175
+ }
176
+
177
+ $ path .= "z " ;
178
+
179
+ return $ path ;
180
+ }
181
+
182
+ function midValue ($ a , $ b ){
183
+ return $ a + ($ b - $ a )/2 ;
184
+ }
111
185
}
0 commit comments