(empty log message)
@@ -112,6 +112,11 @@ | ||
112 | 112 | <groupId>org.apache.maven.plugins</groupId> |
113 | 113 | <artifactId>maven-javadoc-plugin</artifactId> |
114 | 114 | <configuration> |
115 | + <includeDependencySources>true</includeDependencySources> | |
116 | + <dependencySourceExcludes> | |
117 | + <dependencySourceExclude>javax.servlet:*</dependencySourceExclude> | |
118 | + <dependencySourceExclude>net.zamasoft:zs-plugin</dependencySourceExclude> | |
119 | + </dependencySourceExcludes> | |
115 | 120 | <source>1.8</source> |
116 | 121 | <encoding>UTF-8</encoding> |
117 | 122 | <docencoding>UTF-8</docencoding> |
@@ -131,9 +131,9 @@ | ||
131 | 131 | { |
132 | 132 | net.zamasoft.font.OpenTypeFont font = this.getOpenTypeFont(); |
133 | 133 | Glyph gx = font.getGlyph(this.cmap.mapCharCode('x')); |
134 | - this.xHeight = gx.getPath() == null ? DEFAULT_X_HEIGHT : (short) gx.getPath().getBounds().height; | |
134 | + this.xHeight = (gx == null || gx.getPath() == null) ? DEFAULT_X_HEIGHT : (short) gx.getPath().getBounds().height; | |
135 | 135 | Glyph gh = font.getGlyph(this.cmap.mapCharCode('H')); |
136 | - this.capHeight = gh.getPath() == null ? DEFAULT_CAP_HEIGHT : (short) gh.getPath().getBounds().height; | |
136 | + this.capHeight = (gh == null || gh.getPath() == null) ? DEFAULT_CAP_HEIGHT : (short) gh.getPath().getBounds().height; | |
137 | 137 | } |
138 | 138 | |
139 | 139 | this.stemH = 0; |
@@ -34,10 +34,16 @@ | ||
34 | 34 | |
35 | 35 | private final CmapFormat[] formats; |
36 | 36 | |
37 | + private final OpenTypeFont otf; | |
38 | + | |
39 | + private final RandomAccessFile raf; | |
40 | + | |
41 | + private final long fp; | |
42 | + | |
37 | 43 | protected CmapTable(OpenTypeFont otf, DirectoryEntry de, RandomAccessFile raf) throws IOException { |
38 | 44 | synchronized (raf) { |
39 | 45 | raf.seek(de.getOffset()); |
40 | - long fp = raf.getFilePointer(); | |
46 | + this.fp = raf.getFilePointer(); | |
41 | 47 | raf.readUnsignedShort(); // version |
42 | 48 | this.numTables = raf.readUnsignedShort(); |
43 | 49 | this.entries = new CmapIndexEntry[this.numTables]; |
@@ -48,12 +54,8 @@ | ||
48 | 54 | this.entries[i] = new CmapIndexEntry(raf); |
49 | 55 | } |
50 | 56 | |
51 | - // Get each of the tables | |
52 | - for (int i = 0; i < this.numTables; i++) { | |
53 | - raf.seek(fp + this.entries[i].getOffset()); | |
54 | - int format = raf.readUnsignedShort(); | |
55 | - this.formats[i] = new CmapFormat(format, otf.getNumGlyphs(), raf); | |
56 | - } | |
57 | + this.raf = raf; | |
58 | + this.otf = otf; | |
57 | 59 | } |
58 | 60 | } |
59 | 61 |
@@ -62,13 +64,24 @@ | ||
62 | 64 | for (int i = 0; i < this.numTables; i++) { |
63 | 65 | if (this.entries[i].getPlatformId() == platformId |
64 | 66 | && (encodingId == -1 || this.entries[i].getEncodingId() == encodingId)) { |
65 | - return this.formats[i]; | |
67 | + return this.getCmapFormat(i); | |
66 | 68 | } |
67 | 69 | } |
68 | 70 | return null; |
69 | 71 | } |
70 | 72 | |
71 | - public CmapFormat getCmapFormat(int ix) { | |
73 | + public synchronized CmapFormat getCmapFormat(int ix) { | |
74 | + if (this.formats[ix] == null) { | |
75 | + synchronized (raf) { | |
76 | + try { | |
77 | + this.raf.seek(this.fp + this.entries[ix].getOffset()); | |
78 | + int format = raf.readUnsignedShort(); | |
79 | + this.formats[ix] = new CmapFormat(format, this.otf.getNumGlyphs(), this.raf); | |
80 | + } catch (IOException e) { | |
81 | + throw new RuntimeException(e); | |
82 | + } | |
83 | + } | |
84 | + } | |
72 | 85 | return this.formats[ix]; |
73 | 86 | } |
74 | 87 |
@@ -22,163 +22,175 @@ | ||
22 | 22 | |
23 | 23 | /** |
24 | 24 | * This class is a version of the one published at |
25 | - * https://code.google.com/p/jmzreader/wiki/BufferedRandomAccessFile augmented | |
26 | - * to handle unsigned bytes. The original class is published under Apache 2.0 | |
27 | - * license. Fix is marked below | |
25 | + * https://code.google.com/p/jmzreader/wiki/BufferedRandomAccessFile augmented to handle unsigned | |
26 | + * bytes. The original class is published under Apache 2.0 license. Fix is marked below | |
28 | 27 | * |
29 | - * This is an optimized version of the RandomAccessFile class as described by | |
30 | - * Nick Zhang on JavaWorld.com. The article can be found at | |
28 | + * This is an optimized version of the RandomAccessFile class as described by Nick Zhang on | |
29 | + * JavaWorld.com. The article can be found at | |
31 | 30 | * http://www.javaworld.com/javaworld/javatips/jw-javatip26.html |
32 | 31 | * |
33 | 32 | * @author jg |
34 | 33 | */ |
35 | -public class BufferedRandomAccessFile extends RandomAccessFile { | |
36 | - /** | |
37 | - * Uses a byte instead of a char buffer for efficiency reasons. | |
38 | - */ | |
39 | - private final byte buffer[]; | |
40 | - private int bufend = 0; | |
41 | - private int bufpos = 0; | |
34 | +public class BufferedRandomAccessFile extends RandomAccessFile | |
35 | +{ | |
36 | + /** | |
37 | + * Uses a byte instead of a char buffer for efficiency reasons. | |
38 | + */ | |
39 | + private final byte buffer[]; | |
40 | + private int bufend = 0; | |
41 | + private int bufpos = 0; | |
42 | + | |
43 | + /** | |
44 | + * The position inside the actual file. | |
45 | + */ | |
46 | + private long realpos = 0; | |
47 | + | |
48 | + /** | |
49 | + * Buffer size. | |
50 | + */ | |
51 | + private final int BUFSIZE; | |
42 | 52 | |
43 | - /** | |
44 | - * The position inside the actual file. | |
45 | - */ | |
46 | - private long realpos = 0; | |
53 | + /** | |
54 | + * Creates a new instance of the BufferedRandomAccessFile. | |
55 | + * | |
56 | + * @param filename The path of the file to open. | |
57 | + * @param mode Specifies the mode to use ("r", "rw", etc.) See the BufferedLineReader | |
58 | + * documentation for more information. | |
59 | + * @param bufsize The buffer size (in bytes) to use. | |
60 | + * @throws FileNotFoundException If the mode is "r" but the given string does not denote an | |
61 | + * existing regular file, or if the mode begins with "rw" but the given string does not denote | |
62 | + * an existing, writable regular file and a new regular file of that name cannot be created, or | |
63 | + * if some other error occurs while opening or creating the file. | |
64 | + */ | |
65 | + public BufferedRandomAccessFile(String filename, String mode, int bufsize) | |
66 | + throws FileNotFoundException | |
67 | + { | |
68 | + super(filename, mode); | |
69 | + BUFSIZE = bufsize; | |
70 | + buffer = new byte[BUFSIZE]; | |
71 | + } | |
47 | 72 | |
48 | - /** | |
49 | - * Buffer size. | |
50 | - */ | |
51 | - private static final int BUFSIZE = 512; | |
73 | + /** | |
74 | + * Creates a new instance of the BufferedRandomAccessFile. | |
75 | + * | |
76 | + * @param file The file to open. | |
77 | + * @param mode Specifies the mode to use ("r", "rw", etc.) See the BufferedLineReader | |
78 | + * documentation for more information. | |
79 | + * @throws FileNotFoundException If the mode is "r" but the given file path does not denote an | |
80 | + * existing regular file, or if the mode begins with "rw" but the given file path does not denote | |
81 | + * an existing, writable regular file and a new regular file of that name cannot be created, or | |
82 | + * if some other error occurs while opening or creating the file. | |
83 | + */ | |
84 | + public BufferedRandomAccessFile(File file, String mode) | |
85 | + throws FileNotFoundException | |
86 | + { | |
87 | + super(file, mode); | |
88 | + BUFSIZE = 8192; | |
89 | + buffer = new byte[BUFSIZE]; | |
90 | + } | |
52 | 91 | |
53 | - /** | |
54 | - * Creates a new instance of the BufferedRandomAccessFile. | |
55 | - * | |
56 | - * @param filename | |
57 | - * The path of the file to open. | |
58 | - * @param mode | |
59 | - * Specifies the mode to use ("r", "rw", etc.) See the | |
60 | - * BufferedLineReader documentation for more information. | |
61 | - * @throws FileNotFoundException | |
62 | - * If the mode is "r" but the given string does not denote an | |
63 | - * existing regular file, or if the mode begins with "rw" but the | |
64 | - * given string does not denote an existing, writable regular file | |
65 | - * and a new regular file of that name cannot be created, or if some | |
66 | - * other error occurs while opening or creating the file. | |
67 | - */ | |
68 | - public BufferedRandomAccessFile(String filename, String mode) throws FileNotFoundException { | |
69 | - super(filename, mode); | |
70 | - buffer = new byte[BUFSIZE]; | |
71 | - } | |
92 | + /** | |
93 | + * {@inheritDoc} | |
94 | + */ | |
95 | + @Override | |
96 | + public final int read() throws IOException | |
97 | + { | |
98 | + if (bufpos >= bufend && fillBuffer() < 0) | |
99 | + { | |
100 | + return -1; | |
101 | + } | |
102 | + if (bufend == 0) | |
103 | + { | |
104 | + return -1; | |
105 | + } | |
106 | + // FIX to handle unsigned bytes | |
107 | + return (buffer[bufpos++] + 256) & 0xFF; | |
108 | + // End of fix | |
109 | + } | |
72 | 110 | |
73 | - /** | |
74 | - * Creates a new instance of the BufferedRandomAccessFile. | |
75 | - * | |
76 | - * @param file | |
77 | - * The file to open. | |
78 | - * @param mode | |
79 | - * Specifies the mode to use ("r", "rw", etc.) See the | |
80 | - * BufferedLineReader documentation for more information. | |
81 | - * @throws FileNotFoundException | |
82 | - * If the mode is "r" but the given file path does not denote an | |
83 | - * existing regular file, or if the mode begins with "rw" but the | |
84 | - * given file path does not denote an existing, writable regular | |
85 | - * file and a new regular file of that name cannot be created, or if | |
86 | - * some other error occurs while opening or creating the file. | |
87 | - */ | |
88 | - public BufferedRandomAccessFile(File file, String mode) throws FileNotFoundException { | |
89 | - super(file, mode); | |
90 | - buffer = new byte[BUFSIZE]; | |
91 | - } | |
111 | + /** | |
112 | + * Reads the next BUFSIZE bytes into the internal buffer. | |
113 | + * | |
114 | + * @return The total number of bytes read into the buffer, or -1 if there is no more data | |
115 | + * because the end of the file has been reached. | |
116 | + * @throws IOException If the first byte cannot be read for any reason other than end of file, | |
117 | + * or if the random access file has been closed, or if some other I/O error occurs. | |
118 | + */ | |
119 | + private int fillBuffer() throws IOException | |
120 | + { | |
121 | + int n = super.read(buffer, 0, BUFSIZE); | |
92 | 122 | |
93 | - /** | |
94 | - * {@inheritDoc} | |
95 | - */ | |
96 | - @Override | |
97 | - public final int read() throws IOException { | |
98 | - if (bufpos >= bufend && fillBuffer() < 0) { | |
99 | - return -1; | |
100 | - } | |
101 | - if (bufend == 0) { | |
102 | - return -1; | |
103 | - } | |
104 | - // FIX to handle unsigned bytes | |
105 | - return (buffer[bufpos++] + 256) & 0xFF; | |
106 | - // End of fix | |
107 | - } | |
123 | + if (n >= 0) | |
124 | + { | |
125 | + realpos += n; | |
126 | + bufend = n; | |
127 | + bufpos = 0; | |
128 | + } | |
129 | + return n; | |
130 | + } | |
108 | 131 | |
109 | - /** | |
110 | - * Reads the next BUFSIZE bytes into the internal buffer. | |
111 | - * | |
112 | - * @return The total number of bytes read into the buffer, or -1 if there is no | |
113 | - * more data because the end of the file has been reached. | |
114 | - * @throws IOException | |
115 | - * If the first byte cannot be read for any reason other than end of | |
116 | - * file, or if the random access file has been closed, or if some | |
117 | - * other I/O error occurs. | |
118 | - */ | |
119 | - private int fillBuffer() throws IOException { | |
120 | - int n = super.read(buffer, 0, BUFSIZE); | |
121 | - if (n >= 0) { | |
122 | - realpos += n; | |
123 | - bufend = n; | |
124 | - bufpos = 0; | |
125 | - } | |
126 | - return n; | |
127 | - } | |
132 | + /** | |
133 | + * Clears the local buffer. | |
134 | + * | |
135 | + * @throws IOException If an I/O error occurs. | |
136 | + */ | |
137 | + private void invalidate() throws IOException | |
138 | + { | |
139 | + bufend = 0; | |
140 | + bufpos = 0; | |
141 | + realpos = super.getFilePointer(); | |
142 | + } | |
128 | 143 | |
129 | - /** | |
130 | - * Clears the local buffer. | |
131 | - * | |
132 | - * @throws IOException | |
133 | - * If an I/O error occurs. | |
134 | - */ | |
135 | - private void invalidate() throws IOException { | |
136 | - bufend = 0; | |
137 | - bufpos = 0; | |
138 | - realpos = super.getFilePointer(); | |
139 | - } | |
144 | + /** | |
145 | + * {@inheritDoc} | |
146 | + */ | |
147 | + @Override | |
148 | + public int read(byte b[], int off, int len) throws IOException | |
149 | + { | |
150 | + int leftover = bufend - bufpos; | |
151 | + if (len <= leftover) | |
152 | + { | |
153 | + System.arraycopy(buffer, bufpos, b, off, len); | |
154 | + bufpos += len; | |
155 | + return len; | |
156 | + } | |
157 | + System.arraycopy(buffer, bufpos, b, off, leftover); | |
158 | + bufpos += leftover; | |
159 | + if (fillBuffer() > 0) | |
160 | + { | |
161 | + int bytesRead = read(b, off + leftover, len - leftover); | |
162 | + if (bytesRead > 0) | |
163 | + { | |
164 | + leftover += bytesRead; | |
165 | + } | |
166 | + } | |
167 | + return leftover > 0 ? leftover : -1; | |
168 | + } | |
140 | 169 | |
141 | - /** | |
142 | - * {@inheritDoc} | |
143 | - */ | |
144 | - @Override | |
145 | - public int read(byte b[], int off, int len) throws IOException { | |
146 | - int leftover = bufend - bufpos; | |
147 | - if (len <= leftover) { | |
148 | - System.arraycopy(buffer, bufpos, b, off, len); | |
149 | - bufpos += len; | |
150 | - return len; | |
151 | - } | |
152 | - System.arraycopy(buffer, bufpos, b, off, leftover); | |
153 | - bufpos += leftover; | |
154 | - if (fillBuffer() > 0) { | |
155 | - int bytesRead = read(b, off + leftover, len - leftover); | |
156 | - if (bytesRead > 0) { | |
157 | - leftover += bytesRead; | |
158 | - } | |
159 | - } | |
160 | - return leftover; | |
161 | - } | |
170 | + /** | |
171 | + * {@inheritDoc} | |
172 | + */ | |
173 | + @Override | |
174 | + public long getFilePointer() throws IOException | |
175 | + { | |
176 | + return realpos - bufend + bufpos; | |
177 | + } | |
162 | 178 | |
163 | - /** | |
164 | - * {@inheritDoc} | |
165 | - */ | |
166 | - @Override | |
167 | - public long getFilePointer() throws IOException { | |
168 | - return realpos - bufend + bufpos; | |
169 | - } | |
170 | - | |
171 | - /** | |
172 | - * {@inheritDoc} | |
173 | - */ | |
174 | - @Override | |
175 | - public void seek(long pos) throws IOException { | |
176 | - int n = (int) (realpos - pos); | |
177 | - if (n >= 0 && n <= bufend) { | |
178 | - bufpos = bufend - n; | |
179 | - } else { | |
180 | - super.seek(pos); | |
181 | - invalidate(); | |
182 | - } | |
183 | - } | |
184 | -} | |
179 | + /** | |
180 | + * {@inheritDoc} | |
181 | + */ | |
182 | + @Override | |
183 | + public void seek(long pos) throws IOException | |
184 | + { | |
185 | + int n = (int) (realpos - pos); | |
186 | + if (n >= 0 && n <= bufend) | |
187 | + { | |
188 | + bufpos = bufend - n; | |
189 | + } | |
190 | + else | |
191 | + { | |
192 | + super.seek(pos); | |
193 | + invalidate(); | |
194 | + } | |
195 | + } | |
196 | +} | |
\ No newline at end of file |