geomerative 0.4.3-java → 2.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/maven-wrapper.properties +1 -1
- data/CHANGELOG.md +19 -1
- data/COPYING.md +1 -1
- data/README.md +2 -2
- data/Rakefile +2 -15
- data/docs/_config.yml +8 -0
- data/docs/_includes/head.html +7 -6
- data/docs/_includes/header.html +6 -6
- data/docs/_includes/icon-github.svg +3 -1
- data/docs/_includes/icon-twitter.svg +3 -1
- data/docs/_includes/navigation.html +24 -0
- data/docs/_sass/_base.scss +79 -79
- data/docs/_sass/_layout.scss +137 -137
- data/docs/_sass/_syntax-highlighting.scss +64 -64
- data/docs/index.html +18 -18
- data/examples/README.md +1 -1
- data/examples/data/bot1.svg +1 -1
- data/examples/data/lion.svg +156 -156
- data/examples/data/ruby.svg +1 -1
- data/examples/jruby_merge.rb +1 -1
- data/examples/{f_agent.rb → library/f_agent/f_agent.rb} +0 -0
- data/examples/{font_agent.rb → library/font_agent/font_agent.rb} +2 -1
- data/examples/text_on_geomerative_path.rb +3 -2
- data/examples/typo_deform.rb +2 -2
- data/examples/typo_extra_bright.rb +1 -1
- data/geomerative.gemspec +3 -6
- data/lib/geomerative/version.rb +1 -1
- data/lib/geomerative.jar +0 -0
- data/lib/geomerative.rb +10 -10
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.rb +14 -16
- data/pom.xml +13 -19
- data/src/geomerative/FastRClip.java +2050 -2334
- data/src/geomerative/RClip.java +2237 -2539
- data/src/geomerative/RClosest.java +33 -31
- data/src/geomerative/RCommand.java +1750 -1758
- data/src/geomerative/RContour.java +290 -292
- data/src/geomerative/RFont.java +277 -246
- data/src/geomerative/RG.java +722 -727
- data/src/geomerative/RGeomElem.java +967 -962
- data/src/geomerative/RGroup.java +508 -467
- data/src/geomerative/RMatrix.java +304 -289
- data/src/geomerative/RMesh.java +241 -229
- data/src/geomerative/RPath.java +924 -926
- data/src/geomerative/RPoint.java +391 -391
- data/src/geomerative/RPolygon.java +1017 -1013
- data/src/geomerative/RRectangle.java +43 -52
- data/src/geomerative/RSVG.java +480 -516
- data/src/geomerative/RShape.java +1767 -1777
- data/src/geomerative/RStrip.java +173 -176
- data/src/geomerative/RStyle.java +197 -194
- data/src/module-info.java +4 -0
- data/src/org/apache/batik/svggen/font/Font.java +141 -142
- data/src/org/apache/batik/svggen/font/Glyph.java +102 -71
- data/src/org/apache/batik/svggen/font/Point.java +12 -12
- data/src/org/apache/batik/svggen/font/RandomAccessFileEmulator.java +14 -12
- data/src/org/apache/batik/svggen/font/table/ClassDef.java +12 -12
- data/src/org/apache/batik/svggen/font/table/ClassDefFormat1.java +27 -24
- data/src/org/apache/batik/svggen/font/table/ClassDefFormat2.java +20 -17
- data/src/org/apache/batik/svggen/font/table/CmapFormat.java +43 -43
- data/src/org/apache/batik/svggen/font/table/CmapFormat0.java +33 -26
- data/src/org/apache/batik/svggen/font/table/CmapFormat2.java +25 -20
- data/src/org/apache/batik/svggen/font/table/CmapFormat4.java +106 -96
- data/src/org/apache/batik/svggen/font/table/CmapFormat6.java +36 -32
- data/src/org/apache/batik/svggen/font/table/CmapIndexEntry.java +69 -49
- data/src/org/apache/batik/svggen/font/table/CmapTable.java +50 -50
- data/src/org/apache/batik/svggen/font/table/Coverage.java +19 -19
- data/src/org/apache/batik/svggen/font/table/CoverageFormat1.java +30 -27
- data/src/org/apache/batik/svggen/font/table/CoverageFormat2.java +26 -24
- data/src/org/apache/batik/svggen/font/table/CvtTable.java +16 -16
- data/src/org/apache/batik/svggen/font/table/Device.java +32 -32
- data/src/org/apache/batik/svggen/font/table/DirectoryEntry.java +39 -39
- data/src/org/apache/batik/svggen/font/table/Feature.java +26 -23
- data/src/org/apache/batik/svggen/font/table/FeatureList.java +37 -35
- data/src/org/apache/batik/svggen/font/table/FeatureRecord.java +22 -22
- data/src/org/apache/batik/svggen/font/table/FeatureTags.java +4 -3
- data/src/org/apache/batik/svggen/font/table/FpgmTable.java +9 -9
- data/src/org/apache/batik/svggen/font/table/GlyfCompositeComp.java +134 -132
- data/src/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java +123 -122
- data/src/org/apache/batik/svggen/font/table/GlyfDescript.java +44 -44
- data/src/org/apache/batik/svggen/font/table/GlyfSimpleDescript.java +110 -109
- data/src/org/apache/batik/svggen/font/table/GlyfTable.java +46 -46
- data/src/org/apache/batik/svggen/font/table/GlyphDescription.java +25 -13
- data/src/org/apache/batik/svggen/font/table/GposTable.java +26 -23
- data/src/org/apache/batik/svggen/font/table/GsubTable.java +85 -82
- data/src/org/apache/batik/svggen/font/table/HeadTable.java +131 -131
- data/src/org/apache/batik/svggen/font/table/HheaTable.java +80 -80
- data/src/org/apache/batik/svggen/font/table/HmtxTable.java +50 -49
- data/src/org/apache/batik/svggen/font/table/KernSubtable.java +29 -27
- data/src/org/apache/batik/svggen/font/table/KernSubtableFormat0.java +35 -32
- data/src/org/apache/batik/svggen/font/table/KernSubtableFormat2.java +28 -26
- data/src/org/apache/batik/svggen/font/table/KernTable.java +36 -31
- data/src/org/apache/batik/svggen/font/table/KerningPair.java +27 -23
- data/src/org/apache/batik/svggen/font/table/LangSys.java +28 -26
- data/src/org/apache/batik/svggen/font/table/LangSysRecord.java +22 -22
- data/src/org/apache/batik/svggen/font/table/Ligature.java +24 -24
- data/src/org/apache/batik/svggen/font/table/LigatureSet.java +24 -24
- data/src/org/apache/batik/svggen/font/table/LigatureSubst.java +9 -9
- data/src/org/apache/batik/svggen/font/table/LigatureSubstFormat1.java +30 -30
- data/src/org/apache/batik/svggen/font/table/LocaTable.java +37 -37
- data/src/org/apache/batik/svggen/font/table/Lookup.java +41 -40
- data/src/org/apache/batik/svggen/font/table/LookupList.java +34 -34
- data/src/org/apache/batik/svggen/font/table/LookupSubtableFactory.java +7 -5
- data/src/org/apache/batik/svggen/font/table/MaxpTable.java +96 -96
- data/src/org/apache/batik/svggen/font/table/NameRecord.java +64 -65
- data/src/org/apache/batik/svggen/font/table/NameTable.java +33 -33
- data/src/org/apache/batik/svggen/font/table/Os2Table.java +196 -196
- data/src/org/apache/batik/svggen/font/table/Panose.java +14 -12
- data/src/org/apache/batik/svggen/font/table/PostTable.java +338 -338
- data/src/org/apache/batik/svggen/font/table/PrepTable.java +9 -9
- data/src/org/apache/batik/svggen/font/table/Program.java +15 -15
- data/src/org/apache/batik/svggen/font/table/RangeRecord.java +26 -25
- data/src/org/apache/batik/svggen/font/table/Script.java +38 -38
- data/src/org/apache/batik/svggen/font/table/ScriptList.java +42 -42
- data/src/org/apache/batik/svggen/font/table/ScriptRecord.java +22 -22
- data/src/org/apache/batik/svggen/font/table/ScriptTags.java +2 -1
- data/src/org/apache/batik/svggen/font/table/SingleSubst.java +15 -16
- data/src/org/apache/batik/svggen/font/table/SingleSubstFormat1.java +33 -33
- data/src/org/apache/batik/svggen/font/table/SingleSubstFormat2.java +32 -32
- data/src/org/apache/batik/svggen/font/table/Table.java +171 -170
- data/src/org/apache/batik/svggen/font/table/TableDirectory.java +55 -55
- data/src/org/apache/batik/svggen/font/table/TableFactory.java +92 -93
- metadata +18 -19
- data/.travis.yml +0 -10
- data/calculate_torsional_angle.rb +0 -17
data/src/geomerative/RFont.java
CHANGED
@@ -1,110 +1,130 @@
|
|
1
1
|
/**
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
*/
|
19
|
-
|
2
|
+
* Copyright 2004-2008 Ricard Marxer <email@ricardmarxer.com>
|
3
|
+
*
|
4
|
+
* This file is part of Geomerative.
|
5
|
+
*
|
6
|
+
* Geomerative is free software: you can redistribute it and/or modify it under
|
7
|
+
* the terms of the GNU General Public License as published by the Free Software
|
8
|
+
* Foundation, either version 3 of the License, or (at your option) any later
|
9
|
+
* version.
|
10
|
+
*
|
11
|
+
* Geomerative is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14
|
+
* details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU General Public License along with
|
17
|
+
* Geomerative. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
20
19
|
package geomerative;
|
21
|
-
|
22
|
-
|
23
|
-
import
|
24
|
-
import
|
20
|
+
import java.io.IOException;
|
21
|
+
import java.nio.file.Files;
|
22
|
+
import java.nio.file.Path;
|
23
|
+
import java.nio.file.Paths;
|
24
|
+
import org.apache.batik.svggen.font.Font;
|
25
|
+
import org.apache.batik.svggen.font.Glyph;
|
26
|
+
import org.apache.batik.svggen.font.Point;
|
27
|
+
import org.apache.batik.svggen.font.table.CmapFormat;
|
28
|
+
import org.apache.batik.svggen.font.table.SingleSubst;
|
25
29
|
import processing.core.PApplet;
|
26
30
|
import processing.core.PConstants;
|
27
31
|
import processing.core.PGraphics;
|
28
32
|
|
29
33
|
/**
|
30
|
-
* RShape is a reduced interface for creating, holding and drawing text from
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
34
|
+
* RShape is a reduced interface for creating, holding and drawing text from
|
35
|
+
* TrueType Font files. It's a basic interpreter of TrueType fonts enabling to
|
36
|
+
* access any String in the form of a group of shapes. Enabling us in this way
|
37
|
+
* to access their geometry.
|
38
|
+
*
|
39
|
+
RFont
|
40
|
+
* Geometry
|
41
|
+
* RGroup
|
34
42
|
*
|
35
|
-
|
43
|
+
|
36
44
|
*/
|
37
|
-
public class RFont implements PConstants{
|
45
|
+
public class RFont implements PConstants {
|
46
|
+
|
38
47
|
Font f;
|
39
48
|
float scaleFactor = 0.2F;
|
40
49
|
//int scaleFactorFixed = 1;
|
41
|
-
|
50
|
+
|
42
51
|
/**
|
43
|
-
* The point size of the font.
|
44
|
-
*
|
45
|
-
|
46
|
-
*
|
52
|
+
* The point size of the font.
|
53
|
+
*
|
54
|
+
size
|
55
|
+
* setSize ( )
|
56
|
+
* RFont
|
47
57
|
*/
|
48
58
|
public int size = DEFAULT_SIZE;
|
49
|
-
|
59
|
+
|
50
60
|
/**
|
51
|
-
* The alignment of the font. This property can take the following values:
|
52
|
-
*
|
53
|
-
*
|
54
|
-
|
61
|
+
* The alignment of the font. This property can take the following values:
|
62
|
+
* RFont.LEFT, RFont.CENTER and RFont.RIGHT
|
63
|
+
*
|
64
|
+
align
|
65
|
+
* setAlign ( )
|
66
|
+
* RFont
|
55
67
|
*/
|
56
68
|
public int align = DEFAULT_ALIGN;
|
57
|
-
|
69
|
+
|
58
70
|
final static int DEFAULT_SIZE = 48;
|
59
71
|
final static int DEFAULT_RESOLUTION = 72;
|
60
72
|
final static int DEFAULT_ALIGN = RFont.LEFT;
|
61
|
-
|
73
|
+
|
62
74
|
/**
|
63
75
|
* Should we try to use ASCII, rather than Unicode?
|
64
76
|
*/
|
65
77
|
public boolean forceAscii = false;
|
66
|
-
|
67
|
-
|
78
|
+
|
68
79
|
/**
|
69
|
-
* The constructor of the RFont object.
|
70
|
-
*
|
71
|
-
*
|
80
|
+
* The constructor of the RFont object. Use this in order to create a font
|
81
|
+
* with which we will be able to draw and obtain outlines of text.
|
82
|
+
*
|
83
|
+
RFont
|
84
|
+
* @param fontPath String, the name of the TrueType Font file which should be
|
85
|
+
* situated in the data folder of the sketch.
|
72
86
|
* @param size int, the point size of the font in points.
|
73
|
-
* @param align int, this can only take the following values: RFont.LEFT,
|
74
|
-
*
|
75
|
-
*
|
76
|
-
*
|
77
|
-
*
|
78
|
-
*
|
87
|
+
* @param align int, this can only take the following values: RFont.LEFT,
|
88
|
+
* RFont.CENTER and RFont.RIGHT.
|
89
|
+
* toGroup ( )
|
90
|
+
* toShape ( )
|
91
|
+
* toPolygon ( )
|
92
|
+
* toMesh ( )
|
93
|
+
* draw ( )
|
79
94
|
*/
|
80
|
-
public RFont(String fontPath, int size, int align)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
95
|
+
public RFont(String fontPath, int size, int align) {
|
96
|
+
try {
|
97
|
+
// Try to find the font as font path
|
98
|
+
Path path = Paths.get(fontPath);
|
99
|
+
f = Font.create(Files.readAllBytes(path));
|
100
|
+
setSize(size);
|
101
|
+
setAlign(align);
|
102
|
+
} catch (IOException ex) {
|
103
|
+
System.err.println(fontPath + " not found or unreadable");
|
104
|
+
System.exit(2);
|
105
|
+
}
|
87
106
|
}
|
88
|
-
|
89
|
-
public RFont(String fontPath, int size)
|
107
|
+
|
108
|
+
public RFont(String fontPath, int size) {
|
90
109
|
this(fontPath, size, DEFAULT_ALIGN);
|
91
110
|
}
|
92
|
-
|
93
|
-
public RFont(String fontPath)
|
111
|
+
|
112
|
+
public RFont(String fontPath) {
|
94
113
|
this(fontPath, DEFAULT_SIZE, DEFAULT_ALIGN);
|
95
114
|
}
|
96
|
-
|
115
|
+
|
97
116
|
/**
|
98
117
|
* Use this method to reset the point size of the font.
|
99
|
-
*
|
118
|
+
*
|
119
|
+
setSize
|
100
120
|
* @param size int, the point size of the font in points.
|
101
|
-
*
|
102
|
-
*
|
121
|
+
* size
|
122
|
+
* RFont
|
103
123
|
*/
|
104
|
-
public final void setSize(int size){
|
124
|
+
public final void setSize(int size) {
|
105
125
|
short unitsPerEm = f.getHeadTable().getUnitsPerEm();
|
106
126
|
int resolution = RG.dpi();
|
107
|
-
this.scaleFactor = ((float)size * (float)resolution) / (72F * (float)unitsPerEm);
|
127
|
+
this.scaleFactor = ((float) size * (float) resolution) / (72F * (float) unitsPerEm);
|
108
128
|
//this.scaleFactorFixed = (int)(this.scaleFactor * 65536F);
|
109
129
|
//System.out.println(scaleFactor);
|
110
130
|
//System.out.println(scaleFactorFixed);
|
@@ -135,110 +155,120 @@ public class RFont implements PConstants{
|
|
135
155
|
|
136
156
|
return hheaLineGap;
|
137
157
|
}
|
138
|
-
|
158
|
+
|
139
159
|
/**
|
140
|
-
* Use this method to reset the alignment of the font. This property can take
|
141
|
-
*
|
142
|
-
*
|
143
|
-
|
144
|
-
* @
|
160
|
+
* Use this method to reset the alignment of the font. This property can take
|
161
|
+
* the following values: RFont.LEFT, RFont.CENTER and RFont.RIGHT
|
162
|
+
*
|
163
|
+
setAlign
|
164
|
+
* @param align int, this can only take the following values: RFont.LEFT,
|
165
|
+
* RFont.CENTER and RFont.RIGHT.
|
166
|
+
* align
|
167
|
+
* RFont
|
145
168
|
*/
|
146
|
-
public final void setAlign(int align) throws RuntimeException{
|
147
|
-
if(align!=LEFT && align!=CENTER && align!=RIGHT){
|
169
|
+
public final void setAlign(int align) throws RuntimeException {
|
170
|
+
if (align != LEFT && align != CENTER && align != RIGHT) {
|
148
171
|
throw new RuntimeException("Alignment unknown. The only accepted values are: RFont.LEFT, RFont.CENTER and RFont.RIGHT");
|
149
172
|
}
|
150
173
|
this.align = align;
|
151
174
|
}
|
152
|
-
|
175
|
+
|
153
176
|
/**
|
154
|
-
|
155
|
-
*
|
156
|
-
|
157
|
-
public String getFamily(){
|
177
|
+
* @return
|
178
|
+
*
|
179
|
+
*/
|
180
|
+
public String getFamily() {
|
158
181
|
return f.getNameTable().getRecord(org.apache.batik.svggen.font.table.Table.nameFontFamilyName);
|
159
182
|
}
|
160
|
-
|
183
|
+
|
161
184
|
/**
|
162
|
-
* Use this method to get the outlines of a character in the form of an
|
163
|
-
*
|
185
|
+
* Use this method to get the outlines of a character in the form of an
|
186
|
+
* RShape.
|
187
|
+
*
|
188
|
+
RFont_toShape
|
164
189
|
* @param character char, the character we want the outline from.
|
165
190
|
* @return RShape, the outline of the character.
|
166
|
-
*
|
167
|
-
*
|
168
|
-
*
|
191
|
+
* toGroup ( )
|
192
|
+
* toPolygon ( )
|
193
|
+
* draw ( )
|
169
194
|
*/
|
170
|
-
public RShape toShape(char character){
|
195
|
+
public RShape toShape(char character) {
|
171
196
|
RGroup grp = toGroup(Character.toString(character));
|
172
|
-
if(grp.countElements()>0)
|
197
|
+
if (grp.countElements() > 0) {
|
198
|
+
return (RShape) (grp.elements[0]);
|
199
|
+
}
|
173
200
|
return new RShape();
|
174
201
|
}
|
175
|
-
|
202
|
+
|
176
203
|
/**
|
177
|
-
* Use this method to get the outlines of a character in the form of an
|
178
|
-
*
|
204
|
+
* Use this method to get the outlines of a character in the form of an
|
205
|
+
* RPolygon.
|
206
|
+
*
|
207
|
+
RFont_toPolygon
|
179
208
|
* @param character char, the character we want the outline from.
|
180
209
|
* @return RPolygon, the outline of the character.
|
181
|
-
*
|
182
|
-
*
|
183
|
-
*
|
210
|
+
* toGroup ( )
|
211
|
+
* toShape ( )
|
212
|
+
* draw ( )
|
184
213
|
*/
|
185
214
|
public RPolygon toPolygon(char character) {
|
186
215
|
return toShape(character).toPolygon();
|
187
216
|
}
|
188
|
-
|
189
|
-
|
217
|
+
|
190
218
|
private CmapFormat getCmapFormat() {
|
191
219
|
if (forceAscii) {
|
192
220
|
// We've been asked to use the ASCII/Macintosh cmap format
|
193
221
|
return f.getCmapTable().getCmapFormat(
|
194
|
-
|
195
|
-
|
222
|
+
org.apache.batik.svggen.font.table.Table.platformMacintosh,
|
223
|
+
org.apache.batik.svggen.font.table.Table.encodingRoman);
|
196
224
|
} else {
|
197
|
-
short[] platforms = new short[]
|
225
|
+
short[] platforms = new short[]{
|
198
226
|
org.apache.batik.svggen.font.table.Table.platformMicrosoft,
|
199
227
|
org.apache.batik.svggen.font.table.Table.platformAppleUnicode,
|
200
228
|
org.apache.batik.svggen.font.table.Table.platformMacintosh
|
201
229
|
};
|
202
|
-
short[] encodings = new short[]
|
230
|
+
short[] encodings = new short[]{
|
203
231
|
org.apache.batik.svggen.font.table.Table.encodingUGL,
|
204
232
|
org.apache.batik.svggen.font.table.Table.encodingKorean,
|
205
233
|
org.apache.batik.svggen.font.table.Table.encodingHebrew,
|
206
234
|
org.apache.batik.svggen.font.table.Table.encodingUndefined
|
207
235
|
};
|
208
|
-
|
236
|
+
|
209
237
|
CmapFormat cmapFmt;
|
210
|
-
for(int i = 0; i < encodings.length; i++) {
|
211
|
-
for(int j = 0; j < platforms.length; j++) {
|
212
|
-
|
238
|
+
for (int i = 0; i < encodings.length; i++) {
|
239
|
+
for (int j = 0; j < platforms.length; j++) {
|
240
|
+
|
213
241
|
cmapFmt = f.getCmapTable().getCmapFormat(platforms[j], encodings[i]);
|
214
242
|
if (cmapFmt != null) {
|
215
243
|
return cmapFmt;
|
216
|
-
}
|
217
|
-
|
244
|
+
}
|
245
|
+
}
|
218
246
|
}
|
219
247
|
return null;
|
220
248
|
}
|
221
249
|
}
|
222
250
|
|
223
|
-
|
224
251
|
/**
|
225
|
-
* Use this method to get the outlines of a string in the form of an RGroup.
|
226
|
-
*
|
252
|
+
* Use this method to get the outlines of a string in the form of an RGroup.
|
253
|
+
* All the elements of the group will be RShapes.
|
254
|
+
*
|
255
|
+
RFont_toGroup
|
227
256
|
* @param text String, the string we want the outlines from.
|
228
|
-
* @return RGroup, the group of outlines of the character.
|
229
|
-
*
|
230
|
-
*
|
257
|
+
* @return RGroup, the group of outlines of the character. All the elements
|
258
|
+
* are RShapes.
|
259
|
+
* toShape ( )
|
260
|
+
* draw ( )
|
231
261
|
*/
|
232
|
-
public RGroup toGroup(String text)
|
262
|
+
public RGroup toGroup(String text) throws RuntimeException {
|
233
263
|
RGroup result = new RGroup();
|
234
|
-
|
264
|
+
|
235
265
|
// Decide upon a cmap table to use for our character to glyph look-up
|
236
266
|
CmapFormat cmapFmt = getCmapFormat();
|
237
|
-
|
267
|
+
|
238
268
|
if (cmapFmt == null) {
|
239
269
|
throw new RuntimeException("Cannot find a suitable cmap table");
|
240
270
|
}
|
241
|
-
|
271
|
+
|
242
272
|
// If this font includes arabic script, we want to specify
|
243
273
|
// substitutions for initial, medial, terminal & isolated
|
244
274
|
// cases.
|
@@ -265,7 +295,6 @@ public class RFont implements PConstants{
|
|
265
295
|
}
|
266
296
|
}
|
267
297
|
}*/
|
268
|
-
|
269
298
|
int x = 0;
|
270
299
|
for (short i = 0; i < text.length(); i++) {
|
271
300
|
int glyphIndex = cmapFmt.mapCharCode(text.charAt(i));
|
@@ -274,50 +303,50 @@ public class RFont implements PConstants{
|
|
274
303
|
if (glyph != null) {
|
275
304
|
glyph.scale(scaleFactor);
|
276
305
|
// Add the Glyph to the Shape with an horizontal offset of x
|
277
|
-
result.addElement(getGlyphAsShape(f,glyph, glyphIndex,x));
|
306
|
+
result.addElement(getGlyphAsShape(f, glyph, glyphIndex, x));
|
278
307
|
x += glyph.getAdvanceWidth();
|
279
|
-
}else{
|
280
|
-
x += (int)((float)default_advance_x*scaleFactor);
|
308
|
+
} else {
|
309
|
+
x += (int) ((float) default_advance_x * scaleFactor);
|
281
310
|
}
|
282
|
-
|
311
|
+
|
283
312
|
}
|
284
|
-
|
285
|
-
if(align!=LEFT && align!=CENTER && align!=RIGHT){
|
313
|
+
|
314
|
+
if (align != LEFT && align != CENTER && align != RIGHT) {
|
286
315
|
throw new RuntimeException("Alignment unknown. The only accepted values are: RFont.LEFT, RFont.CENTER and RFont.RIGHT");
|
287
316
|
}
|
288
|
-
|
317
|
+
|
289
318
|
RRectangle r;
|
290
319
|
RMatrix mattrans;
|
291
320
|
|
292
|
-
switch(this.align){
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
321
|
+
switch (this.align) {
|
322
|
+
case RFont.CENTER:
|
323
|
+
r = result.getBounds();
|
324
|
+
mattrans = new RMatrix();
|
325
|
+
mattrans.translate((r.getMinX() - r.getMaxX()) / 2, 0);
|
326
|
+
result.transform(mattrans);
|
327
|
+
break;
|
328
|
+
case RFont.RIGHT:
|
329
|
+
r = result.getBounds();
|
330
|
+
mattrans = new RMatrix();
|
331
|
+
mattrans.translate((r.getMinX() - r.getMaxX()), 0);
|
332
|
+
result.transform(mattrans);
|
333
|
+
break;
|
334
|
+
case RFont.LEFT:
|
335
|
+
break;
|
307
336
|
}
|
308
337
|
return result;
|
309
338
|
}
|
310
339
|
|
311
|
-
public RShape toShape(String text)
|
340
|
+
public RShape toShape(String text) throws RuntimeException {
|
312
341
|
RShape result = new RShape();
|
313
|
-
|
342
|
+
|
314
343
|
// Decide upon a cmap table to use for our character to glyph look-up
|
315
344
|
CmapFormat cmapFmt = getCmapFormat();
|
316
|
-
|
345
|
+
|
317
346
|
if (cmapFmt == null) {
|
318
347
|
throw new RuntimeException("Cannot find a suitable cmap table");
|
319
348
|
}
|
320
|
-
|
349
|
+
|
321
350
|
// If this font includes arabic script, we want to specify
|
322
351
|
// substitutions for initial, medial, terminal & isolated
|
323
352
|
// cases.
|
@@ -344,7 +373,6 @@ public class RFont implements PConstants{
|
|
344
373
|
}
|
345
374
|
}
|
346
375
|
}*/
|
347
|
-
|
348
376
|
int x = 0;
|
349
377
|
for (short i = 0; i < text.length(); i++) {
|
350
378
|
int glyphIndex = cmapFmt.mapCharCode(text.charAt(i));
|
@@ -353,147 +381,150 @@ public class RFont implements PConstants{
|
|
353
381
|
if (glyph != null) {
|
354
382
|
glyph.scale(scaleFactor);
|
355
383
|
// Add the Glyph to the Shape with an horizontal offset of x
|
356
|
-
result.addChild(getGlyphAsShape(f,glyph, glyphIndex,x));
|
384
|
+
result.addChild(getGlyphAsShape(f, glyph, glyphIndex, x));
|
357
385
|
x += glyph.getAdvanceWidth();
|
358
|
-
}else{
|
359
|
-
x += (int)((float)default_advance_x*scaleFactor);
|
386
|
+
} else {
|
387
|
+
x += (int) ((float) default_advance_x * scaleFactor);
|
360
388
|
}
|
361
|
-
|
389
|
+
|
362
390
|
}
|
363
|
-
|
364
|
-
if(align!=LEFT && align!=CENTER && align!=RIGHT){
|
391
|
+
|
392
|
+
if (align != LEFT && align != CENTER && align != RIGHT) {
|
365
393
|
throw new RuntimeException("Alignment unknown. The only accepted values are: RFont.LEFT, RFont.CENTER and RFont.RIGHT");
|
366
394
|
}
|
367
|
-
|
395
|
+
|
368
396
|
RRectangle r;
|
369
397
|
RMatrix mattrans;
|
370
398
|
|
371
|
-
switch(this.align){
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
399
|
+
switch (this.align) {
|
400
|
+
case RFont.CENTER:
|
401
|
+
r = result.getBounds();
|
402
|
+
mattrans = new RMatrix();
|
403
|
+
mattrans.translate((r.getMinX() - r.getMaxX()) / 2, 0);
|
404
|
+
result.transform(mattrans);
|
405
|
+
break;
|
406
|
+
case RFont.RIGHT:
|
407
|
+
r = result.getBounds();
|
408
|
+
mattrans = new RMatrix();
|
409
|
+
mattrans.translate((r.getMinX() - r.getMaxX()), 0);
|
410
|
+
result.transform(mattrans);
|
411
|
+
break;
|
412
|
+
case RFont.LEFT:
|
413
|
+
break;
|
386
414
|
}
|
387
415
|
return result;
|
388
416
|
}
|
389
|
-
|
417
|
+
|
390
418
|
/**
|
391
419
|
* Use this method to draw a character on a certain canvas.
|
392
|
-
*
|
393
|
-
|
394
|
-
* @param
|
395
|
-
* @
|
396
|
-
*
|
420
|
+
*
|
421
|
+
RFont_draw
|
422
|
+
* @param character the character to be drawn
|
423
|
+
* @param g the canvas where to draw
|
424
|
+
* toShape ( )
|
425
|
+
* toGroup ( )
|
397
426
|
*/
|
398
|
-
public void draw(char character, PGraphics g) throws RuntimeException{
|
427
|
+
public void draw(char character, PGraphics g) throws RuntimeException {
|
399
428
|
this.toShape(character).draw(g);
|
400
429
|
}
|
401
|
-
|
430
|
+
|
402
431
|
/**
|
403
432
|
* Use this method to draw a character on a certain canvas.
|
404
|
-
*
|
405
|
-
|
406
|
-
* @param
|
407
|
-
* @
|
408
|
-
*
|
409
|
-
|
410
|
-
|
433
|
+
*
|
434
|
+
RFont_draw
|
435
|
+
* @param text the string to be drawn
|
436
|
+
* @param g the canvas where to draw
|
437
|
+
* toShape ( )
|
438
|
+
* toGroup ( )
|
439
|
+
*/
|
440
|
+
public void draw(String text, PGraphics g) throws RuntimeException {
|
411
441
|
this.toGroup(text).draw(g);
|
412
442
|
}
|
413
|
-
|
443
|
+
|
414
444
|
/**
|
415
445
|
* Use this method to draw a character on a certain canvas.
|
416
|
-
*
|
446
|
+
*
|
447
|
+
RFont_draw
|
417
448
|
* @param character char, the character to be drawn
|
418
|
-
* @param g
|
419
|
-
*
|
420
|
-
*
|
449
|
+
* @param g the canvas where to draw
|
450
|
+
* toShape ( )
|
451
|
+
* toGroup ( )
|
421
452
|
*/
|
422
|
-
public void draw(char character, PApplet g) throws RuntimeException{
|
453
|
+
public void draw(char character, PApplet g) throws RuntimeException {
|
423
454
|
this.toShape(character).draw(g);
|
424
455
|
}
|
425
|
-
|
456
|
+
|
426
457
|
/**
|
427
458
|
* Use this method to draw a character on a certain canvas.
|
428
|
-
*
|
429
|
-
|
430
|
-
* @param
|
431
|
-
* @
|
432
|
-
*
|
433
|
-
|
434
|
-
|
459
|
+
*
|
460
|
+
RFont_draw
|
461
|
+
* @param text the string to be drawn
|
462
|
+
* @param g the canvas where to draw
|
463
|
+
* toShape ( )
|
464
|
+
* toGroup ( )
|
465
|
+
*/
|
466
|
+
public void draw(String text, PApplet g) throws RuntimeException {
|
435
467
|
this.toGroup(text).draw(g);
|
436
468
|
}
|
437
|
-
|
438
|
-
public void draw(String text) throws RuntimeException{
|
469
|
+
|
470
|
+
public void draw(String text) throws RuntimeException {
|
439
471
|
this.toGroup(text).draw();
|
440
472
|
}
|
441
|
-
|
442
|
-
public void draw(char character) throws RuntimeException{
|
473
|
+
|
474
|
+
public void draw(char character) throws RuntimeException {
|
443
475
|
this.toShape(character).draw();
|
444
|
-
}
|
445
|
-
|
446
|
-
|
476
|
+
}
|
477
|
+
|
447
478
|
private static float midValue(float a, float b) {
|
448
|
-
return a + (b - a)/2;
|
479
|
+
return a + (b - a) / 2;
|
449
480
|
}
|
450
|
-
|
481
|
+
|
451
482
|
protected static RShape getContourAsShape(Glyph glyph, int startIndex, int count) {
|
452
483
|
return getContourAsShape(glyph, startIndex, count, 0);
|
453
484
|
}
|
454
|
-
|
485
|
+
|
455
486
|
protected static RShape getContourAsShape(Glyph glyph, int startIndex, int count, float xadv) {
|
456
|
-
|
487
|
+
|
457
488
|
// If this is a single point on it's own, weSystem.out.println("Value of pointx: "+pointx); can't do anything with it
|
458
489
|
if (glyph.getPoint(startIndex).endOfContour) {
|
459
490
|
return new RShape();
|
460
491
|
}
|
461
|
-
|
492
|
+
|
462
493
|
RShape result = new RShape();
|
463
494
|
int offset = 0;
|
464
495
|
//float originx = 0F,originy = 0F;
|
465
|
-
|
496
|
+
|
466
497
|
while (offset < count) {
|
467
|
-
Point point = glyph.getPoint(startIndex + offset%count);
|
468
|
-
Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count);
|
469
|
-
Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count);
|
470
|
-
|
471
|
-
float pointx = ((float)point.x + xadv);
|
472
|
-
float pointy = ((float)point.y);
|
473
|
-
float point_plus1x = ((float)point_plus1.x + xadv);
|
474
|
-
float point_plus1y = ((float)point_plus1.y);
|
475
|
-
float point_plus2x = ((float)point_plus2.x + xadv);
|
476
|
-
float point_plus2y = ((float)point_plus2.y);
|
477
|
-
|
498
|
+
Point point = glyph.getPoint(startIndex + offset % count);
|
499
|
+
Point point_plus1 = glyph.getPoint(startIndex + (offset + 1) % count);
|
500
|
+
Point point_plus2 = glyph.getPoint(startIndex + (offset + 2) % count);
|
501
|
+
|
502
|
+
float pointx = ((float) point.x + xadv);
|
503
|
+
float pointy = ((float) point.y);
|
504
|
+
float point_plus1x = ((float) point_plus1.x + xadv);
|
505
|
+
float point_plus1y = ((float) point_plus1.y);
|
506
|
+
float point_plus2x = ((float) point_plus2.x + xadv);
|
507
|
+
float point_plus2y = ((float) point_plus2.y);
|
508
|
+
|
478
509
|
if (offset == 0) {
|
479
510
|
// move command
|
480
|
-
result.addMoveTo(pointx,pointy);
|
511
|
+
result.addMoveTo(pointx, pointy);
|
481
512
|
}
|
482
|
-
|
513
|
+
|
483
514
|
if (point.onCurve && point_plus1.onCurve) {
|
484
515
|
// line command
|
485
|
-
result.addLineTo(point_plus1x,point_plus1y);
|
516
|
+
result.addLineTo(point_plus1x, point_plus1y);
|
486
517
|
offset++;
|
487
518
|
} else if (point.onCurve && !point_plus1.onCurve && point_plus2.onCurve) {
|
488
519
|
// This is a curve with no implied points
|
489
520
|
// quadratic bezier command
|
490
521
|
result.addQuadTo(point_plus1x, point_plus1y, point_plus2x, point_plus2y);
|
491
|
-
offset+=2;
|
522
|
+
offset += 2;
|
492
523
|
} else if (point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve) {
|
493
524
|
// This is a curve with one implied point
|
494
525
|
// quadratic bezier command avec le endPoint implicit
|
495
526
|
result.addQuadTo(point_plus1x, point_plus1y, midValue(point_plus1x, point_plus2x), midValue(point_plus1y, point_plus2y));
|
496
|
-
offset+=2;
|
527
|
+
offset += 2;
|
497
528
|
} else if (!point.onCurve && !point_plus1.onCurve) {
|
498
529
|
// This is a curve with two implied points
|
499
530
|
// quadratic bezier with
|
@@ -511,18 +542,18 @@ public class RFont implements PConstants{
|
|
511
542
|
result.addClose();
|
512
543
|
return result;
|
513
544
|
}
|
514
|
-
|
545
|
+
|
515
546
|
protected static RShape getGlyphAsShape(Font font, Glyph glyph, int glyphIndex) {
|
516
|
-
return getGlyphAsShape(font,glyph,glyphIndex,0);
|
547
|
+
return getGlyphAsShape(font, glyph, glyphIndex, 0);
|
517
548
|
}
|
518
|
-
|
519
|
-
protected static RShape getGlyphAsShape(Font font, Glyph glyph, int glyphIndex,float xadv) {
|
520
|
-
|
549
|
+
|
550
|
+
protected static RShape getGlyphAsShape(Font font, Glyph glyph, int glyphIndex, float xadv) {
|
551
|
+
|
521
552
|
RShape result = new RShape();
|
522
553
|
int firstIndex = 0;
|
523
554
|
int count = 0;
|
524
555
|
int i;
|
525
|
-
|
556
|
+
|
526
557
|
if (glyph != null) {
|
527
558
|
for (i = 0; i < glyph.getPointCount(); i++) {
|
528
559
|
count++;
|
@@ -533,19 +564,19 @@ public class RFont implements PConstants{
|
|
533
564
|
}
|
534
565
|
}
|
535
566
|
}
|
536
|
-
|
567
|
+
|
537
568
|
return result;
|
538
569
|
}
|
539
|
-
|
570
|
+
|
540
571
|
protected static RShape getGlyphAsShape(Font font, Glyph glyph, int glyphIndex, SingleSubst arabInitSubst, SingleSubst arabMediSubst, SingleSubst arabTermSubst) {
|
541
572
|
return getGlyphAsShape(font, glyph, glyphIndex, arabInitSubst, arabMediSubst, arabTermSubst, 0);
|
542
573
|
}
|
543
|
-
|
574
|
+
|
544
575
|
protected static RShape getGlyphAsShape(Font font, Glyph glyph, int glyphIndex, SingleSubst arabInitSubst, SingleSubst arabMediSubst, SingleSubst arabTermSubst, float xadv) {
|
545
|
-
|
576
|
+
|
546
577
|
RShape result = new RShape();
|
547
578
|
boolean substituted = false;
|
548
|
-
|
579
|
+
|
549
580
|
// arabic = "initial | medial | terminal | isolated"
|
550
581
|
int arabInitGlyphIndex = glyphIndex;
|
551
582
|
int arabMediGlyphIndex = glyphIndex;
|
@@ -559,28 +590,28 @@ public class RFont implements PConstants{
|
|
559
590
|
if (arabTermSubst != null) {
|
560
591
|
arabTermGlyphIndex = arabTermSubst.substitute(glyphIndex);
|
561
592
|
}
|
562
|
-
|
593
|
+
|
563
594
|
if (arabInitGlyphIndex != glyphIndex) {
|
564
|
-
result.addShape(getGlyphAsShape(font,font.getGlyph(arabInitGlyphIndex),arabInitGlyphIndex));
|
595
|
+
result.addShape(getGlyphAsShape(font, font.getGlyph(arabInitGlyphIndex), arabInitGlyphIndex));
|
565
596
|
substituted = true;
|
566
597
|
}
|
567
|
-
|
598
|
+
|
568
599
|
if (arabMediGlyphIndex != glyphIndex) {
|
569
|
-
result.addShape(getGlyphAsShape(font,font.getGlyph(arabMediGlyphIndex),arabMediGlyphIndex));
|
600
|
+
result.addShape(getGlyphAsShape(font, font.getGlyph(arabMediGlyphIndex), arabMediGlyphIndex));
|
570
601
|
substituted = true;
|
571
602
|
}
|
572
|
-
|
603
|
+
|
573
604
|
if (arabTermGlyphIndex != glyphIndex) {
|
574
|
-
result.addShape(getGlyphAsShape(font,font.getGlyph(arabTermGlyphIndex),arabTermGlyphIndex));
|
605
|
+
result.addShape(getGlyphAsShape(font, font.getGlyph(arabTermGlyphIndex), arabTermGlyphIndex));
|
575
606
|
substituted = true;
|
576
607
|
}
|
577
|
-
|
608
|
+
|
578
609
|
if (substituted) {
|
579
|
-
result.addShape(getGlyphAsShape(font,glyph,glyphIndex));
|
610
|
+
result.addShape(getGlyphAsShape(font, glyph, glyphIndex));
|
580
611
|
} else {
|
581
|
-
result.addShape(getGlyphAsShape(font,glyph,glyphIndex));
|
612
|
+
result.addShape(getGlyphAsShape(font, glyph, glyphIndex));
|
582
613
|
}
|
583
|
-
|
614
|
+
|
584
615
|
return result;
|
585
616
|
}
|
586
617
|
}
|