12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797 |
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /* $Id$ */
-
- package org.apache.fop.complexscripts.fonts;
-
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
-
- import org.apache.fop.complexscripts.scripts.ScriptProcessor;
- import org.apache.fop.fonts.truetype.FontFileReader;
- import org.apache.fop.fonts.truetype.OFDirTabEntry;
- import org.apache.fop.fonts.truetype.OFTableName;
- import org.apache.fop.fonts.truetype.OpenFont;
-
- // CSOFF: LineLengthCheck
-
- /**
- * <p>OpenType Font (OTF) advanced typographic table reader. Used by @{Link org.apache.fop.fonts.truetype.TTFFile}
- * to read advanced typographic tables (GDEF, GSUB, GPOS).</p>
- *
- * <p>This work was originally authored by Glenn Adams (gadams@apache.org).</p>
- */
- public final class OTFAdvancedTypographicTableReader {
-
- // logging state
- private static Log log = LogFactory.getLog(OTFAdvancedTypographicTableReader.class);
- // instance state
- private OpenFont otf; // parent font file reader
- private FontFileReader in; // input reader
- private GlyphDefinitionTable gdef; // glyph definition table
- private GlyphSubstitutionTable gsub; // glyph substitution table
- private GlyphPositioningTable gpos; // glyph positioning table
- // transient parsing state
- private transient Map<String, Object> seScripts; // script-tag => Object[3] : { default-language-tag, List(language-tag), seLanguages }
- private transient Map<String, Object> seLanguages; // language-tag => Object[2] : { "f<required-feature-index>", List("f<feature-index>")
- private transient Map<String, Object> seFeatures; // "f<feature-index>" => Object[2] : { feature-tag, List("lu<lookup-index>") }
- private transient GlyphMappingTable seMapping; // subtable entry mappings
- private transient List seEntries; // subtable entry entries
- private transient List seSubtables; // subtable entry subtables
- private Map<String, ScriptProcessor> processors = new HashMap<String, ScriptProcessor>();
-
- /**
- * Construct an <code>OTFAdvancedTypographicTableReader</code> instance.
- * @param ttf parent font file reader (must be non-null)
- * @param in font file reader (must be non-null)
- */
- public OTFAdvancedTypographicTableReader(OpenFont otf, FontFileReader in) {
- assert otf != null;
- assert in != null;
- this.otf = otf;
- this.in = in;
- }
-
- /**
- * Read all advanced typographic tables.
- * @throws AdvancedTypographicTableFormatException if ATT table has invalid format
- */
- public void readAll() throws AdvancedTypographicTableFormatException {
- try {
- readGDEF();
- readGSUB();
- readGPOS();
- } catch (AdvancedTypographicTableFormatException e) {
- resetATStateAll();
- throw e;
- } catch (IOException e) {
- resetATStateAll();
- throw new AdvancedTypographicTableFormatException(e.getMessage(), e);
- } finally {
- resetATState();
- }
- }
-
- /**
- * Determine if advanced (typographic) table is present.
- * @return true if advanced (typographic) table is present
- */
- public boolean hasAdvancedTable() {
- return (gdef != null) || (gsub != null) || (gpos != null);
- }
-
- /**
- * Returns the GDEF table or null if none present.
- * @return the GDEF table
- */
- public GlyphDefinitionTable getGDEF() {
- return gdef;
- }
-
- /**
- * Returns the GSUB table or null if none present.
- * @return the GSUB table
- */
- public GlyphSubstitutionTable getGSUB() {
- return gsub;
- }
-
- /**
- * Returns the GPOS table or null if none present.
- * @return the GPOS table
- */
- public GlyphPositioningTable getGPOS() {
- return gpos;
- }
-
- private void readLangSysTable(OFTableName tableTag, long langSysTable, String langSysTag)
- throws IOException {
- in.seekSet(langSysTable);
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lang sys table: " + langSysTag);
- }
- // read lookup order (reorder) table offset
- int lo = in.readTTFUShort();
- // read required feature index
- int rf = in.readTTFUShort();
- String rfi;
- if (rf != 65535) {
- rfi = "f" + rf;
- } else {
- rfi = null;
- }
- // read (non-required) feature count
- int nf = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lang sys table reorder table: " + lo);
- log.debug(tableTag + " lang sys table required feature index: " + rf);
- log.debug(tableTag + " lang sys table non-required feature count: " + nf);
- }
- // read (non-required) feature indices
- List fl = new java.util.ArrayList();
- for (int i = 0; i < nf; i++) {
- int fi = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lang sys table non-required feature index: " + fi);
- }
- fl.add("f" + fi);
- }
- if (seLanguages == null) {
- seLanguages = new java.util.LinkedHashMap();
- }
- seLanguages.put(langSysTag, new Object[] { rfi, fl });
- }
-
- private static String defaultTag = "dflt";
-
- private void readScriptTable(OFTableName tableTag, long scriptTable, String scriptTag) throws IOException {
- in.seekSet(scriptTable);
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " script table: " + scriptTag);
- }
- // read default language system table offset
- int dl = in.readTTFUShort();
- String dt = defaultTag;
- if (dl > 0) {
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " default lang sys tag: " + dt);
- log.debug(tableTag + " default lang sys table offset: " + dl);
- }
- }
- // read language system record count
- int nl = in.readTTFUShort();
- List ll = new java.util.ArrayList();
- if (nl > 0) {
- String[] lta = new String[nl];
- int[] loa = new int[nl];
- // read language system records
- for (int i = 0, n = nl; i < n; i++) {
- String lt = in.readTTFString(4);
- int lo = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lang sys tag: " + lt);
- log.debug(tableTag + " lang sys table offset: " + lo);
- }
- lta[i] = lt;
- loa[i] = lo;
- if (dl == lo) {
- dl = 0;
- dt = lt;
- }
- ll.add(lt);
- }
- // read non-default language system tables
- for (int i = 0, n = nl; i < n; i++) {
- readLangSysTable(tableTag, scriptTable + loa [ i ], lta [ i ]);
- }
- }
- // read default language system table (if specified)
- if (dl > 0) {
- readLangSysTable(tableTag, scriptTable + dl, dt);
- } else if (dt != null) {
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lang sys default: " + dt);
- }
- }
- seScripts.put(scriptTag, new Object[] { dt, ll, seLanguages });
- seLanguages = null;
- }
-
- private void readScriptList(OFTableName tableTag, long scriptList) throws IOException {
- in.seekSet(scriptList);
- // read script record count
- int ns = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " script list record count: " + ns);
- }
- if (ns > 0) {
- String[] sta = new String[ns];
- int[] soa = new int[ns];
- // read script records
- for (int i = 0, n = ns; i < n; i++) {
- String st = in.readTTFString(4);
- int so = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " script tag: " + st);
- log.debug(tableTag + " script table offset: " + so);
- }
- sta[i] = st;
- soa[i] = so;
- }
- // read script tables
- for (int i = 0, n = ns; i < n; i++) {
- seLanguages = null;
- readScriptTable(tableTag, scriptList + soa [ i ], sta [ i ]);
- }
- }
- }
-
- private void readFeatureTable(OFTableName tableTag, long featureTable, String featureTag, int featureIndex) throws IOException {
- in.seekSet(featureTable);
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " feature table: " + featureTag);
- }
- // read feature params offset
- int po = in.readTTFUShort();
- // read lookup list indices count
- int nl = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " feature table parameters offset: " + po);
- log.debug(tableTag + " feature table lookup list index count: " + nl);
- }
- // read lookup table indices
- List lul = new java.util.ArrayList();
- for (int i = 0; i < nl; i++) {
- int li = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " feature table lookup index: " + li);
- }
- lul.add("lu" + li);
- }
- seFeatures.put("f" + featureIndex, new Object[] { featureTag, lul });
- }
-
- private void readFeatureList(OFTableName tableTag, long featureList) throws IOException {
- in.seekSet(featureList);
- // read feature record count
- int nf = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " feature list record count: " + nf);
- }
- if (nf > 0) {
- String[] fta = new String[nf];
- int[] foa = new int[nf];
- // read feature records
- for (int i = 0, n = nf; i < n; i++) {
- String ft = in.readTTFString(4);
- int fo = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " feature tag: " + ft);
- log.debug(tableTag + " feature table offset: " + fo);
- }
- fta[i] = ft;
- foa[i] = fo;
- }
- // read feature tables
- for (int i = 0, n = nf; i < n; i++) {
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " feature index: " + i);
- }
- readFeatureTable(tableTag, featureList + foa [ i ], fta [ i ], i);
- }
- }
- }
-
- static final class GDEFLookupType {
- static final int GLYPH_CLASS = 1;
- static final int ATTACHMENT_POINT = 2;
- static final int LIGATURE_CARET = 3;
- static final int MARK_ATTACHMENT = 4;
- private GDEFLookupType() {
- }
- public static int getSubtableType(int lt) {
- int st;
- switch (lt) {
- case GDEFLookupType.GLYPH_CLASS:
- st = GlyphDefinitionTable.GDEF_LOOKUP_TYPE_GLYPH_CLASS;
- break;
- case GDEFLookupType.ATTACHMENT_POINT:
- st = GlyphDefinitionTable.GDEF_LOOKUP_TYPE_ATTACHMENT_POINT;
- break;
- case GDEFLookupType.LIGATURE_CARET:
- st = GlyphDefinitionTable.GDEF_LOOKUP_TYPE_LIGATURE_CARET;
- break;
- case GDEFLookupType.MARK_ATTACHMENT:
- st = GlyphDefinitionTable.GDEF_LOOKUP_TYPE_MARK_ATTACHMENT;
- break;
- default:
- st = -1;
- break;
- }
- return st;
- }
- public static String toString(int type) {
- String s;
- switch (type) {
- case GLYPH_CLASS:
- s = "GlyphClass";
- break;
- case ATTACHMENT_POINT:
- s = "AttachmentPoint";
- break;
- case LIGATURE_CARET:
- s = "LigatureCaret";
- break;
- case MARK_ATTACHMENT:
- s = "MarkAttachment";
- break;
- default:
- s = "?";
- break;
- }
- return s;
- }
- }
-
- static final class GSUBLookupType {
- static final int SINGLE = 1;
- static final int MULTIPLE = 2;
- static final int ALTERNATE = 3;
- static final int LIGATURE = 4;
- static final int CONTEXTUAL = 5;
- static final int CHAINED_CONTEXTUAL = 6;
- static final int EXTENSION = 7;
- static final int REVERSE_CHAINED_SINGLE = 8;
- private GSUBLookupType() {
- }
- public static int getSubtableType(int lt) {
- int st;
- switch (lt) {
- case GSUBLookupType.SINGLE:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_SINGLE;
- break;
- case GSUBLookupType.MULTIPLE:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_MULTIPLE;
- break;
- case GSUBLookupType.ALTERNATE:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_ALTERNATE;
- break;
- case GSUBLookupType.LIGATURE:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_LIGATURE;
- break;
- case GSUBLookupType.CONTEXTUAL:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_CONTEXTUAL;
- break;
- case GSUBLookupType.CHAINED_CONTEXTUAL:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_CHAINED_CONTEXTUAL;
- break;
- case GSUBLookupType.EXTENSION:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_EXTENSION_SUBSTITUTION;
- break;
- case GSUBLookupType.REVERSE_CHAINED_SINGLE:
- st = GlyphSubstitutionTable.GSUB_LOOKUP_TYPE_REVERSE_CHAINED_SINGLE;
- break;
- default:
- st = -1;
- break;
- }
- return st;
- }
- public static String toString(int type) {
- String s;
- switch (type) {
- case SINGLE:
- s = "Single";
- break;
- case MULTIPLE:
- s = "Multiple";
- break;
- case ALTERNATE:
- s = "Alternate";
- break;
- case LIGATURE:
- s = "Ligature";
- break;
- case CONTEXTUAL:
- s = "Contextual";
- break;
- case CHAINED_CONTEXTUAL:
- s = "ChainedContextual";
- break;
- case EXTENSION:
- s = "Extension";
- break;
- case REVERSE_CHAINED_SINGLE:
- s = "ReverseChainedSingle";
- break;
- default:
- s = "?";
- break;
- }
- return s;
- }
- }
-
- static final class GPOSLookupType {
- static final int SINGLE = 1;
- static final int PAIR = 2;
- static final int CURSIVE = 3;
- static final int MARK_TO_BASE = 4;
- static final int MARK_TO_LIGATURE = 5;
- static final int MARK_TO_MARK = 6;
- static final int CONTEXTUAL = 7;
- static final int CHAINED_CONTEXTUAL = 8;
- static final int EXTENSION = 9;
- private GPOSLookupType() {
- }
- public static String toString(int type) {
- String s;
- switch (type) {
- case SINGLE:
- s = "Single";
- break;
- case PAIR:
- s = "Pair";
- break;
- case CURSIVE:
- s = "Cursive";
- break;
- case MARK_TO_BASE:
- s = "MarkToBase";
- break;
- case MARK_TO_LIGATURE:
- s = "MarkToLigature";
- break;
- case MARK_TO_MARK:
- s = "MarkToMark";
- break;
- case CONTEXTUAL:
- s = "Contextual";
- break;
- case CHAINED_CONTEXTUAL:
- s = "ChainedContextual";
- break;
- case EXTENSION:
- s = "Extension";
- break;
- default:
- s = "?";
- break;
- }
- return s;
- }
- }
-
- static final class LookupFlag {
- static final int RIGHT_TO_LEFT = 0x0001;
- static final int IGNORE_BASE_GLYPHS = 0x0002;
- static final int IGNORE_LIGATURE = 0x0004;
- static final int IGNORE_MARKS = 0x0008;
- static final int USE_MARK_FILTERING_SET = 0x0010;
- static final int MARK_ATTACHMENT_TYPE = 0xFF00;
- private LookupFlag() {
- }
- public static String toString(int flags) {
- StringBuffer sb = new StringBuffer();
- boolean first = true;
- if ((flags & RIGHT_TO_LEFT) != 0) {
- if (first) {
- first = false;
- } else {
- sb.append('|');
- }
- sb.append("RightToLeft");
- }
- if ((flags & IGNORE_BASE_GLYPHS) != 0) {
- if (first) {
- first = false;
- } else {
- sb.append('|');
- }
- sb.append("IgnoreBaseGlyphs");
- }
- if ((flags & IGNORE_LIGATURE) != 0) {
- if (first) {
- first = false;
- } else {
- sb.append('|');
- }
- sb.append("IgnoreLigature");
- }
- if ((flags & IGNORE_MARKS) != 0) {
- if (first) {
- first = false;
- } else {
- sb.append('|');
- }
- sb.append("IgnoreMarks");
- }
- if ((flags & USE_MARK_FILTERING_SET) != 0) {
- if (first) {
- first = false;
- } else {
- sb.append('|');
- }
- sb.append("UseMarkFilteringSet");
- }
- if (sb.length() == 0) {
- sb.append('-');
- }
- return sb.toString();
- }
- }
-
- private GlyphCoverageTable readCoverageTableFormat1(String label, long tableOffset, int coverageFormat) throws IOException {
- List entries = new java.util.ArrayList();
- in.seekSet(tableOffset);
- // skip over format (already known)
- in.skip(2);
- // read glyph count
- int ng = in.readTTFUShort();
- int[] ga = new int[ng];
- for (int i = 0, n = ng; i < n; i++) {
- int g = in.readTTFUShort();
- ga[i] = g;
- entries.add(g);
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(label + " glyphs: " + toString(ga));
- }
- return GlyphCoverageTable.createCoverageTable(entries);
- }
-
- private GlyphCoverageTable readCoverageTableFormat2(String label, long tableOffset, int coverageFormat) throws IOException {
- List entries = new java.util.ArrayList();
- in.seekSet(tableOffset);
- // skip over format (already known)
- in.skip(2);
- // read range record count
- int nr = in.readTTFUShort();
- for (int i = 0, n = nr; i < n; i++) {
- // read range start
- int s = in.readTTFUShort();
- // read range end
- int e = in.readTTFUShort();
- // read range coverage (mapping) index
- int m = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(label + " range[" + i + "]: [" + s + "," + e + "]: " + m);
- }
- entries.add(new GlyphCoverageTable.MappingRange(s, e, m));
- }
- return GlyphCoverageTable.createCoverageTable(entries);
- }
-
- private GlyphCoverageTable readCoverageTable(String label, long tableOffset) throws IOException {
- GlyphCoverageTable gct;
- long cp = in.getCurrentPos();
- in.seekSet(tableOffset);
- // read coverage table format
- int cf = in.readTTFUShort();
- if (cf == 1) {
- gct = readCoverageTableFormat1(label, tableOffset, cf);
- } else if (cf == 2) {
- gct = readCoverageTableFormat2(label, tableOffset, cf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported coverage table format: " + cf);
- }
- in.seekSet(cp);
- return gct;
- }
-
- private GlyphClassTable readClassDefTableFormat1(String label, long tableOffset, int classFormat) throws IOException {
- List entries = new java.util.ArrayList();
- in.seekSet(tableOffset);
- // skip over format (already known)
- in.skip(2);
- // read start glyph
- int sg = in.readTTFUShort();
- entries.add(sg);
- // read glyph count
- int ng = in.readTTFUShort();
- // read glyph classes
- int[] ca = new int[ng];
- for (int i = 0, n = ng; i < n; i++) {
- int gc = in.readTTFUShort();
- ca[i] = gc;
- entries.add(gc);
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(label + " glyph classes: " + toString(ca));
- }
- return GlyphClassTable.createClassTable(entries);
- }
-
- private GlyphClassTable readClassDefTableFormat2(String label, long tableOffset, int classFormat) throws IOException {
- List entries = new java.util.ArrayList();
- in.seekSet(tableOffset);
- // skip over format (already known)
- in.skip(2);
- // read range record count
- int nr = in.readTTFUShort();
- for (int i = 0, n = nr; i < n; i++) {
- // read range start
- int s = in.readTTFUShort();
- // read range end
- int e = in.readTTFUShort();
- // read range glyph class (mapping) index
- int m = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(label + " range[" + i + "]: [" + s + "," + e + "]: " + m);
- }
- entries.add(new GlyphClassTable.MappingRange(s, e, m));
- }
- return GlyphClassTable.createClassTable(entries);
- }
-
- private GlyphClassTable readClassDefTable(String label, long tableOffset) throws IOException {
- GlyphClassTable gct;
- long cp = in.getCurrentPos();
- in.seekSet(tableOffset);
- // read class table format
- int cf = in.readTTFUShort();
- if (cf == 1) {
- gct = readClassDefTableFormat1(label, tableOffset, cf);
- } else if (cf == 2) {
- gct = readClassDefTableFormat2(label, tableOffset, cf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported class definition table format: " + cf);
- }
- in.seekSet(cp);
- return gct;
- }
-
- private void readSingleSubTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read delta glyph
- int dg = in.readTTFShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " single substitution subtable format: " + subtableFormat + " (delta)");
- log.debug(tableTag + " single substitution coverage table offset: " + co);
- log.debug(tableTag + " single substitution delta: " + dg);
- }
- // read coverage table
- seMapping = readCoverageTable(tableTag + " single substitution coverage", subtableOffset + co);
- seEntries.add(dg);
- }
-
- private void readSingleSubTableFormat2(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read glyph count
- int ng = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " single substitution subtable format: " + subtableFormat + " (mapped)");
- log.debug(tableTag + " single substitution coverage table offset: " + co);
- log.debug(tableTag + " single substitution glyph count: " + ng);
- }
- // read coverage table
- seMapping = readCoverageTable(tableTag + " single substitution coverage", subtableOffset + co);
- // read glyph substitutions
- for (int i = 0, n = ng; i < n; i++) {
- int gs = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " single substitution glyph[" + i + "]: " + gs);
- }
- seEntries.add(gs);
- }
- }
-
- private int readSingleSubTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readSingleSubTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 2) {
- readSingleSubTableFormat2(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported single substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private void readMultipleSubTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read sequence count
- int ns = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " multiple substitution subtable format: " + subtableFormat + " (mapped)");
- log.debug(tableTag + " multiple substitution coverage table offset: " + co);
- log.debug(tableTag + " multiple substitution sequence count: " + ns);
- }
- // read coverage table
- seMapping = readCoverageTable(tableTag + " multiple substitution coverage", subtableOffset + co);
- // read sequence table offsets
- int[] soa = new int[ns];
- for (int i = 0, n = ns; i < n; i++) {
- soa[i] = in.readTTFUShort();
- }
- // read sequence tables
- int[][] gsa = new int [ ns ] [];
- for (int i = 0, n = ns; i < n; i++) {
- int so = soa[i];
- int[] ga;
- if (so > 0) {
- in.seekSet(subtableOffset + so);
- // read glyph count
- int ng = in.readTTFUShort();
- ga = new int[ng];
- for (int j = 0; j < ng; j++) {
- ga[j] = in.readTTFUShort();
- }
- } else {
- ga = null;
- }
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " multiple substitution sequence[" + i + "]: " + toString(ga));
- }
- gsa [ i ] = ga;
- }
- seEntries.add(gsa);
- }
-
- private int readMultipleSubTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readMultipleSubTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported multiple substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private void readAlternateSubTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read alternate set count
- int ns = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " alternate substitution subtable format: " + subtableFormat + " (mapped)");
- log.debug(tableTag + " alternate substitution coverage table offset: " + co);
- log.debug(tableTag + " alternate substitution alternate set count: " + ns);
- }
- // read coverage table
- seMapping = readCoverageTable(tableTag + " alternate substitution coverage", subtableOffset + co);
- // read alternate set table offsets
- int[] soa = new int[ns];
- for (int i = 0, n = ns; i < n; i++) {
- soa[i] = in.readTTFUShort();
- }
- // read alternate set tables
- for (int i = 0, n = ns; i < n; i++) {
- int so = soa[i];
- in.seekSet(subtableOffset + so);
- // read glyph count
- int ng = in.readTTFUShort();
- int[] ga = new int[ng];
- for (int j = 0; j < ng; j++) {
- int gs = in.readTTFUShort();
- ga[j] = gs;
- }
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " alternate substitution alternate set[" + i + "]: " + toString(ga));
- }
- seEntries.add(ga);
- }
- }
-
- private int readAlternateSubTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readAlternateSubTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported alternate substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private void readLigatureSubTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read ligature set count
- int ns = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " ligature substitution subtable format: " + subtableFormat + " (mapped)");
- log.debug(tableTag + " ligature substitution coverage table offset: " + co);
- log.debug(tableTag + " ligature substitution ligature set count: " + ns);
- }
- // read coverage table
- seMapping = readCoverageTable(tableTag + " ligature substitution coverage", subtableOffset + co);
- // read ligature set table offsets
- int[] soa = new int[ns];
- for (int i = 0, n = ns; i < n; i++) {
- soa[i] = in.readTTFUShort();
- }
- // read ligature set tables
- for (int i = 0, n = ns; i < n; i++) {
- int so = soa[i];
- in.seekSet(subtableOffset + so);
- // read ligature table count
- int nl = in.readTTFUShort();
- int[] loa = new int[nl];
- for (int j = 0; j < nl; j++) {
- loa[j] = in.readTTFUShort();
- }
- List ligs = new java.util.ArrayList();
- for (int j = 0; j < nl; j++) {
- int lo = loa[j];
- in.seekSet(subtableOffset + so + lo);
- // read ligature glyph id
- int lg = in.readTTFUShort();
- // read ligature (input) component count
- int nc = in.readTTFUShort();
- int[] ca = new int [ nc - 1 ];
- // read ligature (input) component glyph ids
- for (int k = 0; k < nc - 1; k++) {
- ca[k] = in.readTTFUShort();
- }
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " ligature substitution ligature set[" + i + "]: ligature(" + lg + "), components: " + toString(ca));
- }
- ligs.add(new GlyphSubstitutionTable.Ligature(lg, ca));
- }
- seEntries.add(new GlyphSubstitutionTable.LigatureSet(ligs));
- }
- }
-
- private int readLigatureSubTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readLigatureSubTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported ligature substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private GlyphTable.RuleLookup[] readRuleLookups(int numLookups, String header) throws IOException {
- GlyphTable.RuleLookup[] la = new GlyphTable.RuleLookup [ numLookups ];
- for (int i = 0, n = numLookups; i < n; i++) {
- int sequenceIndex = in.readTTFUShort();
- int lookupIndex = in.readTTFUShort();
- la [ i ] = new GlyphTable.RuleLookup(sequenceIndex, lookupIndex);
- // dump info if debugging and header is non-null
- if (log.isDebugEnabled() && (header != null)) {
- log.debug(header + "lookup[" + i + "]: " + la[i]);
- }
- }
- return la;
- }
-
- private void readContextualSubTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read rule set count
- int nrs = in.readTTFUShort();
- // read rule set offsets
- int[] rsoa = new int [ nrs ];
- for (int i = 0; i < nrs; i++) {
- rsoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " contextual substitution format: " + subtableFormat + " (glyphs)");
- log.debug(tableTag + " contextual substitution coverage table offset: " + co);
- log.debug(tableTag + " contextual substitution rule set count: " + nrs);
- for (int i = 0; i < nrs; i++) {
- log.debug(tableTag + " contextual substitution rule set offset[" + i + "]: " + rsoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " contextual substitution coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ nrs ];
- String header = null;
- for (int i = 0; i < nrs; i++) {
- GlyphTable.RuleSet rs;
- int rso = rsoa [ i ];
- if (rso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + rso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- GlyphTable.GlyphSequenceRule r;
- int ro = roa [ j ];
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + rso + ro);
- // read glyph count
- int ng = in.readTTFUShort();
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read glyphs
- int[] glyphs = new int [ ng - 1 ];
- for (int k = 0, nk = glyphs.length; k < nk; k++) {
- glyphs [ k ] = in.readTTFUShort();
- }
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual substitution lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.GlyphSequenceRule(lookups, ng, glyphs);
- } else {
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(rsa);
- }
-
- private void readContextualSubTableFormat2(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read class def table offset
- int cdo = in.readTTFUShort();
- // read class rule set count
- int ngc = in.readTTFUShort();
- // read class rule set offsets
- int[] csoa = new int [ ngc ];
- for (int i = 0; i < ngc; i++) {
- csoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " contextual substitution format: " + subtableFormat + " (glyph classes)");
- log.debug(tableTag + " contextual substitution coverage table offset: " + co);
- log.debug(tableTag + " contextual substitution class set count: " + ngc);
- for (int i = 0; i < ngc; i++) {
- log.debug(tableTag + " contextual substitution class set offset[" + i + "]: " + csoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " contextual substitution coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read class definition table
- GlyphClassTable cdt;
- if (cdo > 0) {
- cdt = readClassDefTable(tableTag + " contextual substitution class definition", subtableOffset + cdo);
- } else {
- cdt = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ ngc ];
- String header = null;
- for (int i = 0; i < ngc; i++) {
- int cso = csoa [ i ];
- GlyphTable.RuleSet rs;
- if (cso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + cso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- int ro = roa [ j ];
- GlyphTable.ClassSequenceRule r;
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + cso + ro);
- // read glyph count
- int ng = in.readTTFUShort();
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read classes
- int[] classes = new int [ ng - 1 ];
- for (int k = 0, nk = classes.length; k < nk; k++) {
- classes [ k ] = in.readTTFUShort();
- }
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual substitution lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.ClassSequenceRule(lookups, ng, classes);
- } else {
- assert ro > 0 : "unexpected null subclass rule offset";
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(cdt);
- seEntries.add(ngc);
- seEntries.add(rsa);
- }
-
- private void readContextualSubTableFormat3(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read glyph (input sequence length) count
- int ng = in.readTTFUShort();
- // read substitution lookup count
- int nl = in.readTTFUShort();
- // read glyph coverage offsets, one per glyph input sequence length count
- int[] gcoa = new int [ ng ];
- for (int i = 0; i < ng; i++) {
- gcoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " contextual substitution format: " + subtableFormat + " (glyph sets)");
- log.debug(tableTag + " contextual substitution glyph input sequence length count: " + ng);
- log.debug(tableTag + " contextual substitution lookup count: " + nl);
- for (int i = 0; i < ng; i++) {
- log.debug(tableTag + " contextual substitution coverage table offset[" + i + "]: " + gcoa[i]);
- }
- }
- // read coverage tables
- GlyphCoverageTable[] gca = new GlyphCoverageTable [ ng ];
- for (int i = 0; i < ng; i++) {
- int gco = gcoa [ i ];
- GlyphCoverageTable gct;
- if (gco > 0) {
- gct = readCoverageTable(tableTag + " contextual substitution coverage[" + i + "]", subtableOffset + gco);
- } else {
- gct = null;
- }
- gca [ i ] = gct;
- }
- // read rule lookups
- String header = null;
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual substitution lookups: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- // construct rule, rule set, and rule set array
- GlyphTable.Rule r = new GlyphTable.CoverageSequenceRule(lookups, ng, gca);
- GlyphTable.RuleSet rs = new GlyphTable.HomogeneousRuleSet(new GlyphTable.Rule[] {r});
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet[] {rs};
- // store results
- assert (gca != null) && (gca.length > 0);
- seMapping = gca[0];
- seEntries.add(rsa);
- }
-
- private int readContextualSubTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readContextualSubTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 2) {
- readContextualSubTableFormat2(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 3) {
- readContextualSubTableFormat3(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported contextual substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private void readChainedContextualSubTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read rule set count
- int nrs = in.readTTFUShort();
- // read rule set offsets
- int[] rsoa = new int [ nrs ];
- for (int i = 0; i < nrs; i++) {
- rsoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " chained contextual substitution format: " + subtableFormat + " (glyphs)");
- log.debug(tableTag + " chained contextual substitution coverage table offset: " + co);
- log.debug(tableTag + " chained contextual substitution rule set count: " + nrs);
- for (int i = 0; i < nrs; i++) {
- log.debug(tableTag + " chained contextual substitution rule set offset[" + i + "]: " + rsoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " chained contextual substitution coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ nrs ];
- String header = null;
- for (int i = 0; i < nrs; i++) {
- GlyphTable.RuleSet rs;
- int rso = rsoa [ i ];
- if (rso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + rso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- GlyphTable.ChainedGlyphSequenceRule r;
- int ro = roa [ j ];
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + rso + ro);
- // read backtrack glyph count
- int nbg = in.readTTFUShort();
- // read backtrack glyphs
- int[] backtrackGlyphs = new int [ nbg ];
- for (int k = 0, nk = backtrackGlyphs.length; k < nk; k++) {
- backtrackGlyphs [ k ] = in.readTTFUShort();
- }
- // read input glyph count
- int nig = in.readTTFUShort();
- // read glyphs
- int[] glyphs = new int [ nig - 1 ];
- for (int k = 0, nk = glyphs.length; k < nk; k++) {
- glyphs [ k ] = in.readTTFUShort();
- }
- // read lookahead glyph count
- int nlg = in.readTTFUShort();
- // read lookahead glyphs
- int[] lookaheadGlyphs = new int [ nlg ];
- for (int k = 0, nk = lookaheadGlyphs.length; k < nk; k++) {
- lookaheadGlyphs [ k ] = in.readTTFUShort();
- }
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual substitution lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.ChainedGlyphSequenceRule(lookups, nig, glyphs, backtrackGlyphs, lookaheadGlyphs);
- } else {
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(rsa);
- }
-
- private void readChainedContextualSubTableFormat2(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read backtrack class def table offset
- int bcdo = in.readTTFUShort();
- // read input class def table offset
- int icdo = in.readTTFUShort();
- // read lookahead class def table offset
- int lcdo = in.readTTFUShort();
- // read class set count
- int ngc = in.readTTFUShort();
- // read class set offsets
- int[] csoa = new int [ ngc ];
- for (int i = 0; i < ngc; i++) {
- csoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " chained contextual substitution format: " + subtableFormat + " (glyph classes)");
- log.debug(tableTag + " chained contextual substitution coverage table offset: " + co);
- log.debug(tableTag + " chained contextual substitution class set count: " + ngc);
- for (int i = 0; i < ngc; i++) {
- log.debug(tableTag + " chained contextual substitution class set offset[" + i + "]: " + csoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " chained contextual substitution coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read backtrack class definition table
- GlyphClassTable bcdt;
- if (bcdo > 0) {
- bcdt = readClassDefTable(tableTag + " contextual substitution backtrack class definition", subtableOffset + bcdo);
- } else {
- bcdt = null;
- }
- // read input class definition table
- GlyphClassTable icdt;
- if (icdo > 0) {
- icdt = readClassDefTable(tableTag + " contextual substitution input class definition", subtableOffset + icdo);
- } else {
- icdt = null;
- }
- // read lookahead class definition table
- GlyphClassTable lcdt;
- if (lcdo > 0) {
- lcdt = readClassDefTable(tableTag + " contextual substitution lookahead class definition", subtableOffset + lcdo);
- } else {
- lcdt = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ ngc ];
- String header = null;
- for (int i = 0; i < ngc; i++) {
- int cso = csoa [ i ];
- GlyphTable.RuleSet rs;
- if (cso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + cso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- int ro = roa [ j ];
- GlyphTable.ChainedClassSequenceRule r;
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + cso + ro);
- // read backtrack glyph class count
- int nbc = in.readTTFUShort();
- // read backtrack glyph classes
- int[] backtrackClasses = new int [ nbc ];
- for (int k = 0, nk = backtrackClasses.length; k < nk; k++) {
- backtrackClasses [ k ] = in.readTTFUShort();
- }
- // read input glyph class count
- int nic = in.readTTFUShort();
- // read input glyph classes
- int[] classes = new int [ nic - 1 ];
- for (int k = 0, nk = classes.length; k < nk; k++) {
- classes [ k ] = in.readTTFUShort();
- }
- // read lookahead glyph class count
- int nlc = in.readTTFUShort();
- // read lookahead glyph classes
- int[] lookaheadClasses = new int [ nlc ];
- for (int k = 0, nk = lookaheadClasses.length; k < nk; k++) {
- lookaheadClasses [ k ] = in.readTTFUShort();
- }
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual substitution lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.ChainedClassSequenceRule(lookups, nic, classes, backtrackClasses, lookaheadClasses);
- } else {
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(icdt);
- seEntries.add(bcdt);
- seEntries.add(lcdt);
- seEntries.add(ngc);
- seEntries.add(rsa);
- }
-
- private void readChainedContextualSubTableFormat3(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read backtrack glyph count
- int nbg = in.readTTFUShort();
- // read backtrack glyph coverage offsets
- int[] bgcoa = new int [ nbg ];
- for (int i = 0; i < nbg; i++) {
- bgcoa [ i ] = in.readTTFUShort();
- }
- // read input glyph count
- int nig = in.readTTFUShort();
- // read input glyph coverage offsets
- int[] igcoa = new int [ nig ];
- for (int i = 0; i < nig; i++) {
- igcoa [ i ] = in.readTTFUShort();
- }
- // read lookahead glyph count
- int nlg = in.readTTFUShort();
- // read lookahead glyph coverage offsets
- int[] lgcoa = new int [ nlg ];
- for (int i = 0; i < nlg; i++) {
- lgcoa [ i ] = in.readTTFUShort();
- }
- // read substitution lookup count
- int nl = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " chained contextual substitution format: " + subtableFormat + " (glyph sets)");
- log.debug(tableTag + " chained contextual substitution backtrack glyph count: " + nbg);
- for (int i = 0; i < nbg; i++) {
- log.debug(tableTag + " chained contextual substitution backtrack coverage table offset[" + i + "]: " + bgcoa[i]);
- }
- log.debug(tableTag + " chained contextual substitution input glyph count: " + nig);
- for (int i = 0; i < nig; i++) {
- log.debug(tableTag + " chained contextual substitution input coverage table offset[" + i + "]: " + igcoa[i]);
- }
- log.debug(tableTag + " chained contextual substitution lookahead glyph count: " + nlg);
- for (int i = 0; i < nlg; i++) {
- log.debug(tableTag + " chained contextual substitution lookahead coverage table offset[" + i + "]: " + lgcoa[i]);
- }
- log.debug(tableTag + " chained contextual substitution lookup count: " + nl);
- }
- // read backtrack coverage tables
- GlyphCoverageTable[] bgca = new GlyphCoverageTable[nbg];
- for (int i = 0; i < nbg; i++) {
- int bgco = bgcoa [ i ];
- GlyphCoverageTable bgct;
- if (bgco > 0) {
- bgct = readCoverageTable(tableTag + " chained contextual substitution backtrack coverage[" + i + "]", subtableOffset + bgco);
- } else {
- bgct = null;
- }
- bgca[i] = bgct;
- }
- // read input coverage tables
- GlyphCoverageTable[] igca = new GlyphCoverageTable[nig];
- for (int i = 0; i < nig; i++) {
- int igco = igcoa [ i ];
- GlyphCoverageTable igct;
- if (igco > 0) {
- igct = readCoverageTable(tableTag + " chained contextual substitution input coverage[" + i + "]", subtableOffset + igco);
- } else {
- igct = null;
- }
- igca[i] = igct;
- }
- // read lookahead coverage tables
- GlyphCoverageTable[] lgca = new GlyphCoverageTable[nlg];
- for (int i = 0; i < nlg; i++) {
- int lgco = lgcoa [ i ];
- GlyphCoverageTable lgct;
- if (lgco > 0) {
- lgct = readCoverageTable(tableTag + " chained contextual substitution lookahead coverage[" + i + "]", subtableOffset + lgco);
- } else {
- lgct = null;
- }
- lgca[i] = lgct;
- }
- // read rule lookups
- String header = null;
- if (log.isDebugEnabled()) {
- header = tableTag + " chained contextual substitution lookups: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- // construct rule, rule set, and rule set array
- GlyphTable.Rule r = new GlyphTable.ChainedCoverageSequenceRule(lookups, nig, igca, bgca, lgca);
- GlyphTable.RuleSet rs = new GlyphTable.HomogeneousRuleSet(new GlyphTable.Rule[] {r});
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet[] {rs};
- // store results
- assert (igca != null) && (igca.length > 0);
- seMapping = igca[0];
- seEntries.add(rsa);
- }
-
- private int readChainedContextualSubTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readChainedContextualSubTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 2) {
- readChainedContextualSubTableFormat2(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 3) {
- readChainedContextualSubTableFormat3(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported chained contextual substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private void readExtensionSubTableFormat1(int lookupType, int lookupFlags, int lookupSequence, int subtableSequence, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read extension lookup type
- int lt = in.readTTFUShort();
- // read extension offset
- long eo = in.readTTFULong();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " extension substitution subtable format: " + subtableFormat);
- log.debug(tableTag + " extension substitution lookup type: " + lt);
- log.debug(tableTag + " extension substitution lookup table offset: " + eo);
- }
- // read referenced subtable from extended offset
- readGSUBSubtable(lt, lookupFlags, lookupSequence, subtableSequence, subtableOffset + eo);
- }
-
- private int readExtensionSubTable(int lookupType, int lookupFlags, int lookupSequence, int subtableSequence, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readExtensionSubTableFormat1(lookupType, lookupFlags, lookupSequence, subtableSequence, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported extension substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private void readReverseChainedSingleSubTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GSUB";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read backtrack glyph count
- int nbg = in.readTTFUShort();
- // read backtrack glyph coverage offsets
- int[] bgcoa = new int [ nbg ];
- for (int i = 0; i < nbg; i++) {
- bgcoa [ i ] = in.readTTFUShort();
- }
- // read lookahead glyph count
- int nlg = in.readTTFUShort();
- // read backtrack glyph coverage offsets
- int[] lgcoa = new int [ nlg ];
- for (int i = 0; i < nlg; i++) {
- lgcoa [ i ] = in.readTTFUShort();
- }
- // read substitution (output) glyph count
- int ng = in.readTTFUShort();
- // read substitution (output) glyphs
- int[] glyphs = new int [ ng ];
- for (int i = 0, n = ng; i < n; i++) {
- glyphs [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " reverse chained contextual substitution format: " + subtableFormat);
- log.debug(tableTag + " reverse chained contextual substitution coverage table offset: " + co);
- log.debug(tableTag + " reverse chained contextual substitution backtrack glyph count: " + nbg);
- for (int i = 0; i < nbg; i++) {
- log.debug(tableTag + " reverse chained contextual substitution backtrack coverage table offset[" + i + "]: " + bgcoa[i]);
- }
- log.debug(tableTag + " reverse chained contextual substitution lookahead glyph count: " + nlg);
- for (int i = 0; i < nlg; i++) {
- log.debug(tableTag + " reverse chained contextual substitution lookahead coverage table offset[" + i + "]: " + lgcoa[i]);
- }
- log.debug(tableTag + " reverse chained contextual substitution glyphs: " + toString(glyphs));
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " reverse chained contextual substitution coverage", subtableOffset + co);
- // read backtrack coverage tables
- GlyphCoverageTable[] bgca = new GlyphCoverageTable[nbg];
- for (int i = 0; i < nbg; i++) {
- int bgco = bgcoa[i];
- GlyphCoverageTable bgct;
- if (bgco > 0) {
- bgct = readCoverageTable(tableTag + " reverse chained contextual substitution backtrack coverage[" + i + "]", subtableOffset + bgco);
- } else {
- bgct = null;
- }
- bgca[i] = bgct;
- }
- // read lookahead coverage tables
- GlyphCoverageTable[] lgca = new GlyphCoverageTable[nlg];
- for (int i = 0; i < nlg; i++) {
- int lgco = lgcoa[i];
- GlyphCoverageTable lgct;
- if (lgco > 0) {
- lgct = readCoverageTable(tableTag + " reverse chained contextual substitution lookahead coverage[" + i + "]", subtableOffset + lgco);
- } else {
- lgct = null;
- }
- lgca[i] = lgct;
- }
- // store results
- seMapping = ct;
- seEntries.add(bgca);
- seEntries.add(lgca);
- seEntries.add(glyphs);
- }
-
- private int readReverseChainedSingleSubTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read substitution subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readReverseChainedSingleSubTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported reverse chained single substitution subtable format: " + sf);
- }
- return sf;
- }
-
- private void readGSUBSubtable(int lookupType, int lookupFlags, int lookupSequence, int subtableSequence, long subtableOffset) throws IOException {
- initATSubState();
- int subtableFormat = -1;
- switch (lookupType) {
- case GSUBLookupType.SINGLE:
- subtableFormat = readSingleSubTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GSUBLookupType.MULTIPLE:
- subtableFormat = readMultipleSubTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GSUBLookupType.ALTERNATE:
- subtableFormat = readAlternateSubTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GSUBLookupType.LIGATURE:
- subtableFormat = readLigatureSubTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GSUBLookupType.CONTEXTUAL:
- subtableFormat = readContextualSubTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GSUBLookupType.CHAINED_CONTEXTUAL:
- subtableFormat = readChainedContextualSubTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GSUBLookupType.REVERSE_CHAINED_SINGLE:
- subtableFormat = readReverseChainedSingleSubTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GSUBLookupType.EXTENSION:
- subtableFormat = readExtensionSubTable(lookupType, lookupFlags, lookupSequence, subtableSequence, subtableOffset);
- break;
- default:
- break;
- }
- extractSESubState(GlyphTable.GLYPH_TABLE_TYPE_SUBSTITUTION, lookupType, lookupFlags, lookupSequence, subtableSequence, subtableFormat);
- resetATSubState();
- }
-
- private GlyphPositioningTable.DeviceTable readPosDeviceTable(long subtableOffset, long deviceTableOffset) throws IOException {
- long cp = in.getCurrentPos();
- in.seekSet(subtableOffset + deviceTableOffset);
- // read start size
- int ss = in.readTTFUShort();
- // read end size
- int es = in.readTTFUShort();
- // read delta format
- int df = in.readTTFUShort();
- int s1;
- int m1;
- int dm;
- int dd;
- int s2;
- if (df == 1) {
- s1 = 14;
- m1 = 0x3;
- dm = 1;
- dd = 4;
- s2 = 2;
- } else if (df == 2) {
- s1 = 12;
- m1 = 0xF;
- dm = 7;
- dd = 16;
- s2 = 4;
- } else if (df == 3) {
- s1 = 8;
- m1 = 0xFF;
- dm = 127;
- dd = 256;
- s2 = 8;
- } else {
- log.debug("unsupported device table delta format: " + df + ", ignoring device table");
- return null;
- }
- // read deltas
- int n = (es - ss) + 1;
- if (n < 0) {
- log.debug("invalid device table delta count: " + n + ", ignoring device table");
- return null;
- }
- int[] da = new int [ n ];
- for (int i = 0; (i < n) && (s2 > 0);) {
- int p = in.readTTFUShort();
- for (int j = 0, k = 16 / s2; j < k; j++) {
- int d = (p >> s1) & m1;
- if (d > dm) {
- d -= dd;
- }
- if (i < n) {
- da [ i++ ] = d;
- } else {
- break;
- }
- p <<= s2;
- }
- }
- in.seekSet(cp);
- return new GlyphPositioningTable.DeviceTable(ss, es, da);
- }
-
- private GlyphPositioningTable.Value readPosValue(long subtableOffset, int valueFormat) throws IOException {
- // XPlacement
- int xp;
- if ((valueFormat & GlyphPositioningTable.Value.X_PLACEMENT) != 0) {
- xp = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- } else {
- xp = 0;
- }
- // YPlacement
- int yp;
- if ((valueFormat & GlyphPositioningTable.Value.Y_PLACEMENT) != 0) {
- yp = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- } else {
- yp = 0;
- }
- // XAdvance
- int xa;
- if ((valueFormat & GlyphPositioningTable.Value.X_ADVANCE) != 0) {
- xa = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- } else {
- xa = 0;
- }
- // YAdvance
- int ya;
- if ((valueFormat & GlyphPositioningTable.Value.Y_ADVANCE) != 0) {
- ya = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- } else {
- ya = 0;
- }
- // XPlaDevice
- GlyphPositioningTable.DeviceTable xpd;
- if ((valueFormat & GlyphPositioningTable.Value.X_PLACEMENT_DEVICE) != 0) {
- int xpdo = in.readTTFUShort();
- xpd = readPosDeviceTable(subtableOffset, xpdo);
- } else {
- xpd = null;
- }
- // YPlaDevice
- GlyphPositioningTable.DeviceTable ypd;
- if ((valueFormat & GlyphPositioningTable.Value.Y_PLACEMENT_DEVICE) != 0) {
- int ypdo = in.readTTFUShort();
- ypd = readPosDeviceTable(subtableOffset, ypdo);
- } else {
- ypd = null;
- }
- // XAdvDevice
- GlyphPositioningTable.DeviceTable xad;
- if ((valueFormat & GlyphPositioningTable.Value.X_ADVANCE_DEVICE) != 0) {
- int xado = in.readTTFUShort();
- xad = readPosDeviceTable(subtableOffset, xado);
- } else {
- xad = null;
- }
- // YAdvDevice
- GlyphPositioningTable.DeviceTable yad;
- if ((valueFormat & GlyphPositioningTable.Value.Y_ADVANCE_DEVICE) != 0) {
- int yado = in.readTTFUShort();
- yad = readPosDeviceTable(subtableOffset, yado);
- } else {
- yad = null;
- }
- return new GlyphPositioningTable.Value(xp, yp, xa, ya, xpd, ypd, xad, yad);
- }
-
- private void readSinglePosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read value format
- int vf = in.readTTFUShort();
- // read value
- GlyphPositioningTable.Value v = readPosValue(subtableOffset, vf);
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " single positioning subtable format: " + subtableFormat + " (delta)");
- log.debug(tableTag + " single positioning coverage table offset: " + co);
- log.debug(tableTag + " single positioning value: " + v);
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " single positioning coverage", subtableOffset + co);
- // store results
- seMapping = ct;
- seEntries.add(v);
- }
-
- private void readSinglePosTableFormat2(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read value format
- int vf = in.readTTFUShort();
- // read value count
- int nv = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " single positioning subtable format: " + subtableFormat + " (mapped)");
- log.debug(tableTag + " single positioning coverage table offset: " + co);
- log.debug(tableTag + " single positioning value count: " + nv);
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " single positioning coverage", subtableOffset + co);
- // read positioning values
- GlyphPositioningTable.Value[] pva = new GlyphPositioningTable.Value[nv];
- for (int i = 0, n = nv; i < n; i++) {
- GlyphPositioningTable.Value pv = readPosValue(subtableOffset, vf);
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " single positioning value[" + i + "]: " + pv);
- }
- pva[i] = pv;
- }
- // store results
- seMapping = ct;
- seEntries.add(pva);
- }
-
- private int readSinglePosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positionining subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readSinglePosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 2) {
- readSinglePosTableFormat2(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported single positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private GlyphPositioningTable.PairValues readPosPairValues(long subtableOffset, boolean hasGlyph, int vf1, int vf2) throws IOException {
- // read glyph (if present)
- int glyph;
- if (hasGlyph) {
- glyph = in.readTTFUShort();
- } else {
- glyph = 0;
- }
- // read first value (if present)
- GlyphPositioningTable.Value v1;
- if (vf1 != 0) {
- v1 = readPosValue(subtableOffset, vf1);
- } else {
- v1 = null;
- }
- // read second value (if present)
- GlyphPositioningTable.Value v2;
- if (vf2 != 0) {
- v2 = readPosValue(subtableOffset, vf2);
- } else {
- v2 = null;
- }
- return new GlyphPositioningTable.PairValues(glyph, v1, v2);
- }
-
- private GlyphPositioningTable.PairValues[] readPosPairSetTable(long subtableOffset, int pairSetTableOffset, int vf1, int vf2) throws IOException {
- String tableTag = "GPOS";
- long cp = in.getCurrentPos();
- in.seekSet(subtableOffset + pairSetTableOffset);
- // read pair values count
- int npv = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " pair set table offset: " + pairSetTableOffset);
- log.debug(tableTag + " pair set table values count: " + npv);
- }
- // read pair values
- GlyphPositioningTable.PairValues[] pva = new GlyphPositioningTable.PairValues [ npv ];
- for (int i = 0, n = npv; i < n; i++) {
- GlyphPositioningTable.PairValues pv = readPosPairValues(subtableOffset, true, vf1, vf2);
- pva [ i ] = pv;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " pair set table value[" + i + "]: " + pv);
- }
- }
- in.seekSet(cp);
- return pva;
- }
-
- private void readPairPosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read value format for first glyph
- int vf1 = in.readTTFUShort();
- // read value format for second glyph
- int vf2 = in.readTTFUShort();
- // read number (count) of pair sets
- int nps = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " pair positioning subtable format: " + subtableFormat + " (glyphs)");
- log.debug(tableTag + " pair positioning coverage table offset: " + co);
- log.debug(tableTag + " pair positioning value format #1: " + vf1);
- log.debug(tableTag + " pair positioning value format #2: " + vf2);
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " pair positioning coverage", subtableOffset + co);
- // read pair value matrix
- GlyphPositioningTable.PairValues[][] pvm = new GlyphPositioningTable.PairValues [ nps ][];
- for (int i = 0, n = nps; i < n; i++) {
- // read pair set offset
- int pso = in.readTTFUShort();
- // read pair set table at offset
- pvm [ i ] = readPosPairSetTable(subtableOffset, pso, vf1, vf2);
- }
- // store results
- seMapping = ct;
- seEntries.add(pvm);
- }
-
- private void readPairPosTableFormat2(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read value format for first glyph
- int vf1 = in.readTTFUShort();
- // read value format for second glyph
- int vf2 = in.readTTFUShort();
- // read class def 1 offset
- int cd1o = in.readTTFUShort();
- // read class def 2 offset
- int cd2o = in.readTTFUShort();
- // read number (count) of classes in class def 1 table
- int nc1 = in.readTTFUShort();
- // read number (count) of classes in class def 2 table
- int nc2 = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " pair positioning subtable format: " + subtableFormat + " (glyph classes)");
- log.debug(tableTag + " pair positioning coverage table offset: " + co);
- log.debug(tableTag + " pair positioning value format #1: " + vf1);
- log.debug(tableTag + " pair positioning value format #2: " + vf2);
- log.debug(tableTag + " pair positioning class def table #1 offset: " + cd1o);
- log.debug(tableTag + " pair positioning class def table #2 offset: " + cd2o);
- log.debug(tableTag + " pair positioning class #1 count: " + nc1);
- log.debug(tableTag + " pair positioning class #2 count: " + nc2);
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " pair positioning coverage", subtableOffset + co);
- // read class definition table #1
- GlyphClassTable cdt1 = readClassDefTable(tableTag + " pair positioning class definition #1", subtableOffset + cd1o);
- // read class definition table #2
- GlyphClassTable cdt2 = readClassDefTable(tableTag + " pair positioning class definition #2", subtableOffset + cd2o);
- // read pair value matrix
- GlyphPositioningTable.PairValues[][] pvm = new GlyphPositioningTable.PairValues [ nc1 ] [ nc2 ];
- for (int i = 0; i < nc1; i++) {
- for (int j = 0; j < nc2; j++) {
- GlyphPositioningTable.PairValues pv = readPosPairValues(subtableOffset, false, vf1, vf2);
- pvm [ i ] [ j ] = pv;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " pair set table value[" + i + "][" + j + "]: " + pv);
- }
- }
- }
- // store results
- seMapping = ct;
- seEntries.add(cdt1);
- seEntries.add(cdt2);
- seEntries.add(nc1);
- seEntries.add(nc2);
- seEntries.add(pvm);
- }
-
- private int readPairPosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readPairPosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 2) {
- readPairPosTableFormat2(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported pair positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private GlyphPositioningTable.Anchor readPosAnchor(long anchorTableOffset) throws IOException {
- GlyphPositioningTable.Anchor a;
- long cp = in.getCurrentPos();
- in.seekSet(anchorTableOffset);
- // read anchor table format
- int af = in.readTTFUShort();
- if (af == 1) {
- // read x coordinate
- int x = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- // read y coordinate
- int y = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- a = new GlyphPositioningTable.Anchor(x, y);
- } else if (af == 2) {
- // read x coordinate
- int x = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- // read y coordinate
- int y = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- // read anchor point index
- int ap = in.readTTFUShort();
- a = new GlyphPositioningTable.Anchor(x, y, ap);
- } else if (af == 3) {
- // read x coordinate
- int x = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- // read y coordinate
- int y = otf.convertTTFUnit2PDFUnit(in.readTTFShort());
- // read x device table offset
- int xdo = in.readTTFUShort();
- // read y device table offset
- int ydo = in.readTTFUShort();
- // read x device table (if present)
- GlyphPositioningTable.DeviceTable xd;
- if (xdo != 0) {
- xd = readPosDeviceTable(cp, xdo);
- } else {
- xd = null;
- }
- // read y device table (if present)
- GlyphPositioningTable.DeviceTable yd;
- if (ydo != 0) {
- yd = readPosDeviceTable(cp, ydo);
- } else {
- yd = null;
- }
- a = new GlyphPositioningTable.Anchor(x, y, xd, yd);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported positioning anchor format: " + af);
- }
- in.seekSet(cp);
- return a;
- }
-
- private void readCursivePosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read entry/exit count
- int ec = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " cursive positioning subtable format: " + subtableFormat);
- log.debug(tableTag + " cursive positioning coverage table offset: " + co);
- log.debug(tableTag + " cursive positioning entry/exit count: " + ec);
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " cursive positioning coverage", subtableOffset + co);
- // read entry/exit records
- GlyphPositioningTable.Anchor[] aa = new GlyphPositioningTable.Anchor [ ec * 2 ];
- for (int i = 0, n = ec; i < n; i++) {
- // read entry anchor offset
- int eno = in.readTTFUShort();
- // read exit anchor offset
- int exo = in.readTTFUShort();
- // read entry anchor
- GlyphPositioningTable.Anchor ena;
- if (eno > 0) {
- ena = readPosAnchor(subtableOffset + eno);
- } else {
- ena = null;
- }
- // read exit anchor
- GlyphPositioningTable.Anchor exa;
- if (exo > 0) {
- exa = readPosAnchor(subtableOffset + exo);
- } else {
- exa = null;
- }
- aa [ (i * 2) + 0 ] = ena;
- aa [ (i * 2) + 1 ] = exa;
- if (log.isDebugEnabled()) {
- if (ena != null) {
- log.debug(tableTag + " cursive entry anchor [" + i + "]: " + ena);
- }
- if (exa != null) {
- log.debug(tableTag + " cursive exit anchor [" + i + "]: " + exa);
- }
- }
- }
- // store results
- seMapping = ct;
- seEntries.add(aa);
- }
-
- private int readCursivePosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readCursivePosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported cursive positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private void readMarkToBasePosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read mark coverage offset
- int mco = in.readTTFUShort();
- // read base coverage offset
- int bco = in.readTTFUShort();
- // read mark class count
- int nmc = in.readTTFUShort();
- // read mark array offset
- int mao = in.readTTFUShort();
- // read base array offset
- int bao = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-base positioning subtable format: " + subtableFormat);
- log.debug(tableTag + " mark-to-base positioning mark coverage table offset: " + mco);
- log.debug(tableTag + " mark-to-base positioning base coverage table offset: " + bco);
- log.debug(tableTag + " mark-to-base positioning mark class count: " + nmc);
- log.debug(tableTag + " mark-to-base positioning mark array offset: " + mao);
- log.debug(tableTag + " mark-to-base positioning base array offset: " + bao);
- }
- // read mark coverage table
- GlyphCoverageTable mct = readCoverageTable(tableTag + " mark-to-base positioning mark coverage", subtableOffset + mco);
- // read base coverage table
- GlyphCoverageTable bct = readCoverageTable(tableTag + " mark-to-base positioning base coverage", subtableOffset + bco);
- // read mark anchor array
- // seek to mark array
- in.seekSet(subtableOffset + mao);
- // read mark count
- int nm = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-base positioning mark count: " + nm);
- }
- // read mark anchor array, where i:{0...markCount}
- GlyphPositioningTable.MarkAnchor[] maa = new GlyphPositioningTable.MarkAnchor [ nm ];
- for (int i = 0; i < nm; i++) {
- // read mark class
- int mc = in.readTTFUShort();
- // read mark anchor offset
- int ao = in.readTTFUShort();
- GlyphPositioningTable.Anchor a;
- if (ao > 0) {
- a = readPosAnchor(subtableOffset + mao + ao);
- } else {
- a = null;
- }
- GlyphPositioningTable.MarkAnchor ma;
- if (a != null) {
- ma = new GlyphPositioningTable.MarkAnchor(mc, a);
- } else {
- ma = null;
- }
- maa [ i ] = ma;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-base positioning mark anchor[" + i + "]: " + ma);
- }
-
- }
- // read base anchor matrix
- // seek to base array
- in.seekSet(subtableOffset + bao);
- // read base count
- int nb = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-base positioning base count: " + nb);
- }
- // read anchor matrix, where i:{0...baseCount - 1}, j:{0...markClassCount - 1}
- GlyphPositioningTable.Anchor[][] bam = new GlyphPositioningTable.Anchor [ nb ] [ nmc ];
- for (int i = 0; i < nb; i++) {
- for (int j = 0; j < nmc; j++) {
- // read base anchor offset
- int ao = in.readTTFUShort();
- GlyphPositioningTable.Anchor a;
- if (ao > 0) {
- a = readPosAnchor(subtableOffset + bao + ao);
- } else {
- a = null;
- }
- bam [ i ] [ j ] = a;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-base positioning base anchor[" + i + "][" + j + "]: " + a);
- }
- }
- }
- // store results
- seMapping = mct;
- seEntries.add(bct);
- seEntries.add(nmc);
- seEntries.add(maa);
- seEntries.add(bam);
- }
-
- private int readMarkToBasePosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readMarkToBasePosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported mark-to-base positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private void readMarkToLigaturePosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read mark coverage offset
- int mco = in.readTTFUShort();
- // read ligature coverage offset
- int lco = in.readTTFUShort();
- // read mark class count
- int nmc = in.readTTFUShort();
- // read mark array offset
- int mao = in.readTTFUShort();
- // read ligature array offset
- int lao = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-ligature positioning subtable format: " + subtableFormat);
- log.debug(tableTag + " mark-to-ligature positioning mark coverage table offset: " + mco);
- log.debug(tableTag + " mark-to-ligature positioning ligature coverage table offset: " + lco);
- log.debug(tableTag + " mark-to-ligature positioning mark class count: " + nmc);
- log.debug(tableTag + " mark-to-ligature positioning mark array offset: " + mao);
- log.debug(tableTag + " mark-to-ligature positioning ligature array offset: " + lao);
- }
- // read mark coverage table
- GlyphCoverageTable mct = readCoverageTable(tableTag + " mark-to-ligature positioning mark coverage", subtableOffset + mco);
- // read ligature coverage table
- GlyphCoverageTable lct = readCoverageTable(tableTag + " mark-to-ligature positioning ligature coverage", subtableOffset + lco);
- // read mark anchor array
- // seek to mark array
- in.seekSet(subtableOffset + mao);
- // read mark count
- int nm = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-ligature positioning mark count: " + nm);
- }
- // read mark anchor array, where i:{0...markCount}
- GlyphPositioningTable.MarkAnchor[] maa = new GlyphPositioningTable.MarkAnchor [ nm ];
- for (int i = 0; i < nm; i++) {
- // read mark class
- int mc = in.readTTFUShort();
- // read mark anchor offset
- int ao = in.readTTFUShort();
- GlyphPositioningTable.Anchor a;
- if (ao > 0) {
- a = readPosAnchor(subtableOffset + mao + ao);
- } else {
- a = null;
- }
- GlyphPositioningTable.MarkAnchor ma;
- if (a != null) {
- ma = new GlyphPositioningTable.MarkAnchor(mc, a);
- } else {
- ma = null;
- }
- maa [ i ] = ma;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-ligature positioning mark anchor[" + i + "]: " + ma);
- }
- }
- // read ligature anchor matrix
- // seek to ligature array
- in.seekSet(subtableOffset + lao);
- // read ligature count
- int nl = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-ligature positioning ligature count: " + nl);
- }
- // read ligature attach table offsets
- int[] laoa = new int [ nl ];
- for (int i = 0; i < nl; i++) {
- laoa [ i ] = in.readTTFUShort();
- }
- // iterate over ligature attach tables, recording maximum component count
- int mxc = 0;
- for (int i = 0; i < nl; i++) {
- int lato = laoa [ i ];
- in.seekSet(subtableOffset + lao + lato);
- // read component count
- int cc = in.readTTFUShort();
- if (cc > mxc) {
- mxc = cc;
- }
- }
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-ligature positioning maximum component count: " + mxc);
- }
- // read anchor matrix, where i:{0...ligatureCount - 1}, j:{0...maxComponentCount - 1}, k:{0...markClassCount - 1}
- GlyphPositioningTable.Anchor[][][] lam = new GlyphPositioningTable.Anchor [ nl ][][];
- for (int i = 0; i < nl; i++) {
- int lato = laoa [ i ];
- // seek to ligature attach table for ligature[i]
- in.seekSet(subtableOffset + lao + lato);
- // read component count
- int cc = in.readTTFUShort();
- GlyphPositioningTable.Anchor[][] lcm = new GlyphPositioningTable.Anchor [ cc ] [ nmc ];
- for (int j = 0; j < cc; j++) {
- for (int k = 0; k < nmc; k++) {
- // read ligature anchor offset
- int ao = in.readTTFUShort();
- GlyphPositioningTable.Anchor a;
- if (ao > 0) {
- a = readPosAnchor(subtableOffset + lao + lato + ao);
- } else {
- a = null;
- }
- lcm [ j ] [ k ] = a;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-ligature positioning ligature anchor[" + i + "][" + j + "][" + k + "]: " + a);
- }
- }
- }
- lam [ i ] = lcm;
- }
- // store results
- seMapping = mct;
- seEntries.add(lct);
- seEntries.add(nmc);
- seEntries.add(mxc);
- seEntries.add(maa);
- seEntries.add(lam);
- }
-
- private int readMarkToLigaturePosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readMarkToLigaturePosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported mark-to-ligature positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private void readMarkToMarkPosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read mark #1 coverage offset
- int m1co = in.readTTFUShort();
- // read mark #2 coverage offset
- int m2co = in.readTTFUShort();
- // read mark class count
- int nmc = in.readTTFUShort();
- // read mark #1 array offset
- int m1ao = in.readTTFUShort();
- // read mark #2 array offset
- int m2ao = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-mark positioning subtable format: " + subtableFormat);
- log.debug(tableTag + " mark-to-mark positioning mark #1 coverage table offset: " + m1co);
- log.debug(tableTag + " mark-to-mark positioning mark #2 coverage table offset: " + m2co);
- log.debug(tableTag + " mark-to-mark positioning mark class count: " + nmc);
- log.debug(tableTag + " mark-to-mark positioning mark #1 array offset: " + m1ao);
- log.debug(tableTag + " mark-to-mark positioning mark #2 array offset: " + m2ao);
- }
- // read mark #1 coverage table
- GlyphCoverageTable mct1 = readCoverageTable(tableTag + " mark-to-mark positioning mark #1 coverage", subtableOffset + m1co);
- // read mark #2 coverage table
- GlyphCoverageTable mct2 = readCoverageTable(tableTag + " mark-to-mark positioning mark #2 coverage", subtableOffset + m2co);
- // read mark #1 anchor array
- // seek to mark array
- in.seekSet(subtableOffset + m1ao);
- // read mark count
- int nm1 = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-mark positioning mark #1 count: " + nm1);
- }
- // read mark anchor array, where i:{0...mark1Count}
- GlyphPositioningTable.MarkAnchor[] maa = new GlyphPositioningTable.MarkAnchor [ nm1 ];
- for (int i = 0; i < nm1; i++) {
- // read mark class
- int mc = in.readTTFUShort();
- // read mark anchor offset
- int ao = in.readTTFUShort();
- GlyphPositioningTable.Anchor a;
- if (ao > 0) {
- a = readPosAnchor(subtableOffset + m1ao + ao);
- } else {
- a = null;
- }
- GlyphPositioningTable.MarkAnchor ma;
- if (a != null) {
- ma = new GlyphPositioningTable.MarkAnchor(mc, a);
- } else {
- ma = null;
- }
- maa [ i ] = ma;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-mark positioning mark #1 anchor[" + i + "]: " + ma);
- }
- }
- // read mark #2 anchor matrix
- // seek to mark #2 array
- in.seekSet(subtableOffset + m2ao);
- // read mark #2 count
- int nm2 = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-mark positioning mark #2 count: " + nm2);
- }
- // read anchor matrix, where i:{0...mark2Count - 1}, j:{0...markClassCount - 1}
- GlyphPositioningTable.Anchor[][] mam = new GlyphPositioningTable.Anchor [ nm2 ] [ nmc ];
- for (int i = 0; i < nm2; i++) {
- for (int j = 0; j < nmc; j++) {
- // read mark anchor offset
- int ao = in.readTTFUShort();
- GlyphPositioningTable.Anchor a;
- if (ao > 0) {
- a = readPosAnchor(subtableOffset + m2ao + ao);
- } else {
- a = null;
- }
- mam [ i ] [ j ] = a;
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark-to-mark positioning mark #2 anchor[" + i + "][" + j + "]: " + a);
- }
- }
- }
- // store results
- seMapping = mct1;
- seEntries.add(mct2);
- seEntries.add(nmc);
- seEntries.add(maa);
- seEntries.add(mam);
- }
-
- private int readMarkToMarkPosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readMarkToMarkPosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported mark-to-mark positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private void readContextualPosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read rule set count
- int nrs = in.readTTFUShort();
- // read rule set offsets
- int[] rsoa = new int [ nrs ];
- for (int i = 0; i < nrs; i++) {
- rsoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " contextual positioning subtable format: " + subtableFormat + " (glyphs)");
- log.debug(tableTag + " contextual positioning coverage table offset: " + co);
- log.debug(tableTag + " contextual positioning rule set count: " + nrs);
- for (int i = 0; i < nrs; i++) {
- log.debug(tableTag + " contextual positioning rule set offset[" + i + "]: " + rsoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " contextual positioning coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ nrs ];
- String header = null;
- for (int i = 0; i < nrs; i++) {
- GlyphTable.RuleSet rs;
- int rso = rsoa [ i ];
- if (rso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + rso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- GlyphTable.GlyphSequenceRule r;
- int ro = roa [ j ];
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + rso + ro);
- // read glyph count
- int ng = in.readTTFUShort();
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read glyphs
- int[] glyphs = new int [ ng - 1 ];
- for (int k = 0, nk = glyphs.length; k < nk; k++) {
- glyphs [ k ] = in.readTTFUShort();
- }
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual positioning lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.GlyphSequenceRule(lookups, ng, glyphs);
- } else {
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(rsa);
- }
-
- private void readContextualPosTableFormat2(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read class def table offset
- int cdo = in.readTTFUShort();
- // read class rule set count
- int ngc = in.readTTFUShort();
- // read class rule set offsets
- int[] csoa = new int [ ngc ];
- for (int i = 0; i < ngc; i++) {
- csoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " contextual positioning subtable format: " + subtableFormat + " (glyph classes)");
- log.debug(tableTag + " contextual positioning coverage table offset: " + co);
- log.debug(tableTag + " contextual positioning class set count: " + ngc);
- for (int i = 0; i < ngc; i++) {
- log.debug(tableTag + " contextual positioning class set offset[" + i + "]: " + csoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " contextual positioning coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read class definition table
- GlyphClassTable cdt;
- if (cdo > 0) {
- cdt = readClassDefTable(tableTag + " contextual positioning class definition", subtableOffset + cdo);
- } else {
- cdt = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ ngc ];
- String header = null;
- for (int i = 0; i < ngc; i++) {
- int cso = csoa [ i ];
- GlyphTable.RuleSet rs;
- if (cso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + cso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- int ro = roa [ j ];
- GlyphTable.ClassSequenceRule r;
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + cso + ro);
- // read glyph count
- int ng = in.readTTFUShort();
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read classes
- int[] classes = new int [ ng - 1 ];
- for (int k = 0, nk = classes.length; k < nk; k++) {
- classes [ k ] = in.readTTFUShort();
- }
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual positioning lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.ClassSequenceRule(lookups, ng, classes);
- } else {
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(cdt);
- seEntries.add(ngc);
- seEntries.add(rsa);
- }
-
- private void readContextualPosTableFormat3(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read glyph (input sequence length) count
- int ng = in.readTTFUShort();
- // read positioning lookup count
- int nl = in.readTTFUShort();
- // read glyph coverage offsets, one per glyph input sequence length count
- int[] gcoa = new int [ ng ];
- for (int i = 0; i < ng; i++) {
- gcoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " contextual positioning subtable format: " + subtableFormat + " (glyph sets)");
- log.debug(tableTag + " contextual positioning glyph input sequence length count: " + ng);
- log.debug(tableTag + " contextual positioning lookup count: " + nl);
- for (int i = 0; i < ng; i++) {
- log.debug(tableTag + " contextual positioning coverage table offset[" + i + "]: " + gcoa[i]);
- }
- }
- // read coverage tables
- GlyphCoverageTable[] gca = new GlyphCoverageTable [ ng ];
- for (int i = 0; i < ng; i++) {
- int gco = gcoa [ i ];
- GlyphCoverageTable gct;
- if (gco > 0) {
- gct = readCoverageTable(tableTag + " contextual positioning coverage[" + i + "]", subtableOffset + gcoa[i]);
- } else {
- gct = null;
- }
- gca [ i ] = gct;
- }
- // read rule lookups
- String header = null;
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual positioning lookups: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- // construct rule, rule set, and rule set array
- GlyphTable.Rule r = new GlyphTable.CoverageSequenceRule(lookups, ng, gca);
- GlyphTable.RuleSet rs = new GlyphTable.HomogeneousRuleSet(new GlyphTable.Rule[] {r});
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet[] {rs};
- // store results
- assert (gca != null) && (gca.length > 0);
- seMapping = gca[0];
- seEntries.add(rsa);
- }
-
- private int readContextualPosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readContextualPosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 2) {
- readContextualPosTableFormat2(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 3) {
- readContextualPosTableFormat3(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported contextual positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private void readChainedContextualPosTableFormat1(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read rule set count
- int nrs = in.readTTFUShort();
- // read rule set offsets
- int[] rsoa = new int [ nrs ];
- for (int i = 0; i < nrs; i++) {
- rsoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " chained contextual positioning subtable format: " + subtableFormat + " (glyphs)");
- log.debug(tableTag + " chained contextual positioning coverage table offset: " + co);
- log.debug(tableTag + " chained contextual positioning rule set count: " + nrs);
- for (int i = 0; i < nrs; i++) {
- log.debug(tableTag + " chained contextual positioning rule set offset[" + i + "]: " + rsoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " chained contextual positioning coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ nrs ];
- String header = null;
- for (int i = 0; i < nrs; i++) {
- GlyphTable.RuleSet rs;
- int rso = rsoa [ i ];
- if (rso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + rso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- GlyphTable.ChainedGlyphSequenceRule r;
- int ro = roa [ j ];
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + rso + ro);
- // read backtrack glyph count
- int nbg = in.readTTFUShort();
- // read backtrack glyphs
- int[] backtrackGlyphs = new int [ nbg ];
- for (int k = 0, nk = backtrackGlyphs.length; k < nk; k++) {
- backtrackGlyphs [ k ] = in.readTTFUShort();
- }
- // read input glyph count
- int nig = in.readTTFUShort();
- // read glyphs
- int[] glyphs = new int [ nig - 1 ];
- for (int k = 0, nk = glyphs.length; k < nk; k++) {
- glyphs [ k ] = in.readTTFUShort();
- }
- // read lookahead glyph count
- int nlg = in.readTTFUShort();
- // read lookahead glyphs
- int[] lookaheadGlyphs = new int [ nlg ];
- for (int k = 0, nk = lookaheadGlyphs.length; k < nk; k++) {
- lookaheadGlyphs [ k ] = in.readTTFUShort();
- }
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual positioning lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.ChainedGlyphSequenceRule(lookups, nig, glyphs, backtrackGlyphs, lookaheadGlyphs);
- } else {
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(rsa);
- }
-
- private void readChainedContextualPosTableFormat2(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read coverage offset
- int co = in.readTTFUShort();
- // read backtrack class def table offset
- int bcdo = in.readTTFUShort();
- // read input class def table offset
- int icdo = in.readTTFUShort();
- // read lookahead class def table offset
- int lcdo = in.readTTFUShort();
- // read class set count
- int ngc = in.readTTFUShort();
- // read class set offsets
- int[] csoa = new int [ ngc ];
- for (int i = 0; i < ngc; i++) {
- csoa [ i ] = in.readTTFUShort();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " chained contextual positioning subtable format: " + subtableFormat + " (glyph classes)");
- log.debug(tableTag + " chained contextual positioning coverage table offset: " + co);
- log.debug(tableTag + " chained contextual positioning class set count: " + ngc);
- for (int i = 0; i < ngc; i++) {
- log.debug(tableTag + " chained contextual positioning class set offset[" + i + "]: " + csoa[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct;
- if (co > 0) {
- ct = readCoverageTable(tableTag + " chained contextual positioning coverage", subtableOffset + co);
- } else {
- ct = null;
- }
- // read backtrack class definition table
- GlyphClassTable bcdt;
- if (bcdo > 0) {
- bcdt = readClassDefTable(tableTag + " contextual positioning backtrack class definition", subtableOffset + bcdo);
- } else {
- bcdt = null;
- }
- // read input class definition table
- GlyphClassTable icdt;
- if (icdo > 0) {
- icdt = readClassDefTable(tableTag + " contextual positioning input class definition", subtableOffset + icdo);
- } else {
- icdt = null;
- }
- // read lookahead class definition table
- GlyphClassTable lcdt;
- if (lcdo > 0) {
- lcdt = readClassDefTable(tableTag + " contextual positioning lookahead class definition", subtableOffset + lcdo);
- } else {
- lcdt = null;
- }
- // read rule sets
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet [ ngc ];
- String header = null;
- for (int i = 0; i < ngc; i++) {
- int cso = csoa [ i ];
- GlyphTable.RuleSet rs;
- if (cso > 0) {
- // seek to rule set [ i ]
- in.seekSet(subtableOffset + cso);
- // read rule count
- int nr = in.readTTFUShort();
- // read rule offsets
- int[] roa = new int [ nr ];
- GlyphTable.Rule[] ra = new GlyphTable.Rule [ nr ];
- for (int j = 0; j < nr; j++) {
- roa [ j ] = in.readTTFUShort();
- }
- // read glyph sequence rules
- for (int j = 0; j < nr; j++) {
- GlyphTable.ChainedClassSequenceRule r;
- int ro = roa [ j ];
- if (ro > 0) {
- // seek to rule [ j ]
- in.seekSet(subtableOffset + cso + ro);
- // read backtrack glyph class count
- int nbc = in.readTTFUShort();
- // read backtrack glyph classes
- int[] backtrackClasses = new int [ nbc ];
- for (int k = 0, nk = backtrackClasses.length; k < nk; k++) {
- backtrackClasses [ k ] = in.readTTFUShort();
- }
- // read input glyph class count
- int nic = in.readTTFUShort();
- // read input glyph classes
- int[] classes = new int [ nic - 1 ];
- for (int k = 0, nk = classes.length; k < nk; k++) {
- classes [ k ] = in.readTTFUShort();
- }
- // read lookahead glyph class count
- int nlc = in.readTTFUShort();
- // read lookahead glyph classes
- int[] lookaheadClasses = new int [ nlc ];
- for (int k = 0, nk = lookaheadClasses.length; k < nk; k++) {
- lookaheadClasses [ k ] = in.readTTFUShort();
- }
- // read rule lookup count
- int nl = in.readTTFUShort();
- // read rule lookups
- if (log.isDebugEnabled()) {
- header = tableTag + " contextual positioning lookups @rule[" + i + "][" + j + "]: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- r = new GlyphTable.ChainedClassSequenceRule(lookups, nic, classes, backtrackClasses, lookaheadClasses);
- } else {
- r = null;
- }
- ra [ j ] = r;
- }
- rs = new GlyphTable.HomogeneousRuleSet(ra);
- } else {
- rs = null;
- }
- rsa [ i ] = rs;
- }
- // store results
- seMapping = ct;
- seEntries.add(icdt);
- seEntries.add(bcdt);
- seEntries.add(lcdt);
- seEntries.add(ngc);
- seEntries.add(rsa);
- }
-
- private void readChainedContextualPosTableFormat3(int lookupType, int lookupFlags, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read backtrack glyph count
- int nbg = in.readTTFUShort();
- // read backtrack glyph coverage offsets
- int[] bgcoa = new int [ nbg ];
- for (int i = 0; i < nbg; i++) {
- bgcoa [ i ] = in.readTTFUShort();
- }
- // read input glyph count
- int nig = in.readTTFUShort();
- // read backtrack glyph coverage offsets
- int[] igcoa = new int [ nig ];
- for (int i = 0; i < nig; i++) {
- igcoa [ i ] = in.readTTFUShort();
- }
- // read lookahead glyph count
- int nlg = in.readTTFUShort();
- // read backtrack glyph coverage offsets
- int[] lgcoa = new int [ nlg ];
- for (int i = 0; i < nlg; i++) {
- lgcoa [ i ] = in.readTTFUShort();
- }
- // read positioning lookup count
- int nl = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " chained contextual positioning subtable format: " + subtableFormat + " (glyph sets)");
- log.debug(tableTag + " chained contextual positioning backtrack glyph count: " + nbg);
- for (int i = 0; i < nbg; i++) {
- log.debug(tableTag + " chained contextual positioning backtrack coverage table offset[" + i + "]: " + bgcoa[i]);
- }
- log.debug(tableTag + " chained contextual positioning input glyph count: " + nig);
- for (int i = 0; i < nig; i++) {
- log.debug(tableTag + " chained contextual positioning input coverage table offset[" + i + "]: " + igcoa[i]);
- }
- log.debug(tableTag + " chained contextual positioning lookahead glyph count: " + nlg);
- for (int i = 0; i < nlg; i++) {
- log.debug(tableTag + " chained contextual positioning lookahead coverage table offset[" + i + "]: " + lgcoa[i]);
- }
- log.debug(tableTag + " chained contextual positioning lookup count: " + nl);
- }
- // read backtrack coverage tables
- GlyphCoverageTable[] bgca = new GlyphCoverageTable[nbg];
- for (int i = 0; i < nbg; i++) {
- int bgco = bgcoa [ i ];
- GlyphCoverageTable bgct;
- if (bgco > 0) {
- bgct = readCoverageTable(tableTag + " chained contextual positioning backtrack coverage[" + i + "]", subtableOffset + bgco);
- } else {
- bgct = null;
- }
- bgca[i] = bgct;
- }
- // read input coverage tables
- GlyphCoverageTable[] igca = new GlyphCoverageTable[nig];
- for (int i = 0; i < nig; i++) {
- int igco = igcoa [ i ];
- GlyphCoverageTable igct;
- if (igco > 0) {
- igct = readCoverageTable(tableTag + " chained contextual positioning input coverage[" + i + "]", subtableOffset + igco);
- } else {
- igct = null;
- }
- igca[i] = igct;
- }
- // read lookahead coverage tables
- GlyphCoverageTable[] lgca = new GlyphCoverageTable[nlg];
- for (int i = 0; i < nlg; i++) {
- int lgco = lgcoa [ i ];
- GlyphCoverageTable lgct;
- if (lgco > 0) {
- lgct = readCoverageTable(tableTag + " chained contextual positioning lookahead coverage[" + i + "]", subtableOffset + lgco);
- } else {
- lgct = null;
- }
- lgca[i] = lgct;
- }
- // read rule lookups
- String header = null;
- if (log.isDebugEnabled()) {
- header = tableTag + " chained contextual positioning lookups: ";
- }
- GlyphTable.RuleLookup[] lookups = readRuleLookups(nl, header);
- // construct rule, rule set, and rule set array
- GlyphTable.Rule r = new GlyphTable.ChainedCoverageSequenceRule(lookups, nig, igca, bgca, lgca);
- GlyphTable.RuleSet rs = new GlyphTable.HomogeneousRuleSet(new GlyphTable.Rule[] {r});
- GlyphTable.RuleSet[] rsa = new GlyphTable.RuleSet[] {rs};
- // store results
- assert (igca != null) && (igca.length > 0);
- seMapping = igca[0];
- seEntries.add(rsa);
- }
-
- private int readChainedContextualPosTable(int lookupType, int lookupFlags, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readChainedContextualPosTableFormat1(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 2) {
- readChainedContextualPosTableFormat2(lookupType, lookupFlags, subtableOffset, sf);
- } else if (sf == 3) {
- readChainedContextualPosTableFormat3(lookupType, lookupFlags, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported chained contextual positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private void readExtensionPosTableFormat1(int lookupType, int lookupFlags, int lookupSequence, int subtableSequence, long subtableOffset, int subtableFormat) throws IOException {
- String tableTag = "GPOS";
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read extension lookup type
- int lt = in.readTTFUShort();
- // read extension offset
- long eo = in.readTTFULong();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " extension positioning subtable format: " + subtableFormat);
- log.debug(tableTag + " extension positioning lookup type: " + lt);
- log.debug(tableTag + " extension positioning lookup table offset: " + eo);
- }
- // read referenced subtable from extended offset
- readGPOSSubtable(lt, lookupFlags, lookupSequence, subtableSequence, subtableOffset + eo);
- }
-
- private int readExtensionPosTable(int lookupType, int lookupFlags, int lookupSequence, int subtableSequence, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read positioning subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readExtensionPosTableFormat1(lookupType, lookupFlags, lookupSequence, subtableSequence, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported extension positioning subtable format: " + sf);
- }
- return sf;
- }
-
- private void readGPOSSubtable(int lookupType, int lookupFlags, int lookupSequence, int subtableSequence, long subtableOffset) throws IOException {
- initATSubState();
- int subtableFormat = -1;
- switch (lookupType) {
- case GPOSLookupType.SINGLE:
- subtableFormat = readSinglePosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.PAIR:
- subtableFormat = readPairPosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.CURSIVE:
- subtableFormat = readCursivePosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.MARK_TO_BASE:
- subtableFormat = readMarkToBasePosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.MARK_TO_LIGATURE:
- subtableFormat = readMarkToLigaturePosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.MARK_TO_MARK:
- subtableFormat = readMarkToMarkPosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.CONTEXTUAL:
- subtableFormat = readContextualPosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.CHAINED_CONTEXTUAL:
- subtableFormat = readChainedContextualPosTable(lookupType, lookupFlags, subtableOffset);
- break;
- case GPOSLookupType.EXTENSION:
- subtableFormat = readExtensionPosTable(lookupType, lookupFlags, lookupSequence, subtableSequence, subtableOffset);
- break;
- default:
- break;
- }
- extractSESubState(GlyphTable.GLYPH_TABLE_TYPE_POSITIONING, lookupType, lookupFlags, lookupSequence, subtableSequence, subtableFormat);
- resetATSubState();
- }
-
- private void readLookupTable(OFTableName tableTag, int lookupSequence, long lookupTable) throws IOException {
- boolean isGSUB = tableTag.equals(OFTableName.GSUB);
- boolean isGPOS = tableTag.equals(OFTableName.GPOS);
- in.seekSet(lookupTable);
- // read lookup type
- int lt = in.readTTFUShort();
- // read lookup flags
- int lf = in.readTTFUShort();
- // read sub-table count
- int ns = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- String lts;
- if (isGSUB) {
- lts = GSUBLookupType.toString(lt);
- } else if (isGPOS) {
- lts = GPOSLookupType.toString(lt);
- } else {
- lts = "?";
- }
- log.debug(tableTag + " lookup table type: " + lt + " (" + lts + ")");
- log.debug(tableTag + " lookup table flags: " + lf + " (" + LookupFlag.toString(lf) + ")");
- log.debug(tableTag + " lookup table subtable count: " + ns);
- }
- // read subtable offsets
- int[] soa = new int[ns];
- for (int i = 0; i < ns; i++) {
- int so = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lookup table subtable offset: " + so);
- }
- soa[i] = so;
- }
- // read mark filtering set
- if ((lf & LookupFlag.USE_MARK_FILTERING_SET) != 0) {
- // read mark filtering set
- int fs = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lookup table mark filter set: " + fs);
- }
- }
- // read subtables
- for (int i = 0; i < ns; i++) {
- int so = soa[i];
- if (isGSUB) {
- readGSUBSubtable(lt, lf, lookupSequence, i, lookupTable + so);
- } else if (isGPOS) {
- readGPOSSubtable(lt, lf, lookupSequence, i, lookupTable + so);
- }
- }
- }
-
- private void readLookupList(OFTableName tableTag, long lookupList) throws IOException {
- in.seekSet(lookupList);
- // read lookup record count
- int nl = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lookup list record count: " + nl);
- }
- if (nl > 0) {
- int[] loa = new int[nl];
- // read lookup records
- for (int i = 0, n = nl; i < n; i++) {
- int lo = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lookup table offset: " + lo);
- }
- loa[i] = lo;
- }
- // read lookup tables
- for (int i = 0, n = nl; i < n; i++) {
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " lookup index: " + i);
- }
- readLookupTable(tableTag, i, lookupList + loa [ i ]);
- }
- }
- }
-
- /**
- * Read the common layout tables (used by GSUB and GPOS).
- * @param tableTag tag of table being read
- * @param scriptList offset to script list from beginning of font file
- * @param featureList offset to feature list from beginning of font file
- * @param lookupList offset to lookup list from beginning of font file
- * @throws IOException In case of a I/O problem
- */
- private void readCommonLayoutTables(OFTableName tableTag, long scriptList, long featureList, long lookupList) throws IOException {
- if (scriptList > 0) {
- readScriptList(tableTag, scriptList);
- }
- if (featureList > 0) {
- readFeatureList(tableTag, featureList);
- }
- if (lookupList > 0) {
- readLookupList(tableTag, lookupList);
- }
- }
-
- private void readGDEFClassDefTable(OFTableName tableTag, int lookupSequence, long subtableOffset) throws IOException {
- initATSubState();
- in.seekSet(subtableOffset);
- // subtable is a bare class definition table
- GlyphClassTable ct = readClassDefTable(tableTag + " glyph class definition table", subtableOffset);
- // store results
- seMapping = ct;
- // extract subtable
- extractSESubState(GlyphTable.GLYPH_TABLE_TYPE_DEFINITION, GDEFLookupType.GLYPH_CLASS, 0, lookupSequence, 0, 1);
- resetATSubState();
- }
-
- private void readGDEFAttachmentTable(OFTableName tableTag, int lookupSequence, long subtableOffset) throws IOException {
- initATSubState();
- in.seekSet(subtableOffset);
- // read coverage offset
- int co = in.readTTFUShort();
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " attachment point coverage table offset: " + co);
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " attachment point coverage", subtableOffset + co);
- // store results
- seMapping = ct;
- // extract subtable
- extractSESubState(GlyphTable.GLYPH_TABLE_TYPE_DEFINITION, GDEFLookupType.ATTACHMENT_POINT, 0, lookupSequence, 0, 1);
- resetATSubState();
- }
-
- private void readGDEFLigatureCaretTable(OFTableName tableTag, int lookupSequence, long subtableOffset) throws IOException {
- initATSubState();
- in.seekSet(subtableOffset);
- // read coverage offset
- int co = in.readTTFUShort();
- // read ligature glyph count
- int nl = in.readTTFUShort();
- // read ligature glyph table offsets
- int[] lgto = new int [ nl ];
- for (int i = 0; i < nl; i++) {
- lgto [ i ] = in.readTTFUShort();
- }
-
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " ligature caret coverage table offset: " + co);
- log.debug(tableTag + " ligature caret ligature glyph count: " + nl);
- for (int i = 0; i < nl; i++) {
- log.debug(tableTag + " ligature glyph table offset[" + i + "]: " + lgto[i]);
- }
- }
- // read coverage table
- GlyphCoverageTable ct = readCoverageTable(tableTag + " ligature caret coverage", subtableOffset + co);
- // store results
- seMapping = ct;
- // extract subtable
- extractSESubState(GlyphTable.GLYPH_TABLE_TYPE_DEFINITION, GDEFLookupType.LIGATURE_CARET, 0, lookupSequence, 0, 1);
- resetATSubState();
- }
-
- private void readGDEFMarkAttachmentTable(OFTableName tableTag, int lookupSequence, long subtableOffset) throws IOException {
- initATSubState();
- in.seekSet(subtableOffset);
- // subtable is a bare class definition table
- GlyphClassTable ct = readClassDefTable(tableTag + " glyph class definition table", subtableOffset);
- // store results
- seMapping = ct;
- // extract subtable
- extractSESubState(GlyphTable.GLYPH_TABLE_TYPE_DEFINITION, GDEFLookupType.MARK_ATTACHMENT, 0, lookupSequence, 0, 1);
- resetATSubState();
- }
-
- private void readGDEFMarkGlyphsTableFormat1(OFTableName tableTag, int lookupSequence, long subtableOffset, int subtableFormat) throws IOException {
- initATSubState();
- in.seekSet(subtableOffset);
- // skip over format (already known)
- in.skip(2);
- // read mark set class count
- int nmc = in.readTTFUShort();
- long[] mso = new long [ nmc ];
- // read mark set coverage offsets
- for (int i = 0; i < nmc; i++) {
- mso [ i ] = in.readTTFULong();
- }
- // dump info if debugging
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " mark set subtable format: " + subtableFormat + " (glyph sets)");
- log.debug(tableTag + " mark set class count: " + nmc);
- for (int i = 0; i < nmc; i++) {
- log.debug(tableTag + " mark set coverage table offset[" + i + "]: " + mso[i]);
- }
- }
- // read mark set coverage tables, one per class
- GlyphCoverageTable[] msca = new GlyphCoverageTable[nmc];
- for (int i = 0; i < nmc; i++) {
- msca[i] = readCoverageTable(tableTag + " mark set coverage[" + i + "]", subtableOffset + mso[i]);
- }
- // create combined class table from per-class coverage tables
- GlyphClassTable ct = GlyphClassTable.createClassTable(Arrays.asList(msca));
- // store results
- seMapping = ct;
- // extract subtable
- extractSESubState(GlyphTable.GLYPH_TABLE_TYPE_DEFINITION, GDEFLookupType.MARK_ATTACHMENT, 0, lookupSequence, 0, 1);
- resetATSubState();
- }
-
- private void readGDEFMarkGlyphsTable(OFTableName tableTag, int lookupSequence, long subtableOffset) throws IOException {
- in.seekSet(subtableOffset);
- // read mark set subtable format
- int sf = in.readTTFUShort();
- if (sf == 1) {
- readGDEFMarkGlyphsTableFormat1(tableTag, lookupSequence, subtableOffset, sf);
- } else {
- throw new AdvancedTypographicTableFormatException("unsupported mark glyph sets subtable format: " + sf);
- }
- }
-
- /**
- * Read the GDEF table.
- * @throws IOException In case of a I/O problem
- */
- private void readGDEF() throws IOException {
- OFTableName tableTag = OFTableName.GDEF;
- // Initialize temporary state
- initATState();
- // Read glyph definition (GDEF) table
- OFDirTabEntry dirTab = otf.getDirectoryEntry(tableTag);
- if (gdef != null) {
- if (log.isDebugEnabled()) {
- log.debug(tableTag + ": ignoring duplicate table");
- }
- } else if (dirTab != null) {
- otf.seekTab(in, tableTag, 0);
- long version = in.readTTFULong();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " version: " + (version / 65536) + "." + (version % 65536));
- }
- // glyph class definition table offset (may be null)
- int cdo = in.readTTFUShort();
- // attach point list offset (may be null)
- int apo = in.readTTFUShort();
- // ligature caret list offset (may be null)
- int lco = in.readTTFUShort();
- // mark attach class definition table offset (may be null)
- int mao = in.readTTFUShort();
- // mark glyph sets definition table offset (may be null)
- int mgo;
- if (version >= 0x00010002) {
- mgo = in.readTTFUShort();
- } else {
- mgo = 0;
- }
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " glyph class definition table offset: " + cdo);
- log.debug(tableTag + " attachment point list offset: " + apo);
- log.debug(tableTag + " ligature caret list offset: " + lco);
- log.debug(tableTag + " mark attachment class definition table offset: " + mao);
- log.debug(tableTag + " mark glyph set definitions table offset: " + mgo);
- }
- // initialize subtable sequence number
- int seqno = 0;
- // obtain offset to start of gdef table
- long to = dirTab.getOffset();
- // (optionally) read glyph class definition subtable
- if (cdo != 0) {
- readGDEFClassDefTable(tableTag, seqno++, to + cdo);
- }
- // (optionally) read glyph attachment point subtable
- if (apo != 0) {
- readGDEFAttachmentTable(tableTag, seqno++, to + apo);
- }
- // (optionally) read ligature caret subtable
- if (lco != 0) {
- readGDEFLigatureCaretTable(tableTag, seqno++, to + lco);
- }
- // (optionally) read mark attachment class subtable
- if (mao != 0) {
- readGDEFMarkAttachmentTable(tableTag, seqno++, to + mao);
- }
- // (optionally) read mark glyph sets subtable
- if (mgo != 0) {
- readGDEFMarkGlyphsTable(tableTag, seqno++, to + mgo);
- }
- GlyphDefinitionTable gdef;
- if ((gdef = constructGDEF()) != null) {
- this.gdef = gdef;
- }
- }
- }
-
- /**
- * Read the GSUB table.
- * @throws IOException In case of a I/O problem
- */
- private void readGSUB() throws IOException {
- OFTableName tableTag = OFTableName.GSUB;
- // Initialize temporary state
- initATState();
- // Read glyph substitution (GSUB) table
- OFDirTabEntry dirTab = otf.getDirectoryEntry(tableTag);
- if (gpos != null) {
- if (log.isDebugEnabled()) {
- log.debug(tableTag + ": ignoring duplicate table");
- }
- } else if (dirTab != null) {
- otf.seekTab(in, tableTag, 0);
- int version = in.readTTFLong();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " version: " + (version / 65536) + "." + (version % 65536));
- }
- int slo = in.readTTFUShort();
- int flo = in.readTTFUShort();
- int llo = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " script list offset: " + slo);
- log.debug(tableTag + " feature list offset: " + flo);
- log.debug(tableTag + " lookup list offset: " + llo);
- }
- long to = dirTab.getOffset();
- readCommonLayoutTables(tableTag, to + slo, to + flo, to + llo);
- GlyphSubstitutionTable gsub;
- if ((gsub = constructGSUB()) != null) {
- this.gsub = gsub;
- }
- }
- }
-
- /**
- * Read the GPOS table.
- * @throws IOException In case of a I/O problem
- */
- private void readGPOS() throws IOException {
- OFTableName tableTag = OFTableName.GPOS;
- // Initialize temporary state
- initATState();
- // Read glyph positioning (GPOS) table
- OFDirTabEntry dirTab = otf.getDirectoryEntry(tableTag);
- if (gpos != null) {
- if (log.isDebugEnabled()) {
- log.debug(tableTag + ": ignoring duplicate table");
- }
- } else if (dirTab != null) {
- otf.seekTab(in, tableTag, 0);
- int version = in.readTTFLong();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " version: " + (version / 65536) + "." + (version % 65536));
- }
- int slo = in.readTTFUShort();
- int flo = in.readTTFUShort();
- int llo = in.readTTFUShort();
- if (log.isDebugEnabled()) {
- log.debug(tableTag + " script list offset: " + slo);
- log.debug(tableTag + " feature list offset: " + flo);
- log.debug(tableTag + " lookup list offset: " + llo);
- }
- long to = dirTab.getOffset();
- readCommonLayoutTables(tableTag, to + slo, to + flo, to + llo);
- GlyphPositioningTable gpos;
- if ((gpos = constructGPOS()) != null) {
- this.gpos = gpos;
- }
- }
- }
-
- /**
- * Construct the (internal representation of the) GDEF table based on previously
- * parsed state.
- * @returns glyph definition table or null if insufficient or invalid state
- */
- private GlyphDefinitionTable constructGDEF() {
- GlyphDefinitionTable gdef = null;
- List subtables;
- if ((subtables = constructGDEFSubtables()) != null) {
- if (subtables.size() > 0) {
- gdef = new GlyphDefinitionTable(subtables, processors);
- }
- }
- resetATState();
- return gdef;
- }
-
- /**
- * Construct the (internal representation of the) GSUB table based on previously
- * parsed state.
- * @returns glyph substitution table or null if insufficient or invalid state
- */
- private GlyphSubstitutionTable constructGSUB() {
- GlyphSubstitutionTable gsub = null;
- Map lookups;
- if ((lookups = constructLookups()) != null) {
- List subtables;
- if ((subtables = constructGSUBSubtables()) != null) {
- if ((lookups.size() > 0) && (subtables.size() > 0)) {
- gsub = new GlyphSubstitutionTable(gdef, lookups, subtables, processors);
- }
- }
- }
- resetATState();
- return gsub;
- }
-
- /**
- * Construct the (internal representation of the) GPOS table based on previously
- * parsed state.
- * @returns glyph positioning table or null if insufficient or invalid state
- */
- private GlyphPositioningTable constructGPOS() {
- GlyphPositioningTable gpos = null;
- Map lookups;
- if ((lookups = constructLookups()) != null) {
- List subtables;
- if ((subtables = constructGPOSSubtables()) != null) {
- if ((lookups.size() > 0) && (subtables.size() > 0)) {
- gpos = new GlyphPositioningTable(gdef, lookups, subtables, processors);
- }
- }
- }
- resetATState();
- return gpos;
- }
-
- private void constructLookupsFeature(Map lookups, String st, String lt, String fid) {
- Object[] fp = (Object[]) seFeatures.get(fid);
- if (fp != null) {
- assert fp.length == 2;
- String ft = (String) fp[0]; // feature tag
- List<String> lul = (List) fp[1]; // list of lookup table ids
- if ((ft != null) && (lul != null) && (lul.size() > 0)) {
- GlyphTable.LookupSpec ls = new GlyphTable.LookupSpec(st, lt, ft);
- lookups.put(ls, lul);
- }
- }
- }
-
- private void constructLookupsFeatures(Map lookups, String st, String lt, List<String> fids) {
- for (Object fid1 : fids) {
- String fid = (String) fid1;
- constructLookupsFeature(lookups, st, lt, fid);
- }
- }
-
- private void constructLookupsLanguage(Map lookups, String st, String lt, Map<String, Object> languages) {
- Object[] lp = (Object[]) languages.get(lt);
- if (lp != null) {
- assert lp.length == 2;
- if (lp[0] != null) { // required feature id
- constructLookupsFeature(lookups, st, lt, (String) lp[0]);
- }
- if (lp[1] != null) { // non-required features ids
- constructLookupsFeatures(lookups, st, lt, (List) lp[1]);
- }
- }
- }
-
- private void constructLookupsLanguages(Map lookups, String st, List<String> ll, Map<String, Object> languages) {
- for (Object aLl : ll) {
- String lt = (String) aLl;
- constructLookupsLanguage(lookups, st, lt, languages);
- }
- }
-
- private Map constructLookups() {
- Map<GlyphTable.LookupSpec, List<String>> lookups = new java.util.LinkedHashMap();
- for (Object o : seScripts.keySet()) {
- String st = (String) o;
- Object[] sp = (Object[]) seScripts.get(st);
- if (sp != null) {
- assert sp.length == 3;
- Map<String, Object> languages = (Map) sp[2];
- if (sp[0] != null) { // default language
- constructLookupsLanguage(lookups, st, (String) sp[0], languages);
- }
- if (sp[1] != null) { // non-default languages
- constructLookupsLanguages(lookups, st, (List) sp[1], languages);
- }
- }
- }
- return lookups;
- }
-
- private List constructGDEFSubtables() {
- List<GlyphSubtable> subtables = new java.util.ArrayList();
- if (seSubtables != null) {
- for (Object seSubtable : seSubtables) {
- Object[] stp = (Object[]) seSubtable;
- GlyphSubtable st;
- if ((st = constructGDEFSubtable(stp)) != null) {
- subtables.add(st);
- }
- }
- }
- return subtables;
- }
-
- private GlyphSubtable constructGDEFSubtable(Object[] stp) {
- GlyphSubtable st = null;
- assert (stp != null) && (stp.length == 8);
- Integer tt = (Integer) stp[0]; // table type
- Integer lt = (Integer) stp[1]; // lookup type
- Integer ln = (Integer) stp[2]; // lookup sequence number
- Integer lf = (Integer) stp[3]; // lookup flags
- Integer sn = (Integer) stp[4]; // subtable sequence number
- Integer sf = (Integer) stp[5]; // subtable format
- GlyphMappingTable mapping = (GlyphMappingTable) stp[6];
- List entries = (List) stp[7];
- if (tt == GlyphTable.GLYPH_TABLE_TYPE_DEFINITION) {
- int type = GDEFLookupType.getSubtableType(lt);
- String lid = "lu" + ln;
- int sequence = sn;
- int flags = lf;
- int format = sf;
- st = GlyphDefinitionTable.createSubtable(type, lid, sequence, flags, format, mapping, entries);
- }
- return st;
- }
-
- private List constructGSUBSubtables() {
- List<GlyphSubtable> subtables = new java.util.ArrayList();
- if (seSubtables != null) {
- for (Object seSubtable : seSubtables) {
- Object[] stp = (Object[]) seSubtable;
- GlyphSubtable st;
- if ((st = constructGSUBSubtable(stp)) != null) {
- subtables.add(st);
- }
- }
- }
- return subtables;
- }
-
- private GlyphSubtable constructGSUBSubtable(Object[] stp) {
- GlyphSubtable st = null;
- assert (stp != null) && (stp.length == 8);
- Integer tt = (Integer) stp[0]; // table type
- Integer lt = (Integer) stp[1]; // lookup type
- Integer ln = (Integer) stp[2]; // lookup sequence number
- Integer lf = (Integer) stp[3]; // lookup flags
- Integer sn = (Integer) stp[4]; // subtable sequence number
- Integer sf = (Integer) stp[5]; // subtable format
- GlyphCoverageTable coverage = (GlyphCoverageTable) stp[6];
- List entries = (List) stp[7];
- if (tt == GlyphTable.GLYPH_TABLE_TYPE_SUBSTITUTION) {
- int type = GSUBLookupType.getSubtableType(lt);
- String lid = "lu" + ln;
- int sequence = sn;
- int flags = lf;
- int format = sf;
- st = GlyphSubstitutionTable.createSubtable(type, lid, sequence, flags, format, coverage, entries);
- }
- return st;
- }
-
- private List constructGPOSSubtables() {
- List<GlyphSubtable> subtables = new java.util.ArrayList();
- if (seSubtables != null) {
- for (Object seSubtable : seSubtables) {
- Object[] stp = (Object[]) seSubtable;
- GlyphSubtable st;
- if ((st = constructGPOSSubtable(stp)) != null) {
- subtables.add(st);
- }
- }
- }
- return subtables;
- }
-
- private GlyphSubtable constructGPOSSubtable(Object[] stp) {
- GlyphSubtable st = null;
- assert (stp != null) && (stp.length == 8);
- Integer tt = (Integer) stp[0]; // table type
- Integer lt = (Integer) stp[1]; // lookup type
- Integer ln = (Integer) stp[2]; // lookup sequence number
- Integer lf = (Integer) stp[3]; // lookup flags
- Integer sn = (Integer) stp[4]; // subtable sequence number
- Integer sf = (Integer) stp[5]; // subtable format
- GlyphCoverageTable coverage = (GlyphCoverageTable) stp[6];
- List entries = (List) stp[7];
- if (tt == GlyphTable.GLYPH_TABLE_TYPE_POSITIONING) {
- int type = GSUBLookupType.getSubtableType(lt);
- String lid = "lu" + ln;
- int sequence = sn;
- int flags = lf;
- int format = sf;
- st = GlyphPositioningTable.createSubtable(type, lid, sequence, flags, format, coverage, entries);
- }
- return st;
- }
-
- private void initATState() {
- seScripts = new java.util.LinkedHashMap();
- seLanguages = new java.util.LinkedHashMap();
- seFeatures = new java.util.LinkedHashMap();
- seSubtables = new java.util.ArrayList();
- resetATSubState();
- }
-
- private void resetATState() {
- seScripts = null;
- seLanguages = null;
- seFeatures = null;
- seSubtables = null;
- resetATSubState();
- }
-
- private void initATSubState() {
- seMapping = null;
- seEntries = new java.util.ArrayList();
- }
-
- private void extractSESubState(int tableType, int lookupType, int lookupFlags, int lookupSequence, int subtableSequence, int subtableFormat) {
- if (seEntries != null) {
- if ((tableType == GlyphTable.GLYPH_TABLE_TYPE_DEFINITION) || (seEntries.size() > 0)) {
- if (seSubtables != null) {
- Integer tt = tableType;
- Integer lt = lookupType;
- Integer ln = lookupSequence;
- Integer lf = lookupFlags;
- Integer sn = subtableSequence;
- Integer sf = subtableFormat;
- seSubtables.add(new Object[] { tt, lt, ln, lf, sn, sf, seMapping, seEntries });
- }
- }
- }
- }
-
- private void resetATSubState() {
- seMapping = null;
- seEntries = null;
- }
-
- private void resetATStateAll() {
- resetATState();
- gdef = null;
- gsub = null;
- gpos = null;
- }
-
- /** helper method for formatting an integer array for output */
- private String toString(int[] ia) {
- StringBuffer sb = new StringBuffer();
- if ((ia == null) || (ia.length == 0)) {
- sb.append('-');
- } else {
- boolean first = true;
- for (int anIa : ia) {
- if (!first) {
- sb.append(' ');
- } else {
- first = false;
- }
- sb.append(anIa);
- }
- }
- return sb.toString();
- }
-
- }
|