You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GlyphProcessingState.java 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.complexscripts.fonts;
  19. import java.nio.IntBuffer;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import org.apache.fop.complexscripts.util.CharAssociation;
  23. import org.apache.fop.complexscripts.util.GlyphContextTester;
  24. import org.apache.fop.complexscripts.util.GlyphSequence;
  25. import org.apache.fop.complexscripts.util.GlyphTester;
  26. import org.apache.fop.complexscripts.util.ScriptContextTester;
  27. // CSOFF: LineLengthCheck
  28. /**
  29. * <p>The <code>GlyphProcessingState</code> implements a common, base state object used during glyph substitution
  30. * and positioning processing.</p>
  31. *
  32. * <p>This work was originally authored by Glenn Adams (gadams@apache.org).</p>
  33. */
  34. public class GlyphProcessingState {
  35. /** governing glyph definition table */
  36. protected GlyphDefinitionTable gdef;
  37. /** governing script */
  38. protected String script;
  39. /** governing language */
  40. protected String language;
  41. /** governing feature */
  42. protected String feature;
  43. /** current input glyph sequence */
  44. protected GlyphSequence igs;
  45. /** current index in input sequence */
  46. protected int index;
  47. /** last (maximum) index of input sequence (exclusive) */
  48. protected int indexLast;
  49. /** consumed, updated after each successful subtable application */
  50. protected int consumed;
  51. /** lookup flags */
  52. protected int lookupFlags;
  53. /** class match set */
  54. protected int classMatchSet;
  55. /** script specific context tester or null */
  56. protected ScriptContextTester sct;
  57. /** glyph context tester or null */
  58. protected GlyphContextTester gct;
  59. /** ignore base glyph tester */
  60. protected GlyphTester ignoreBase;
  61. /** ignore ligature glyph tester */
  62. protected GlyphTester ignoreLigature;
  63. /** ignore mark glyph tester */
  64. protected GlyphTester ignoreMark;
  65. /** default ignore glyph tester */
  66. protected GlyphTester ignoreDefault;
  67. /** current subtable */
  68. private GlyphSubtable subtable;
  69. /**
  70. * Construct default (reset) glyph processing state.
  71. */
  72. public GlyphProcessingState() {
  73. }
  74. /**
  75. * Construct glyph processing state.
  76. * @param gs input glyph sequence
  77. * @param script script identifier
  78. * @param language language identifier
  79. * @param feature feature identifier
  80. * @param sct script context tester (or null)
  81. */
  82. protected GlyphProcessingState(GlyphSequence gs, String script, String language, String feature, ScriptContextTester sct) {
  83. this.script = script;
  84. this.language = language;
  85. this.feature = feature;
  86. this.igs = gs;
  87. this.indexLast = gs.getGlyphCount();
  88. this.sct = sct;
  89. this.gct = (sct != null) ? sct.getTester(feature) : null;
  90. this.ignoreBase = new GlyphTester() {
  91. public boolean test(int gi, int flags) {
  92. return isIgnoredBase(gi, flags);
  93. }
  94. };
  95. this.ignoreLigature = new GlyphTester() {
  96. public boolean test(int gi, int flags) {
  97. return isIgnoredLigature(gi, flags);
  98. }
  99. };
  100. this.ignoreMark = new GlyphTester() {
  101. public boolean test(int gi, int flags) {
  102. return isIgnoredMark(gi, flags);
  103. }
  104. };
  105. }
  106. /**
  107. * Construct glyph processing state using an existing state object using shallow copy
  108. * except as follows: input glyph sequence is copied deep except for its characters array.
  109. * @param s existing processing state to copy from
  110. */
  111. protected GlyphProcessingState(GlyphProcessingState s) {
  112. this (new GlyphSequence(s.igs), s.script, s.language, s.feature, s.sct);
  113. setPosition(s.index);
  114. }
  115. /**
  116. * Reset glyph processing state.
  117. * @param gs input glyph sequence
  118. * @param script script identifier
  119. * @param language language identifier
  120. * @param feature feature identifier
  121. * @param sct script context tester (or null)
  122. * @return this instance
  123. */
  124. protected GlyphProcessingState reset(GlyphSequence gs, String script, String language, String feature, ScriptContextTester sct) {
  125. this.gdef = null;
  126. this.script = script;
  127. this.language = language;
  128. this.feature = feature;
  129. this.igs = gs;
  130. this.index = 0;
  131. this.indexLast = gs.getGlyphCount();
  132. this.consumed = 0;
  133. this.lookupFlags = 0;
  134. this.classMatchSet = 0; // @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
  135. this.sct = sct;
  136. this.gct = (sct != null) ? sct.getTester(feature) : null;
  137. this.ignoreBase = new GlyphTester() {
  138. public boolean test(int gi, int flags) {
  139. return isIgnoredBase(gi, flags);
  140. }
  141. };
  142. this.ignoreLigature = new GlyphTester() {
  143. public boolean test(int gi, int flags) {
  144. return isIgnoredLigature(gi, flags);
  145. }
  146. };
  147. this.ignoreMark = new GlyphTester() {
  148. public boolean test(int gi, int flags) {
  149. return isIgnoredMark(gi, flags);
  150. }
  151. };
  152. this.ignoreDefault = null;
  153. this.subtable = null;
  154. return this;
  155. }
  156. /**
  157. * Set governing glyph definition table.
  158. * @param gdef glyph definition table (or null, to unset)
  159. */
  160. public void setGDEF(GlyphDefinitionTable gdef) {
  161. if (this.gdef == null) {
  162. this.gdef = gdef;
  163. } else if (gdef == null) {
  164. this.gdef = null;
  165. }
  166. }
  167. /**
  168. * Obtain governing glyph definition table.
  169. * @return glyph definition table (or null, to not set)
  170. */
  171. public GlyphDefinitionTable getGDEF() {
  172. return gdef;
  173. }
  174. /**
  175. * Set governing lookup flags
  176. * @param flags lookup flags (or zero, to unset)
  177. */
  178. public void setLookupFlags(int flags) {
  179. if (this.lookupFlags == 0) {
  180. this.lookupFlags = flags;
  181. } else if (flags == 0) {
  182. this.lookupFlags = 0;
  183. }
  184. }
  185. /**
  186. * Obtain governing lookup flags.
  187. * @return lookup flags (zero may indicate unset or no flags)
  188. */
  189. public int getLookupFlags() {
  190. return lookupFlags;
  191. }
  192. /**
  193. * Obtain governing class match set.
  194. * @param gi glyph index that may be used to determine which match set applies
  195. * @return class match set (zero may indicate unset or no set)
  196. */
  197. public int getClassMatchSet(int gi) {
  198. return 0;
  199. }
  200. /**
  201. * Set default ignore tester.
  202. * @param ignoreDefault glyph tester (or null, to unset)
  203. */
  204. public void setIgnoreDefault(GlyphTester ignoreDefault) {
  205. if (this.ignoreDefault == null) {
  206. this.ignoreDefault = ignoreDefault;
  207. } else if (ignoreDefault == null) {
  208. this.ignoreDefault = null;
  209. }
  210. }
  211. /**
  212. * Obtain governing default ignores tester.
  213. * @return default ignores tester
  214. */
  215. public GlyphTester getIgnoreDefault() {
  216. return ignoreDefault;
  217. }
  218. /**
  219. * Update glyph subtable specific state. Each time a
  220. * different glyph subtable is to be applied, it is used
  221. * to update this state prior to application, after which
  222. * this state is to be reset.
  223. * @param st glyph subtable to use for update
  224. */
  225. public void updateSubtableState(GlyphSubtable st) {
  226. if (this.subtable != st) {
  227. setGDEF(st.getGDEF());
  228. setLookupFlags(st.getFlags());
  229. setIgnoreDefault(getIgnoreTester(getLookupFlags()));
  230. this.subtable = st;
  231. }
  232. }
  233. /**
  234. * Obtain current position index in input glyph sequence.
  235. * @return current index
  236. */
  237. public int getPosition() {
  238. return index;
  239. }
  240. /**
  241. * Set (seek to) position index in input glyph sequence.
  242. * @param index to seek to
  243. * @throws IndexOutOfBoundsException if index is less than zero
  244. * or exceeds last valid position
  245. */
  246. public void setPosition(int index) throws IndexOutOfBoundsException {
  247. if ((index >= 0) && (index <= indexLast)) {
  248. this.index = index;
  249. } else {
  250. throw new IndexOutOfBoundsException();
  251. }
  252. }
  253. /**
  254. * Obtain last valid position index in input glyph sequence.
  255. * @return current last index
  256. */
  257. public int getLastPosition() {
  258. return indexLast;
  259. }
  260. /**
  261. * Determine if at least one glyph remains in
  262. * input sequence.
  263. * @return true if one or more glyph remains
  264. */
  265. public boolean hasNext() {
  266. return hasNext(1);
  267. }
  268. /**
  269. * Determine if at least <code>count</code> glyphs remain in
  270. * input sequence.
  271. * @param count of glyphs to test
  272. * @return true if at least <code>count</code> glyphs are available
  273. */
  274. public boolean hasNext(int count) {
  275. return (index + count) <= indexLast;
  276. }
  277. /**
  278. * Update the current position index based upon previously consumed
  279. * glyphs, i.e., add the consuemd count to the current position index.
  280. * If no glyphs were previously consumed, then forces exactly one
  281. * glyph to be consumed.
  282. * @return the new (updated) position index
  283. */
  284. public int next() {
  285. if (index < indexLast) {
  286. // force consumption of at least one input glyph
  287. if (consumed == 0) {
  288. consumed = 1;
  289. }
  290. index += consumed;
  291. consumed = 0;
  292. if (index > indexLast) {
  293. index = indexLast;
  294. }
  295. }
  296. return index;
  297. }
  298. /**
  299. * Determine if at least one backtrack (previous) glyph is present
  300. * in input sequence.
  301. * @return true if one or more glyph remains
  302. */
  303. public boolean hasPrev() {
  304. return hasPrev(1);
  305. }
  306. /**
  307. * Determine if at least <code>count</code> backtrack (previous) glyphs
  308. * are present in input sequence.
  309. * @param count of glyphs to test
  310. * @return true if at least <code>count</code> glyphs are available
  311. */
  312. public boolean hasPrev(int count) {
  313. return (index - count) >= 0;
  314. }
  315. /**
  316. * Update the current position index based upon previously consumed
  317. * glyphs, i.e., subtract the consuemd count from the current position index.
  318. * If no glyphs were previously consumed, then forces exactly one
  319. * glyph to be consumed. This method is used to traverse an input
  320. * glyph sequence in reverse order.
  321. * @return the new (updated) position index
  322. */
  323. public int prev() {
  324. if (index > 0) {
  325. // force consumption of at least one input glyph
  326. if (consumed == 0) {
  327. consumed = 1;
  328. }
  329. index -= consumed;
  330. consumed = 0;
  331. if (index < 0) {
  332. index = 0;
  333. }
  334. }
  335. return index;
  336. }
  337. /**
  338. * Record the consumption of <code>count</code> glyphs such that
  339. * this consumption never exceeds the number of glyphs in the input glyph
  340. * sequence.
  341. * @param count of glyphs to consume
  342. * @return newly adjusted consumption count
  343. * @throws IndexOutOfBoundsException if count would cause consumption
  344. * to exceed count of glyphs in input glyph sequence
  345. */
  346. public int consume(int count) throws IndexOutOfBoundsException {
  347. if ((consumed + count) <= indexLast) {
  348. consumed += count;
  349. return consumed;
  350. } else {
  351. throw new IndexOutOfBoundsException();
  352. }
  353. }
  354. /**
  355. * Determine if any consumption has occurred.
  356. * @return true if consumption count is greater than zero
  357. */
  358. public boolean didConsume() {
  359. return consumed > 0;
  360. }
  361. /**
  362. * Obtain reference to input glyph sequence, which must not be modified.
  363. * @return input glyph sequence
  364. */
  365. public GlyphSequence getInput() {
  366. return igs;
  367. }
  368. /**
  369. * Obtain glyph at specified offset from current position.
  370. * @param offset from current position
  371. * @return glyph at specified offset from current position
  372. * @throws IndexOutOfBoundsException if no glyph available at offset
  373. */
  374. public int getGlyph(int offset) throws IndexOutOfBoundsException {
  375. int i = index + offset;
  376. if ((i >= 0) && (i < indexLast)) {
  377. return igs.getGlyph(i);
  378. } else {
  379. throw new IndexOutOfBoundsException("attempting index at " + i);
  380. }
  381. }
  382. public int getUnprocessedGlyph(int offset) throws IndexOutOfBoundsException {
  383. int i = index + offset;
  384. if ((i >= 0) && (i < indexLast)) {
  385. return igs.getUnprocessedGlyph(i);
  386. } else {
  387. throw new IndexOutOfBoundsException("Attempting to process glyph at index " + i);
  388. }
  389. }
  390. /**
  391. * Obtain glyph at current position.
  392. * @return glyph at current position
  393. * @throws IndexOutOfBoundsException if no glyph available
  394. */
  395. public int getGlyph() throws IndexOutOfBoundsException {
  396. return getGlyph(0);
  397. }
  398. /**
  399. * Set (replace) glyph at specified offset from current position.
  400. * @param offset from current position
  401. * @param glyph to set at specified offset from current position
  402. * @throws IndexOutOfBoundsException if specified offset is not valid position
  403. */
  404. public void setGlyph(int offset, int glyph) throws IndexOutOfBoundsException {
  405. int i = index + offset;
  406. if ((i >= 0) && (i < indexLast)) {
  407. igs.setGlyph(i, glyph);
  408. } else {
  409. throw new IndexOutOfBoundsException("attempting index at " + i);
  410. }
  411. }
  412. /**
  413. * Obtain character association of glyph at specified offset from current position.
  414. * @param offset from current position
  415. * @return character association of glyph at current position
  416. * @throws IndexOutOfBoundsException if offset results in an invalid index into input glyph sequence
  417. */
  418. public CharAssociation getAssociation(int offset) throws IndexOutOfBoundsException {
  419. int i = index + offset;
  420. if ((i >= 0) && (i < indexLast)) {
  421. return igs.getAssociation(i);
  422. } else {
  423. throw new IndexOutOfBoundsException("attempting index at " + i);
  424. }
  425. }
  426. /**
  427. * Obtain character association of glyph at current position.
  428. * @return character association of glyph at current position
  429. * @throws IndexOutOfBoundsException if no glyph available
  430. */
  431. public CharAssociation getAssociation() throws IndexOutOfBoundsException {
  432. return getAssociation(0);
  433. }
  434. /**
  435. * Obtain <code>count</code> glyphs starting at specified offset from current position. If
  436. * <code>reverseOrder</code> is true, then glyphs are returned in reverse order starting at specified offset
  437. * and going in reverse towards beginning of input glyph sequence.
  438. * @param offset from current position
  439. * @param count number of glyphs to obtain
  440. * @param reverseOrder true if to obtain in reverse order
  441. * @param ignoreTester glyph tester to use to determine which glyphs are ignored (or null, in which case none are ignored)
  442. * @param glyphs array to use to fetch glyphs
  443. * @param counts int[2] array to receive fetched glyph counts, where counts[0] will
  444. * receive the number of glyphs obtained, and counts[1] will receive the number of glyphs
  445. * ignored
  446. * @return array of glyphs
  447. * @throws IndexOutOfBoundsException if offset or count results in an
  448. * invalid index into input glyph sequence
  449. */
  450. public int[] getGlyphs(int offset, int count, boolean reverseOrder, GlyphTester ignoreTester, int[] glyphs, int[] counts) throws IndexOutOfBoundsException {
  451. if (count < 0) {
  452. count = getGlyphsAvailable(offset, reverseOrder, ignoreTester) [ 0 ];
  453. }
  454. int start = index + offset;
  455. if (start < 0) {
  456. throw new IndexOutOfBoundsException("will attempt index at " + start);
  457. } else if (!reverseOrder && ((start + count) > indexLast)) {
  458. throw new IndexOutOfBoundsException("will attempt index at " + (start + count));
  459. } else if (reverseOrder && ((start + 1) < count)) {
  460. throw new IndexOutOfBoundsException("will attempt index at " + (start - count));
  461. }
  462. if (glyphs == null) {
  463. glyphs = new int [ count ];
  464. } else if (glyphs.length != count) {
  465. throw new IllegalArgumentException("glyphs array is non-null, but its length (" + glyphs.length + "), is not equal to count (" + count + ")");
  466. }
  467. if (!reverseOrder) {
  468. return getGlyphsForward(start, count, ignoreTester, glyphs, counts);
  469. } else {
  470. return getGlyphsReverse(start, count, ignoreTester, glyphs, counts);
  471. }
  472. }
  473. private int[] getGlyphsForward(int start, int count, GlyphTester ignoreTester, int[] glyphs, int[] counts) throws IndexOutOfBoundsException {
  474. int counted = 0;
  475. int ignored = 0;
  476. for (int i = start, n = indexLast; (i < n) && (counted < count); i++) {
  477. int gi = getGlyph(i - index);
  478. if (gi == 65535) {
  479. ignored++;
  480. } else {
  481. if ((ignoreTester == null) || !ignoreTester.test(gi, getLookupFlags())) {
  482. glyphs [ counted++ ] = gi;
  483. } else {
  484. ignored++;
  485. }
  486. }
  487. }
  488. if ((counts != null) && (counts.length > 1)) {
  489. counts[0] = counted;
  490. counts[1] = ignored;
  491. }
  492. return glyphs;
  493. }
  494. private int[] getGlyphsReverse(int start, int count, GlyphTester ignoreTester, int[] glyphs, int[] counts) throws IndexOutOfBoundsException {
  495. int counted = 0;
  496. int ignored = 0;
  497. for (int i = start; (i >= 0) && (counted < count); i--) {
  498. int gi = getGlyph(i - index);
  499. if (gi == 65535) {
  500. ignored++;
  501. } else {
  502. if ((ignoreTester == null) || !ignoreTester.test(gi, getLookupFlags())) {
  503. glyphs [ counted++ ] = gi;
  504. } else {
  505. ignored++;
  506. }
  507. }
  508. }
  509. if ((counts != null) && (counts.length > 1)) {
  510. counts[0] = counted;
  511. counts[1] = ignored;
  512. }
  513. return glyphs;
  514. }
  515. /**
  516. * Obtain <code>count</code> glyphs starting at specified offset from current position. If
  517. * offset is negative, then glyphs are returned in reverse order starting at specified offset
  518. * and going in reverse towards beginning of input glyph sequence.
  519. * @param offset from current position
  520. * @param count number of glyphs to obtain
  521. * @param glyphs array to use to fetch glyphs
  522. * @param counts int[2] array to receive fetched glyph counts, where counts[0] will
  523. * receive the number of glyphs obtained, and counts[1] will receive the number of glyphs
  524. * ignored
  525. * @return array of glyphs
  526. * @throws IndexOutOfBoundsException if offset or count results in an
  527. * invalid index into input glyph sequence
  528. */
  529. public int[] getGlyphs(int offset, int count, int[] glyphs, int[] counts) throws IndexOutOfBoundsException {
  530. return getGlyphs(offset, count, offset < 0, ignoreDefault, glyphs, counts);
  531. }
  532. /**
  533. * Obtain all glyphs starting from current position to end of input glyph sequence.
  534. * @return array of available glyphs
  535. * @throws IndexOutOfBoundsException if no glyph available
  536. */
  537. public int[] getGlyphs() throws IndexOutOfBoundsException {
  538. return getGlyphs(0, indexLast - index, false, null, null, null);
  539. }
  540. /**
  541. * Obtain <code>count</code> ignored glyphs starting at specified offset from current position. If
  542. * <code>reverseOrder</code> is true, then glyphs are returned in reverse order starting at specified offset
  543. * and going in reverse towards beginning of input glyph sequence.
  544. * @param offset from current position
  545. * @param count number of glyphs to obtain
  546. * @param reverseOrder true if to obtain in reverse order
  547. * @param ignoreTester glyph tester to use to determine which glyphs are ignored (or null, in which case none are ignored)
  548. * @param glyphs array to use to fetch glyphs
  549. * @param counts int[2] array to receive fetched glyph counts, where counts[0] will
  550. * receive the number of glyphs obtained, and counts[1] will receive the number of glyphs
  551. * ignored
  552. * @return array of glyphs
  553. * @throws IndexOutOfBoundsException if offset or count results in an
  554. * invalid index into input glyph sequence
  555. */
  556. public int[] getIgnoredGlyphs(int offset, int count, boolean reverseOrder, GlyphTester ignoreTester, int[] glyphs, int[] counts) throws IndexOutOfBoundsException {
  557. return getGlyphs(offset, count, reverseOrder, new NotGlyphTester(ignoreTester), glyphs, counts);
  558. }
  559. /**
  560. * Obtain <code>count</code> ignored glyphs starting at specified offset from current position. If <code>offset</code> is
  561. * negative, then fetch in reverse order.
  562. * @param offset from current position
  563. * @param count number of glyphs to obtain
  564. * @return array of glyphs
  565. * @throws IndexOutOfBoundsException if offset or count results in an
  566. * invalid index into input glyph sequence
  567. */
  568. public int[] getIgnoredGlyphs(int offset, int count) throws IndexOutOfBoundsException {
  569. return getIgnoredGlyphs(offset, count, offset < 0, ignoreDefault, null, null);
  570. }
  571. /**
  572. * Determine if glyph at specified offset from current position is ignored. If <code>offset</code> is
  573. * negative, then test in reverse order.
  574. * @param offset from current position
  575. * @param ignoreTester glyph tester to use to determine which glyphs are ignored (or null, in which case none are ignored)
  576. * @return true if glyph is ignored
  577. * @throws IndexOutOfBoundsException if offset results in an
  578. * invalid index into input glyph sequence
  579. */
  580. public boolean isIgnoredGlyph(int offset, GlyphTester ignoreTester) throws IndexOutOfBoundsException {
  581. return (ignoreTester != null) && ignoreTester.test(getGlyph(offset), getLookupFlags());
  582. }
  583. /**
  584. * Determine if glyph at specified offset from current position is ignored. If <code>offset</code> is
  585. * negative, then test in reverse order.
  586. * @param offset from current position
  587. * @return true if glyph is ignored
  588. * @throws IndexOutOfBoundsException if offset results in an
  589. * invalid index into input glyph sequence
  590. */
  591. public boolean isIgnoredGlyph(int offset) throws IndexOutOfBoundsException {
  592. return isIgnoredGlyph(offset, ignoreDefault);
  593. }
  594. /**
  595. * Determine if glyph at current position is ignored.
  596. * @return true if glyph is ignored
  597. * @throws IndexOutOfBoundsException if offset results in an
  598. * invalid index into input glyph sequence
  599. */
  600. public boolean isIgnoredGlyph() throws IndexOutOfBoundsException {
  601. return isIgnoredGlyph(getPosition());
  602. }
  603. /**
  604. * Determine number of glyphs available starting at specified offset from current position. If
  605. * <code>reverseOrder</code> is true, then search backwards in input glyph sequence.
  606. * @param offset from current position
  607. * @param reverseOrder true if to obtain in reverse order
  608. * @param ignoreTester glyph tester to use to determine which glyphs to count (or null, in which case none are ignored)
  609. * @return an int[2] array where counts[0] is the number of glyphs available, and counts[1] is the number of glyphs ignored
  610. * @throws IndexOutOfBoundsException if offset or count results in an
  611. * invalid index into input glyph sequence
  612. */
  613. public int[] getGlyphsAvailable(int offset, boolean reverseOrder, GlyphTester ignoreTester) throws IndexOutOfBoundsException {
  614. int start = index + offset;
  615. if ((start < 0) || (start > indexLast)) {
  616. return new int[] { 0, 0 };
  617. } else if (!reverseOrder) {
  618. return getGlyphsAvailableForward(start, ignoreTester);
  619. } else {
  620. return getGlyphsAvailableReverse(start, ignoreTester);
  621. }
  622. }
  623. private int[] getGlyphsAvailableForward(int start, GlyphTester ignoreTester) throws IndexOutOfBoundsException {
  624. int counted = 0;
  625. int ignored = 0;
  626. if (ignoreTester == null) {
  627. counted = indexLast - start;
  628. } else {
  629. for (int i = start, n = indexLast; i < n; i++) {
  630. int gi = getGlyph(i - index);
  631. if (gi == 65535) {
  632. ignored++;
  633. } else {
  634. if (ignoreTester.test(gi, getLookupFlags())) {
  635. ignored++;
  636. } else {
  637. counted++;
  638. }
  639. }
  640. }
  641. }
  642. return new int[] { counted, ignored };
  643. }
  644. private int[] getGlyphsAvailableReverse(int start, GlyphTester ignoreTester) throws IndexOutOfBoundsException {
  645. int counted = 0;
  646. int ignored = 0;
  647. if (ignoreTester == null) {
  648. counted = start + 1;
  649. } else {
  650. for (int i = start; i >= 0; i--) {
  651. int gi = getGlyph(i - index);
  652. if (gi == 65535) {
  653. ignored++;
  654. } else {
  655. if (ignoreTester.test(gi, getLookupFlags())) {
  656. ignored++;
  657. } else {
  658. counted++;
  659. }
  660. }
  661. }
  662. }
  663. return new int[] { counted, ignored };
  664. }
  665. /**
  666. * Determine number of glyphs available starting at specified offset from current position. If
  667. * <code>reverseOrder</code> is true, then search backwards in input glyph sequence. Uses the
  668. * default ignores tester.
  669. * @param offset from current position
  670. * @param reverseOrder true if to obtain in reverse order
  671. * @return an int[2] array where counts[0] is the number of glyphs available, and counts[1] is the number of glyphs ignored
  672. * @throws IndexOutOfBoundsException if offset or count results in an
  673. * invalid index into input glyph sequence
  674. */
  675. public int[] getGlyphsAvailable(int offset, boolean reverseOrder) throws IndexOutOfBoundsException {
  676. return getGlyphsAvailable(offset, reverseOrder, ignoreDefault);
  677. }
  678. /**
  679. * Determine number of glyphs available starting at specified offset from current position. If
  680. * offset is negative, then search backwards in input glyph sequence. Uses the
  681. * default ignores tester.
  682. * @param offset from current position
  683. * @return an int[2] array where counts[0] is the number of glyphs available, and counts[1] is the number of glyphs ignored
  684. * @throws IndexOutOfBoundsException if offset or count results in an
  685. * invalid index into input glyph sequence
  686. */
  687. public int[] getGlyphsAvailable(int offset) throws IndexOutOfBoundsException {
  688. return getGlyphsAvailable(offset, offset < 0);
  689. }
  690. /**
  691. * Obtain <code>count</code> character associations of glyphs starting at specified offset from current position. If
  692. * <code>reverseOrder</code> is true, then associations are returned in reverse order starting at specified offset
  693. * and going in reverse towards beginning of input glyph sequence.
  694. * @param offset from current position
  695. * @param count number of associations to obtain
  696. * @param reverseOrder true if to obtain in reverse order
  697. * @param ignoreTester glyph tester to use to determine which glyphs are ignored (or null, in which case none are ignored)
  698. * @param associations array to use to fetch associations
  699. * @param counts int[2] array to receive fetched association counts, where counts[0] will
  700. * receive the number of associations obtained, and counts[1] will receive the number of glyphs whose
  701. * associations were ignored
  702. * @return array of associations
  703. * @throws IndexOutOfBoundsException if offset or count results in an
  704. * invalid index into input glyph sequence
  705. */
  706. public CharAssociation[] getAssociations(int offset, int count, boolean reverseOrder, GlyphTester ignoreTester, CharAssociation[] associations, int[] counts)
  707. throws IndexOutOfBoundsException {
  708. if (count < 0) {
  709. count = getGlyphsAvailable(offset, reverseOrder, ignoreTester) [ 0 ];
  710. }
  711. int start = index + offset;
  712. if (start < 0) {
  713. throw new IndexOutOfBoundsException("will attempt index at " + start);
  714. } else if (!reverseOrder && ((start + count) > indexLast)) {
  715. throw new IndexOutOfBoundsException("will attempt index at " + (start + count));
  716. } else if (reverseOrder && ((start + 1) < count)) {
  717. throw new IndexOutOfBoundsException("will attempt index at " + (start - count));
  718. }
  719. if (associations == null) {
  720. associations = new CharAssociation [ count ];
  721. } else if (associations.length != count) {
  722. throw new IllegalArgumentException("associations array is non-null, but its length (" + associations.length + "), is not equal to count (" + count + ")");
  723. }
  724. if (!reverseOrder) {
  725. return getAssociationsForward(start, count, ignoreTester, associations, counts);
  726. } else {
  727. return getAssociationsReverse(start, count, ignoreTester, associations, counts);
  728. }
  729. }
  730. private CharAssociation[] getAssociationsForward(int start, int count, GlyphTester ignoreTester, CharAssociation[] associations, int[] counts)
  731. throws IndexOutOfBoundsException {
  732. int counted = 0;
  733. int ignored = 0;
  734. for (int i = start, n = indexLast, k = 0; i < n; i++) {
  735. int gi = getGlyph(i - index);
  736. if (gi == 65535) {
  737. ignored++;
  738. } else {
  739. if ((ignoreTester == null) || !ignoreTester.test(gi, getLookupFlags())) {
  740. if (k < count) {
  741. associations [ k++ ] = getAssociation(i - index);
  742. counted++;
  743. } else {
  744. break;
  745. }
  746. } else {
  747. ignored++;
  748. }
  749. }
  750. }
  751. if ((counts != null) && (counts.length > 1)) {
  752. counts[0] = counted;
  753. counts[1] = ignored;
  754. }
  755. return associations;
  756. }
  757. private CharAssociation[] getAssociationsReverse(int start, int count, GlyphTester ignoreTester, CharAssociation[] associations, int[] counts)
  758. throws IndexOutOfBoundsException {
  759. int counted = 0;
  760. int ignored = 0;
  761. for (int i = start, k = 0; i >= 0; i--) {
  762. int gi = getGlyph(i - index);
  763. if (gi == 65535) {
  764. ignored++;
  765. } else {
  766. if ((ignoreTester == null) || !ignoreTester.test(gi, getLookupFlags())) {
  767. if (k < count) {
  768. associations [ k++ ] = getAssociation(i - index);
  769. counted++;
  770. } else {
  771. break;
  772. }
  773. } else {
  774. ignored++;
  775. }
  776. }
  777. }
  778. if ((counts != null) && (counts.length > 1)) {
  779. counts[0] = counted;
  780. counts[1] = ignored;
  781. }
  782. return associations;
  783. }
  784. /**
  785. * Obtain <code>count</code> character associations of glyphs starting at specified offset from current position. If
  786. * offset is negative, then search backwards in input glyph sequence. Uses the
  787. * default ignores tester.
  788. * @param offset from current position
  789. * @param count number of associations to obtain
  790. * @return array of associations
  791. * @throws IndexOutOfBoundsException if offset or count results in an
  792. * invalid index into input glyph sequence
  793. */
  794. public CharAssociation[] getAssociations(int offset, int count) throws IndexOutOfBoundsException {
  795. return getAssociations(offset, count, offset < 0, ignoreDefault, null, null);
  796. }
  797. /**
  798. * Obtain <code>count</code> character associations of ignored glyphs starting at specified offset from current position. If
  799. * <code>reverseOrder</code> is true, then glyphs are returned in reverse order starting at specified offset
  800. * and going in reverse towards beginning of input glyph sequence.
  801. * @param offset from current position
  802. * @param count number of character associations to obtain
  803. * @param reverseOrder true if to obtain in reverse order
  804. * @param ignoreTester glyph tester to use to determine which glyphs are ignored (or null, in which case none are ignored)
  805. * @param associations array to use to fetch associations
  806. * @param counts int[2] array to receive fetched association counts, where counts[0] will
  807. * receive the number of associations obtained, and counts[1] will receive the number of glyphs whose
  808. * associations were ignored
  809. * @return array of associations
  810. * @throws IndexOutOfBoundsException if offset or count results in an
  811. * invalid index into input glyph sequence
  812. */
  813. public CharAssociation[] getIgnoredAssociations(int offset, int count, boolean reverseOrder, GlyphTester ignoreTester, CharAssociation[] associations, int[] counts)
  814. throws IndexOutOfBoundsException {
  815. return getAssociations(offset, count, reverseOrder, new NotGlyphTester(ignoreTester), associations, counts);
  816. }
  817. /**
  818. * Obtain <code>count</code> character associations of ignored glyphs starting at specified offset from current position. If
  819. * offset is negative, then search backwards in input glyph sequence. Uses the
  820. * default ignores tester.
  821. * @param offset from current position
  822. * @param count number of character associations to obtain
  823. * @return array of associations
  824. * @throws IndexOutOfBoundsException if offset or count results in an
  825. * invalid index into input glyph sequence
  826. */
  827. public CharAssociation[] getIgnoredAssociations(int offset, int count) throws IndexOutOfBoundsException {
  828. return getIgnoredAssociations(offset, count, offset < 0, ignoreDefault, null, null);
  829. }
  830. /**
  831. * Replace subsequence of input glyph sequence starting at specified offset from current position and of
  832. * length <code>count</code> glyphs with a subsequence of the sequence <code>gs</code> starting from the specified
  833. * offset <code>gsOffset</code> of length <code>gsCount</code> glyphs.
  834. * @param offset from current position
  835. * @param count number of glyphs to replace, which, if negative means all glyphs from offset to end of input sequence
  836. * @param gs glyph sequence from which to obtain replacement glyphs
  837. * @param gsOffset offset of first glyph in replacement sequence
  838. * @param gsCount count of glyphs in replacement sequence starting at <code>gsOffset</code>
  839. * @return true if replacement occurred, or false if replacement would result in no change to input glyph sequence
  840. * @throws IndexOutOfBoundsException if offset or count results in an
  841. * invalid index into input glyph sequence
  842. */
  843. public boolean replaceInput(int offset, int count, GlyphSequence gs, int gsOffset, int gsCount) throws IndexOutOfBoundsException {
  844. int nig = (igs != null) ? igs.getGlyphCount() : 0;
  845. int position = getPosition() + offset;
  846. if (position < 0) {
  847. position = 0;
  848. } else if (position > nig) {
  849. position = nig;
  850. }
  851. if ((count < 0) || ((position + count) > nig)) {
  852. count = nig - position;
  853. }
  854. int nrg = (gs != null) ? gs.getGlyphCount() : 0;
  855. if (gsOffset < 0) {
  856. gsOffset = 0;
  857. } else if (gsOffset > nrg) {
  858. gsOffset = nrg;
  859. }
  860. if ((gsCount < 0) || ((gsOffset + gsCount) > nrg)) {
  861. gsCount = nrg - gsOffset;
  862. }
  863. int ng = nig + gsCount - count;
  864. IntBuffer gb = IntBuffer.allocate(ng);
  865. List al = new ArrayList(ng);
  866. for (int i = 0, n = position; i < n; i++) {
  867. gb.put(igs.getGlyph(i));
  868. al.add(igs.getAssociation(i));
  869. }
  870. for (int i = gsOffset, n = gsOffset + gsCount; i < n; i++) {
  871. gb.put(gs.getGlyph(i));
  872. al.add(gs.getAssociation(i));
  873. }
  874. for (int i = position + count, n = nig; i < n; i++) {
  875. gb.put(igs.getGlyph(i));
  876. al.add(igs.getAssociation(i));
  877. }
  878. gb.flip();
  879. assert igs != null;
  880. if (igs.compareGlyphs(gb) != 0) {
  881. this.igs = new GlyphSequence(igs.getCharacters(), gb, al);
  882. this.indexLast = gb.limit();
  883. return true;
  884. } else {
  885. return false;
  886. }
  887. }
  888. /**
  889. * Replace subsequence of input glyph sequence starting at specified offset from current position and of
  890. * length <code>count</code> glyphs with all glyphs in the replacement sequence <code>gs</code>.
  891. * @param offset from current position
  892. * @param count number of glyphs to replace, which, if negative means all glyphs from offset to end of input sequence
  893. * @param gs glyph sequence from which to obtain replacement glyphs
  894. * @return true if replacement occurred, or false if replacement would result in no change to input glyph sequence
  895. * @throws IndexOutOfBoundsException if offset or count results in an
  896. * invalid index into input glyph sequence
  897. */
  898. public boolean replaceInput(int offset, int count, GlyphSequence gs) throws IndexOutOfBoundsException {
  899. return replaceInput(offset, count, gs, 0, gs.getGlyphCount());
  900. }
  901. /**
  902. * Erase glyphs in input glyph sequence starting at specified offset from current position, where each glyph
  903. * in the specified <code>glyphs</code> array is matched, one at a time, and when a (forward searching) match is found
  904. * in the input glyph sequence, the matching glyph is replaced with the glyph index 65535.
  905. * @param offset from current position
  906. * @param glyphs array of glyphs to erase
  907. * @return the number of glyphs erased, which may be less than the number of specified glyphs
  908. * @throws IndexOutOfBoundsException if offset or count results in an
  909. * invalid index into input glyph sequence
  910. */
  911. public int erase(int offset, int[] glyphs) throws IndexOutOfBoundsException {
  912. int start = index + offset;
  913. if ((start < 0) || (start > indexLast)) {
  914. throw new IndexOutOfBoundsException("will attempt index at " + start);
  915. } else {
  916. int erased = 0;
  917. for (int i = start - index, n = indexLast - start; i < n; i++) {
  918. int gi = getGlyph(i);
  919. if (gi == glyphs [ erased ]) {
  920. setGlyph(i, 65535);
  921. erased++;
  922. }
  923. }
  924. return erased;
  925. }
  926. }
  927. /**
  928. * Determine if is possible that the current input sequence satisfies a script specific
  929. * context testing predicate. If no predicate applies, then application is always possible.
  930. * @return true if no script specific context tester applies or if a specified tester returns
  931. * true for the current input sequence context
  932. */
  933. public boolean maybeApplicable() {
  934. if (gct == null) {
  935. return true;
  936. } else {
  937. return gct.test(script, language, feature, igs, index, getLookupFlags());
  938. }
  939. }
  940. /**
  941. * Apply default application semantices; namely, consume one glyph.
  942. */
  943. public void applyDefault() {
  944. consumed += 1;
  945. }
  946. /**
  947. * Determine if specified glyph is a base glyph according to the governing
  948. * glyph definition table.
  949. * @param gi glyph index to test
  950. * @return true if glyph definition table records glyph as a base glyph; otherwise, false
  951. */
  952. public boolean isBase(int gi) {
  953. if (gdef != null) {
  954. return gdef.isGlyphClass(gi, GlyphDefinitionTable.GLYPH_CLASS_BASE);
  955. } else {
  956. return false;
  957. }
  958. }
  959. /**
  960. * Determine if specified glyph is an ignored base glyph according to the governing
  961. * glyph definition table.
  962. * @param gi glyph index to test
  963. * @param flags that apply to lookup in scope
  964. * @return true if glyph definition table records glyph as a base glyph; otherwise, false
  965. */
  966. public boolean isIgnoredBase(int gi, int flags) {
  967. return ((flags & GlyphSubtable.LF_IGNORE_BASE) != 0) && isBase(gi);
  968. }
  969. /**
  970. * Determine if specified glyph is an ligature glyph according to the governing
  971. * glyph definition table.
  972. * @param gi glyph index to test
  973. * @return true if glyph definition table records glyph as a ligature glyph; otherwise, false
  974. */
  975. public boolean isLigature(int gi) {
  976. if (gdef != null) {
  977. return gdef.isGlyphClass(gi, GlyphDefinitionTable.GLYPH_CLASS_LIGATURE);
  978. } else {
  979. return false;
  980. }
  981. }
  982. /**
  983. * Determine if specified glyph is an ignored ligature glyph according to the governing
  984. * glyph definition table.
  985. * @param gi glyph index to test
  986. * @param flags that apply to lookup in scope
  987. * @return true if glyph definition table records glyph as a ligature glyph; otherwise, false
  988. */
  989. public boolean isIgnoredLigature(int gi, int flags) {
  990. return ((flags & GlyphSubtable.LF_IGNORE_LIGATURE) != 0) && isLigature(gi);
  991. }
  992. /**
  993. * Determine if specified glyph is a mark glyph according to the governing
  994. * glyph definition table.
  995. * @param gi glyph index to test
  996. * @return true if glyph definition table records glyph as a mark glyph; otherwise, false
  997. */
  998. public boolean isMark(int gi) {
  999. if (gdef != null) {
  1000. return gdef.isGlyphClass(gi, GlyphDefinitionTable.GLYPH_CLASS_MARK);
  1001. } else {
  1002. return false;
  1003. }
  1004. }
  1005. /**
  1006. * Determine if specified glyph is an ignored ligature glyph according to the governing
  1007. * glyph definition table.
  1008. * @param gi glyph index to test
  1009. * @param flags that apply to lookup in scope
  1010. * @return true if glyph definition table records glyph as a ligature glyph; otherwise, false
  1011. */
  1012. public boolean isIgnoredMark(int gi, int flags) {
  1013. if ((flags & GlyphSubtable.LF_IGNORE_MARK) != 0) {
  1014. return isMark(gi);
  1015. } else if ((flags & GlyphSubtable.LF_MARK_ATTACHMENT_TYPE) != 0) {
  1016. int lac = (flags & GlyphSubtable.LF_MARK_ATTACHMENT_TYPE) >> 8;
  1017. int gac = gdef.getMarkAttachClass(gi);
  1018. return (gac != lac);
  1019. } else {
  1020. return false;
  1021. }
  1022. }
  1023. /**
  1024. * Obtain an ignored glyph tester that corresponds to the specified lookup flags.
  1025. * @param flags lookup flags
  1026. * @return a glyph tester
  1027. */
  1028. public GlyphTester getIgnoreTester(int flags) {
  1029. if ((flags & GlyphSubtable.LF_IGNORE_BASE) != 0) {
  1030. if ((flags & (GlyphSubtable.LF_IGNORE_LIGATURE | GlyphSubtable.LF_IGNORE_MARK)) == 0) {
  1031. return ignoreBase;
  1032. } else {
  1033. return getCombinedIgnoreTester(flags);
  1034. }
  1035. }
  1036. if ((flags & GlyphSubtable.LF_IGNORE_LIGATURE) != 0) {
  1037. if ((flags & (GlyphSubtable.LF_IGNORE_BASE | GlyphSubtable.LF_IGNORE_MARK)) == 0) {
  1038. return ignoreLigature;
  1039. } else {
  1040. return getCombinedIgnoreTester(flags);
  1041. }
  1042. }
  1043. if ((flags & GlyphSubtable.LF_IGNORE_MARK) != 0) {
  1044. if ((flags & (GlyphSubtable.LF_IGNORE_BASE | GlyphSubtable.LF_IGNORE_LIGATURE)) == 0) {
  1045. return ignoreMark;
  1046. } else {
  1047. return getCombinedIgnoreTester(flags);
  1048. }
  1049. }
  1050. return null;
  1051. }
  1052. /**
  1053. * Obtain an ignored glyph tester that corresponds to the specified multiple (combined) lookup flags.
  1054. * @param flags lookup flags
  1055. * @return a glyph tester
  1056. */
  1057. public GlyphTester getCombinedIgnoreTester(int flags) {
  1058. GlyphTester[] gta = new GlyphTester [ 3 ];
  1059. int ngt = 0;
  1060. if ((flags & GlyphSubtable.LF_IGNORE_BASE) != 0) {
  1061. gta [ ngt++ ] = ignoreBase;
  1062. }
  1063. if ((flags & GlyphSubtable.LF_IGNORE_LIGATURE) != 0) {
  1064. gta [ ngt++ ] = ignoreLigature;
  1065. }
  1066. if ((flags & GlyphSubtable.LF_IGNORE_MARK) != 0) {
  1067. gta [ ngt++ ] = ignoreMark;
  1068. }
  1069. return getCombinedOrTester(gta, ngt);
  1070. }
  1071. /**
  1072. * Obtain an combined OR glyph tester.
  1073. * @param gta an array of glyph testers
  1074. * @param ngt number of glyph testers present in specified array
  1075. * @return a combined OR glyph tester
  1076. */
  1077. public GlyphTester getCombinedOrTester(GlyphTester[] gta, int ngt) {
  1078. if (ngt > 0) {
  1079. return new CombinedOrGlyphTester(gta, ngt);
  1080. } else {
  1081. return null;
  1082. }
  1083. }
  1084. /**
  1085. * Obtain an combined AND glyph tester.
  1086. * @param gta an array of glyph testers
  1087. * @param ngt number of glyph testers present in specified array
  1088. * @return a combined AND glyph tester
  1089. */
  1090. public GlyphTester getCombinedAndTester(GlyphTester[] gta, int ngt) {
  1091. if (ngt > 0) {
  1092. return new CombinedAndGlyphTester(gta, ngt);
  1093. } else {
  1094. return null;
  1095. }
  1096. }
  1097. /** combined OR glyph tester */
  1098. private static class CombinedOrGlyphTester implements GlyphTester {
  1099. private GlyphTester[] gta;
  1100. private int ngt;
  1101. CombinedOrGlyphTester(GlyphTester[] gta, int ngt) {
  1102. this.gta = gta;
  1103. this.ngt = ngt;
  1104. }
  1105. /** {@inheritDoc} */
  1106. public boolean test(int gi, int flags) {
  1107. for (int i = 0, n = ngt; i < n; i++) {
  1108. GlyphTester gt = gta [ i ];
  1109. if (gt != null) {
  1110. if (gt.test(gi, flags)) {
  1111. return true;
  1112. }
  1113. }
  1114. }
  1115. return false;
  1116. }
  1117. }
  1118. /** combined AND glyph tester */
  1119. private static class CombinedAndGlyphTester implements GlyphTester {
  1120. private GlyphTester[] gta;
  1121. private int ngt;
  1122. CombinedAndGlyphTester(GlyphTester[] gta, int ngt) {
  1123. this.gta = gta;
  1124. this.ngt = ngt;
  1125. }
  1126. /** {@inheritDoc} */
  1127. public boolean test(int gi, int flags) {
  1128. for (int i = 0, n = ngt; i < n; i++) {
  1129. GlyphTester gt = gta [ i ];
  1130. if (gt != null) {
  1131. if (!gt.test(gi, flags)) {
  1132. return false;
  1133. }
  1134. }
  1135. }
  1136. return true;
  1137. }
  1138. }
  1139. /** NOT glyph tester */
  1140. private static class NotGlyphTester implements GlyphTester {
  1141. private GlyphTester gt;
  1142. NotGlyphTester(GlyphTester gt) {
  1143. this.gt = gt;
  1144. }
  1145. /** {@inheritDoc} */
  1146. public boolean test(int gi, int flags) {
  1147. if (gt != null) {
  1148. if (gt.test(gi, flags)) {
  1149. return false;
  1150. }
  1151. }
  1152. return true;
  1153. }
  1154. }
  1155. }