public void GetSetClipboard() { var wsManager = new PalasoWritingSystemManager(); IWritingSystem enWs; wsManager.GetOrSet("en", out enWs); int wsEng = enWs.Handle; IWritingSystem swgWs; wsManager.GetOrSet("swg", out swgWs); int wsSwg = swgWs.Handle; var strFactory = TsStrFactoryClass.Create(); var incStrBldr = strFactory.GetIncBldr(); incStrBldr.AppendTsString(strFactory.MakeString("Gogomer ", wsSwg)); incStrBldr.AppendTsString(strFactory.MakeString("cucumber", wsEng)); EditingHelper.SetTsStringOnClipboard(incStrBldr.GetString(), false, wsManager); var tss = m_basicView.EditingHelper.GetTsStringFromClipboard(wsManager); Assert.IsNotNull(tss, "Couldn't get TsString from clipboard"); Assert.AreEqual(2, tss.RunCount); Assert.AreEqual("Gogomer ", tss.get_RunText(0)); Assert.AreEqual("cucumber", tss.get_RunText(1)); var newDataObj = ClipboardUtils.GetDataObject(); Assert.IsNotNull(newDataObj, "Couldn't get DataObject from clipboard"); Assert.AreEqual("Gogomer cucumber", newDataObj.GetData("Text")); }
public void TestTsStringWrapperRoundTrip(string str1, string namedStyle1, string str2, string namedStyle2) { var wsFact = new PalasoWritingSystemManager(); ITsStrBldr bldr = TsStrBldrClass.Create(); ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); try { wsFact.get_Engine("en"); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsFact.GetWsFromStr("en")); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, namedStyle1); bldr.Replace(bldr.Length, bldr.Length, str1, ttpBldr.GetTextProps()); if (namedStyle2 != null && str2 != null) { ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, namedStyle2); bldr.Replace(bldr.Length, bldr.Length, str2, ttpBldr.GetTextProps()); } var tsString1 = bldr.GetString(); var strWrapper = new TsStringWrapper(tsString1, wsFact); var tsString2 = strWrapper.GetTsString(wsFact); Assert.AreEqual(tsString1.Text, tsString2.Text); } finally { Marshal.ReleaseComObject(ttpBldr); Marshal.ReleaseComObject(bldr); } }
/// <summary> /// Whenever possible use this in place of new PalasoWritingSystemManager. /// It sets the TemplateFolder, which unfortunately the constructor cannot do because /// the direction of our dependencies does not allow it to reference FwUtils and access FwDirectoryFinder. /// </summary> /// <returns></returns> public static PalasoWritingSystemManager CreateWritingSystemManager() { var result = new PalasoWritingSystemManager(); result.TemplateFolder = FwDirectoryFinder.TemplateDirectory; return(result); }
/// <summary> /// NOTE: Copied from SIL.FieldWorks.IText.InterlinSfmImportTests /// </summary> /// <returns></returns> private PalasoWritingSystemManager GetWsf() { var wsf = new PalasoWritingSystemManager(); IWritingSystem wsObj; wsf.GetOrSet("qaa-x-kal", out wsObj); EnsureQuoteAndHyphenWordForming(wsObj); return(wsf); }
public void Persistence() { var wsManager = new PalasoWritingSystemManager(); IWritingSystem enWs; wsManager.GetOrSet("en", out enWs); int wsEng = enWs.Handle; IWritingSystem frWs; wsManager.GetOrSet("fr", out frWs); int wsFrn = frWs.Handle; IWritingSystem deWs; wsManager.GetOrSet("de", out deWs); int wsGer = deWs.Handle; InterlinLineChoices choices = new InterlinLineChoices(m_lp, wsFrn, wsEng); MakeStandardState(choices); string persist = choices.Persist(wsManager); choices = InterlinLineChoices.Restore(persist, wsManager, m_lp, wsFrn, wsEng); Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid); Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid); Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid); Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid); Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[4].Flid); Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid); Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[6].Flid); Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[7].Flid); Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[8].Flid); // Check writing systems assigned by default. Assert.AreEqual(wsFrn, choices[0].WritingSystem); Assert.AreEqual(wsEng, choices[5].WritingSystem); Assert.AreEqual(wsFrn, choices[2].WritingSystem); choices = new EditableInterlinLineChoices(m_lp, 0, wsEng); MakeStandardState(choices); choices.Add(InterlinLineChoices.kflidLexGloss, wsGer); Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid); Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid); Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid); Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid); Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid); Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid); Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid); Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[7].Flid); Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid); Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[9].Flid); Assert.AreEqual(wsGer, choices[4].WritingSystem); }
private static void RetrieveDefaultWritingSystemsFromLift(string liftPath, out IWritingSystem wsVern, out IWritingSystem wsAnalysis) { using (var liftReader = new StreamReader(liftPath, Encoding.UTF8)) { string vernWsId, analysisWsId; using (var reader = XmlReader.Create(liftReader)) RetrieveDefaultWritingSystemIdsFromLift(reader, out vernWsId, out analysisWsId); var wsManager = new PalasoWritingSystemManager(new GlobalFileWritingSystemStore()); wsManager.GetOrSet(vernWsId, out wsVern); wsManager.GetOrSet(analysisWsId, out wsAnalysis); } }
public void LanguageSubtag_newWS() { var wsManager = new PalasoWritingSystemManager(); using (var langSetup = new LanguageSetup()) { langSetup.WritingSystemManager = wsManager; langSetup.StartedInModifyState = false; langSetup.LanguageName = "Monkey"; LanguageSubtag subtag = langSetup.LanguageSubtag; Assert.AreEqual("mon", subtag.Code); LanguageSubtag newSubtag = new LanguageSubtag("mon", "Moniker", true, null); IWritingSystem newWs = wsManager.Create(newSubtag, null, null, null); wsManager.Set(newWs); subtag = langSetup.LanguageSubtag; Assert.AreEqual("aaa", subtag.Code, "Language code 'mon' should already be in use"); } }
public void SetTsStringOnClipboard_UsesNFC() { var wsManager = new PalasoWritingSystemManager(); IWritingSystem enWs; wsManager.GetOrSet("en", out enWs); int wsEng = enWs.Handle; var strFactory = TsStrFactoryClass.Create(); var originalInput = "\x7a7a\x60f3\x79d1\x5b78\x0020\xd558"; var input = originalInput.Normalize(NormalizationForm.FormD); Assert.That(originalInput, Is.Not.EqualTo(input)); // make sure input is NOT NFC var tss = strFactory.MakeString(input, wsEng); EditingHelper.SetTsStringOnClipboard(tss, false, wsManager); var newDataObj = ClipboardUtils.GetDataObject(); Assert.IsNotNull(newDataObj, "Couldn't get DataObject from clipboard"); Assert.AreEqual(originalInput, newDataObj.GetData("Text")); }
public void TestOverrideFontForWritingSystem_ForStyleWithNullProps() { var stylesheet = new TestFwStylesheet(); int hvoNewStyle1 = stylesheet.MakeNewStyle(); stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, 0, 0, false, false, null); var wsf = new PalasoWritingSystemManager(); ILgWritingSystem ws = wsf.get_Engine("de"); int hvoGermanWs = ws.Handle; Assert.IsTrue(hvoGermanWs > 0, "Should have gotten an hvo for the German WS"); // Array of 1 struct, contains writing system and font size to override List <FontOverride> fontOverrides = new List <FontOverride>(1); FontOverride aFontOverride; aFontOverride.writingSystem = hvoGermanWs; aFontOverride.fontSize = 48; fontOverrides.Add(aFontOverride); stylesheet.OverrideFontsForWritingSystems("FirstStyle", fontOverrides); //check results IVwPropertyStore vwps = VwPropertyStoreClass.Create(); vwps.Stylesheet = stylesheet; vwps.WritingSystemFactory = wsf; ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "FirstStyle"); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoGermanWs); ITsTextProps ttp = ttpBldr.GetTextProps(); LgCharRenderProps chrps = vwps.get_ChrpFor(ttp); ws.InterpretChrp(ref chrps); Assert.AreEqual(48, chrps.dympHeight / 1000); }
public void TestOverrideFontsForWritingSystems_ForStyleWithProps() { var stylesheet = new TestFwStylesheet(); int hvoNewStyle1 = stylesheet.MakeNewStyle(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial"); propsBldr.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 23000); stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, 0, 0, false, false, propsBldr.GetTextProps()); var wsf = new PalasoWritingSystemManager(); ILgWritingSystem wsIngles = wsf.get_Engine("en"); int hvoInglesWs = wsIngles.Handle; Assert.IsTrue(hvoInglesWs > 0, "Should have gotten an HVO for the English WS"); ILgWritingSystem wsFrench = wsf.get_Engine("fr"); int hvoFrenchWs = wsFrench.Handle; Assert.IsTrue(hvoFrenchWs > 0, "Should have gotten an HVO for the French WS"); ILgWritingSystem wsGerman = wsf.get_Engine("de"); int hvoGermanWs = wsGerman.Handle; Assert.IsTrue(hvoGermanWs > 0, "Should have gotten an HVO for the German WS"); Assert.IsTrue(hvoFrenchWs != hvoGermanWs, "Should have gotten different HVOs for each WS"); Assert.IsTrue(hvoInglesWs != hvoGermanWs, "Should have gotten different HVOs for each WS"); Assert.IsTrue(hvoFrenchWs != hvoInglesWs, "Should have gotten different HVOs for each WS"); // Array of structs, containing writing systems and font sizes to override. var fontOverrides = new List <FontOverride>(2); FontOverride aFontOverride; aFontOverride.writingSystem = hvoInglesWs; aFontOverride.fontSize = 34; fontOverrides.Add(aFontOverride); aFontOverride.writingSystem = hvoGermanWs; aFontOverride.fontSize = 48; fontOverrides.Add(aFontOverride); stylesheet.OverrideFontsForWritingSystems("FirstStyle", fontOverrides); //check results IVwPropertyStore vwps = VwPropertyStoreClass.Create(); vwps.Stylesheet = stylesheet; vwps.WritingSystemFactory = wsf; ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "FirstStyle"); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoFrenchWs); ITsTextProps ttpFrench = ttpBldr.GetTextProps(); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoGermanWs); ITsTextProps ttpGerman = ttpBldr.GetTextProps(); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoInglesWs); ITsTextProps ttpIngles = ttpBldr.GetTextProps(); LgCharRenderProps chrpsFrench = vwps.get_ChrpFor(ttpFrench); LgCharRenderProps chrpsGerman = vwps.get_ChrpFor(ttpGerman); LgCharRenderProps chrpsIngles = vwps.get_ChrpFor(ttpIngles); wsFrench.InterpretChrp(ref chrpsFrench); wsGerman.InterpretChrp(ref chrpsGerman); wsIngles.InterpretChrp(ref chrpsIngles); Assert.AreEqual(23, chrpsFrench.dympHeight / 1000); Assert.AreEqual(34, chrpsIngles.dympHeight / 1000); Assert.AreEqual(48, chrpsGerman.dympHeight / 1000); }
/// ------------------------------------------------------------------------------------- /// <summary> /// Make a writing system factory that is based on the Languages folder (ICU-based). /// This is only used in Designer, tests, and momentarily (during construction) in /// production, until the client sets supplies a real one. /// </summary> /// ------------------------------------------------------------------------------------- private void CreateTempWritingSystemFactory() { m_wsf = new PalasoWritingSystemManager(); m_fUsingTempWsFactory = true; }
public SharpViewFdo() { m_wsf = new PalasoWritingSystemManager(); //m_wsf.get_CharPropEngine(m_wsf.UserWs); // This is a device for getting InitIcuDataDirectory called. }