private void ReadScriptRecord(TagAndLocation tagLoc) { openTypeReader.rf.Seek(tagLoc.location); int locationDefaultLanguage = openTypeReader.rf.ReadUnsignedShort(); if (locationDefaultLanguage > 0) { locationDefaultLanguage += tagLoc.location; } TagAndLocation[] tagsLocs = openTypeReader.ReadTagAndLocations(tagLoc.location); ScriptRecord srec = new ScriptRecord(); srec.tag = tagLoc.tag; srec.languages = new LanguageRecord[tagsLocs.Length]; for (int k = 0; k < tagsLocs.Length; ++k) { srec.languages[k] = ReadLanguageRecord(tagsLocs[k]); } if (locationDefaultLanguage > 0) { TagAndLocation t = new TagAndLocation(); t.tag = ""; t.location = locationDefaultLanguage; srec.defaultLanguage = ReadLanguageRecord(t); } records.Add(srec); }
public virtual LanguageRecord GetLanguageRecord(String[] scripts, String language) { ScriptRecord scriptFound = null; ScriptRecord scriptDefault = null; foreach (ScriptRecord sr in records) { if (DEFAULT_SCRIPT.Equals(sr.tag)) { scriptDefault = sr; break; } } foreach (String script in scripts) { foreach (ScriptRecord sr in records) { if (sr.tag.Equals(script)) { scriptFound = sr; break; } if (DEFAULT_SCRIPT.Equals(script)) { scriptDefault = sr; } } if (scriptFound != null) { break; } } if (scriptFound == null) { scriptFound = scriptDefault; } if (scriptFound == null) { return(null); } LanguageRecord lang = null; foreach (LanguageRecord lr in scriptFound.languages) { if (lr.tag.Equals(language)) { lang = lr; break; } } if (lang == null) { lang = scriptFound.defaultLanguage; } return(lang); }
public virtual void TestFetchLangSysByTag() { TrueTypeFont fontProgram = (TrueTypeFont)FontProgramFactory.CreateFont(RESOURCE_FOLDER + "NotoSansMyanmar-Regular.ttf" ); GlyphSubstitutionTableReader gsub = fontProgram.GetGsubTable(); ScriptRecord mym2 = gsub.GetScriptRecords()[0]; NUnit.Framework.Assert.AreEqual("mym2", mym2.tag); // default LangSys has no tag NUnit.Framework.Assert.AreEqual("", gsub.GetLanguageRecord("mym2").tag); NUnit.Framework.Assert.AreEqual(LanguageTags.SGAW_KAREN, gsub.GetLanguageRecord("mym2", LanguageTags.SGAW_KAREN ).tag); NUnit.Framework.Assert.AreEqual(LanguageTags.MON, gsub.GetLanguageRecord("mym2", LanguageTags.MON).tag); NUnit.Framework.Assert.IsNull(gsub.GetLanguageRecord(null)); NUnit.Framework.Assert.IsNull(gsub.GetLanguageRecord("mym3")); NUnit.Framework.Assert.IsNull(gsub.GetLanguageRecord("mym3", LanguageTags.SGAW_KAREN)); }