Esempio n. 1
0
        public void AddDeleteStyle()
        {
            var tsPropsBldr        = TsPropsBldrClass.Create();
            var ttpFormattingProps = tsPropsBldr.GetTextProps();             // default properties
            var nStylesOrig        = m_styleSheet.CStyles;

            // get an hvo for the new style
            var hvoStyle = m_styleSheet.MakeNewStyle();
            var style    = Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(hvoStyle);

            // PutStyle() adds the style to the stylesheet
            m_styleSheet.PutStyle("MyNewStyle", "bla", hvoStyle, 0,
                                  hvoStyle, 0, false, false, ttpFormattingProps);

            Assert.AreEqual(nStylesOrig + 1, m_styleSheet.CStyles);
            Assert.AreEqual(ttpFormattingProps, m_styleSheet.GetStyleRgch(0, "MyNewStyle"),
                            "Should get correct format props for the style added");

            // Make style be based on section head and check context
            var baseOnStyle = m_scr.FindStyle(ScrStyleNames.SectionHead);

            m_styleSheet.PutStyle("MyNewStyle", "bla", hvoStyle, baseOnStyle.Hvo,
                                  hvoStyle, 0, false, false, ttpFormattingProps);
            Assert.AreEqual(baseOnStyle.Context, style.Context);

            // Now delete the new style
            m_styleSheet.Delete(hvoStyle);

            // Verfiy the deletion
            Assert.AreEqual(nStylesOrig, m_styleSheet.CStyles);
            Assert.IsNull(m_styleSheet.GetStyleRgch(0, "MyNewStyle"),
                          "Should get null because style is not there");
        }
Esempio n. 2
0
        public void CreateFromStringRep_BT_withBrackets()
        {
            SetupBackTrans();

            // Setup expected results for the footnote
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                       (int)FwTextPropVar.ktpvDefault, m_vernWs);
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
            ITsStrBldr bldr = TsStrBldrClass.Create();

            bldr.Replace(0, 0, "Text in <brackets>", propsBldr.GetTextProps());
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                      null);
            m_footnotePara.Contents = bldr.GetString();

            // ... and now set up the expected results for the back translations of the footnote.
            AddRunToMockedTrans(m_trans, m_wsEs, "Spanish BT in <brackets>", null);
            AddRunToMockedTrans(m_trans, m_wsDe, "German BT in <brackets>", null);

            // Define text representation and create a footnote from it.
            string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" +
                                 @"<RUN WS='fr'>Text in &lt;brackets&gt;</RUN>" +
                                 @"<TRANS WS='de'><RUN WS='de'>German BT in &lt;brackets&gt;</RUN></TRANS>" +
                                 @"<TRANS WS='es'><RUN WS='es'>Spanish BT in &lt;brackets&gt;</RUN></TRANS></P></FN>";
            IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book,
                                                                                                                footnoteRep, 0, "Note Marker");

            CompareFootnote(footnote);
        }
Esempio n. 3
0
        public void StringPropWrongLengthFmtTest()
        {
            CheckDisposed();

            // Set class first, or it will throw an exception.
            int  hvo  = 1;
            uint clid = SilDataAccess.MetaDataCache.GetClassId("PhEnvironment");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clid);
            int tag = (int)SilDataAccess.MetaDataCache.GetFieldId("PhEnvironment", "StringRepresentation", false);

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            ITsStrBldr strBldr = TsStrBldrClass.Create();

            // Test StringFields (which are basically the same, except that the
            // format of the parameters is different)
            strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();
            int       cbFmt;

            byte[] rgbFmt;
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte)))
            {
                cbFmt  = tsString.SerializeFmtRgb(arrayPtr, 1000);
                rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte));
            }
            VwCacheDa.CacheStringFields(hvo, tag, tsString.Text,
                                        tsString.Length, rgbFmt, cbFmt - 1);
        }
Esempio n. 4
0
        public void StringFields_Replace()
        {
            CheckDisposed();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            ITsStrBldr strBldr = TsStrBldrClass.Create();

            // Test StringFields (which are basically the same, except that the
            // format of the parameters is different)
            strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte)))
            {
                int    cbFmt  = tsString.SerializeFmtRgb(arrayPtr, 1000);
                byte[] rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte));
                m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text,
                                               tsString.Length, rgbFmt, cbFmt);
                strBldr.Replace(0, 5, "Fourth", propsBldr.GetTextProps());
                tsString = strBldr.GetString();

                m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text,
                                               tsString.Length, rgbFmt, cbFmt);

                ITsString tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228);

                Assert.AreEqual(tsString.Text, tsStringNew.Text);
            }
        }
Esempio n. 5
0
        public void CreateFromStringRep_twoCharStylePara()
        {
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                       (int)FwTextPropVar.ktpvDefault,
                                       m_vernWs);
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                      "Emphasis");
            ITsStrBldr bldr = TsStrBldrClass.Create();

            bldr.Replace(0, 0, "Test Text", propsBldr.GetTextProps());
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                      null);
            bldr.Replace(bldr.Length, bldr.Length, "No char style",
                         propsBldr.GetTextProps());
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                      "Quoted Text");
            bldr.Replace(bldr.Length, bldr.Length, "Ahh!!!!!!",
                         propsBldr.GetTextProps());
            m_footnotePara.Contents = bldr.GetString();

            string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" +
                                 @"<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" +
                                 "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN></P></FN>";
            IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book,
                                                                                                                footnoteRep, 0, "Note Marker");

            CompareFootnote(footnote);
        }
        public void MergeWritingSystemWithStyleDefnForToWs_DoesNotConvertStyleDefinition()
        {
            IWritingSystem fromWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, "en-NO", true, false, out fromWs);
            IWritingSystem toWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, "en-SO", true, false, out toWs);
            EnsureAnalysisWs(new[] { fromWs, toWs });

            var style1 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create();

            Cache.LangProject.StylesOC.Add(style1);
            var fontOverrides = new Dictionary <int, FontInfo>();
            var fontOverride  = new FontInfo();

            fontOverride.m_italic.ExplicitValue = true;
            fontOverrides[fromWs.Handle]        = fontOverride;
            fontOverride = new FontInfo();
            fontOverride.m_bold.ExplicitValue = true;
            fontOverrides[toWs.Handle]        = fontOverride;
            var bldr = TsPropsBldrClass.Create();

            BaseStyleInfo.SaveFontOverridesToBuilder(fontOverrides, bldr);
            style1.Rules = bldr.GetTextProps();
            m_actionHandler.EndUndoTask();
            UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler,
                                        () => WritingSystemServices.MergeWritingSystems(Cache, fromWs, toWs));
            var styleInfo    = new BaseStyleInfo(style1);
            var overrideInfo = styleInfo.OverrideCharacterStyleInfo(toWs.Handle);

            Assert.IsNotNull(overrideInfo);
            Assert.That(overrideInfo.Bold.Value, Is.True);
            Assert.That(overrideInfo.Italic.ValueIsSet, Is.False);
        }
Esempio n. 7
0
        public void MultiStringAlt()
        {
            CheckDisposed();
            ITsString tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7);

            Assert.IsNotNull(tsStringNew);
            Assert.AreEqual(0, tsStringNew.Length);

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
            ITsStrBldr   strBldr   = TsStrBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            strBldr.Replace(0, 0, "Test", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();

            m_IVwCacheDa.CacheStringAlt(1117, 2227, 7, tsString);
            tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7);
            Assert.AreEqual(tsString, tsStringNew);

            strBldr.Replace(0, 0, "SecondTest", propsBldr.GetTextProps());
            tsString = strBldr.GetString();
            m_IVwCacheDa.CacheStringAlt(1117, 2227, 7, tsString);
            tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7);
            Assert.AreEqual(tsString, tsStringNew);

            tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 8);
            Assert.IsNotNull(tsStringNew);
            Assert.AreEqual(0, tsStringNew.Length);
        }
Esempio n. 8
0
        public void PropsDifferByCount()
        {
            // test of different string property counts
            ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create();

            //note: due to design in PropsAreEqual(), we will get the count message
            // only when all the str props in the first ttp match in the second ttp, and the
            // second ttp has additional str props
            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily,
                                        "my font");
            ITsTextProps ttp1 = tsPropsBldr.GetTextProps();

            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style");
            ITsTextProps ttp2 = tsPropsBldr.GetTextProps();
            string       s;

            Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s));
            Assert.AreEqual("Props differ in count of strProps. Expected <1>, but was <2>.", s);

            // test of different int property counts
            tsPropsBldr = TsPropsBldrClass.Create();             // empty builder
            tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBorderColor,
                                         (int)FwTextPropVar.ktpvDefault, 123);
            ttp1 = tsPropsBldr.GetTextProps();
            tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBorderTop,
                                         (int)FwTextPropVar.ktpvDefault, 10);
            ttp2 = tsPropsBldr.GetTextProps();
            Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s));
            Assert.AreEqual("Props differ in count of intProps. Expected <1>, but was <2>.", s);
        }
Esempio n. 9
0
        public void PropsDifferByIntProps()
        {
            // test of different int prop: writing system
            ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create();

            tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                         (int)FwTextPropVar.ktpvDefault, 4565754);
            ITsTextProps ttp1 = tsPropsBldr.GetTextProps();

            tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                         (int)FwTextPropVar.ktpvDefault, 4565753);
            ITsTextProps ttp2 = tsPropsBldr.GetTextProps();
            string       s;

            Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s));
            Assert.AreEqual("Props differ in ktptWs property. Expected ws <4565754> and var <0>, but was ws <4565753> and var <0>.", s);

            // test of different int prop: background color
            tsPropsBldr = TsPropsBldrClass.Create(); // empty builder
            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                        "my style"); //string prop, same for both
            tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor,
                                         (int)FwTextPropVar.ktpvDefault, 98);
            ttp1 = tsPropsBldr.GetTextProps();
            tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor,
                                         (int)FwTextPropVar.ktpvDefault, 99);
            ttp2 = tsPropsBldr.GetTextProps();
            Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s));
            Assert.AreEqual("Props differ in intProp type 9. "
                            + "Expected <98,0>, but was <99,0>.", s);
        }
Esempio n. 10
0
        public void PropsDifferByStrProps()
        {
            // test of different str prop: named style
            ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create();

            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                        "my style");
            ITsTextProps ttp1 = tsPropsBldr.GetTextProps();

            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                        "your style");
            ITsTextProps ttp2 = tsPropsBldr.GetTextProps();
            string       s;

            Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s));
            Assert.AreEqual("Props differ in ktptNamedStyle property. "
                            + "Expected <my style>, but was <your style>.", s);

            // test of different str prop: named style
            tsPropsBldr = TsPropsBldrClass.Create();                               // empty builder
            tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                         (int)FwTextPropVar.ktpvDefault, 4565754); // int prop, same for both
            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily,
                                        "my font");
            ttp1 = tsPropsBldr.GetTextProps();
            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily,
                                        "your font");
            ttp2 = tsPropsBldr.GetTextProps();
            Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s));
            Assert.AreEqual("Props differ in strProp type 1. "
                            + "Expected <my font>, but was <your font>.", s);
        }
Esempio n. 11
0
        public void TestGetStyleRgch()
        {
            IVwStylesheet stylesheet = (IVwStylesheet) new TestFwStylesheet();
            ITsPropsBldr  propsBldr  = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times");
            ITsTextProps props1 = propsBldr.GetTextProps();

            propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor,
                                       (int)FwTextPropVar.ktpvDefault, 256);
            ITsTextProps props2       = propsBldr.GetTextProps();
            int          hvoNewStyle1 = stylesheet.MakeNewStyle();

            stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, hvoNewStyle1, 0, false,
                                false, props1);
            int hvoNewStyle2 = stylesheet.MakeNewStyle();

            stylesheet.PutStyle("SecondStyle", "bla", hvoNewStyle2, 0, hvoNewStyle1, 0, false,
                                false, props2);
            string sHowDifferent;
            bool   fEqual = TsTextPropsHelper.PropsAreEqual(props2,
                                                            stylesheet.GetStyleRgch(0, "SecondStyle"), out sHowDifferent);

            Assert.IsTrue(fEqual, sHowDifferent);
            fEqual = TsTextPropsHelper.PropsAreEqual(props1,
                                                     stylesheet.GetStyleRgch(0, "FirstStyle"), out sHowDifferent);
            Assert.IsTrue(fEqual, sHowDifferent);
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fdoCache"></param>
        /// <returns></returns>
        public static ITsTextProps PartOfSpeechTextProperties(FdoCache fdoCache, bool inAnalysisLine, bool fUseStyleSheet)
        {
            int          color = (int)CmObjectUi.RGB(Color.Green);
            ITsPropsBldr bldr  = TsPropsBldrClass.Create();

            if (!fUseStyleSheet)
            {
                bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                      (int)FwTextPropVar.ktpvMilliPoint, (int)(s_baseFontSize * 1000 * .8));
            }
            bldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                  (int)FwTextPropVar.ktpvDefault, fdoCache.DefaultAnalWs);
            //			bldr.SetIntPropValues((int)FwTextPropType.ktptItalic,
            //				(int)FwTextPropVar.ktpvEnum,
            //				(int)FwTextToggleVal.kttvInvert);

            if (inAnalysisLine)
            {
                bldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript,
                                      (int)FwTextPropVar.ktpvEnum,
                                      (int)FwSuperscriptVal.kssvSub);
            }



            bldr.SetIntPropValues((int)FwTextPropType.ktptForeColor,
                                  (int)FwTextPropVar.ktpvDefault, color);
            return(bldr.GetTextProps());
        }
Esempio n. 13
0
        public void CreateFromStringRep_twoCharStylePara()
        {
            CheckDisposed();

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                       (int)FwTextPropVar.ktpvDefault,
                                       m_vernWs);
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                      "Emphasis");
            ITsStrBldr bldr = TsStrBldrClass.Create();

            bldr.Replace(0, 0, "Test Text", propsBldr.GetTextProps());
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                      null);
            bldr.Replace(bldr.Length, bldr.Length, "No char style",
                         propsBldr.GetTextProps());
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                      "Quoted Text");
            bldr.Replace(bldr.Length, bldr.Length, "Ahh!!!!!!",
                         propsBldr.GetTextProps());
            m_footnotePara.Contents.UnderlyingTsString = bldr.GetString();

            string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" +
                                 @"<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" +
                                 "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN></P></FN>";
            StFootnote footnote = StFootnote.CreateFromStringRep(m_book,
                                                                 (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker");

            CompareFootnote(footnote);
        }
        public void UnknownTests()
        {
            var      lp           = Cache.LanguageProject;
            var      styleFactory = Cache.ServiceLocator.GetInstance <IStStyleFactory>();
            IStStyle style;

            using (var undoHelper = new NonUndoableUnitOfWorkHelper(m_actionHandler))
            {
                style = styleFactory.Create();
                lp.StylesOC.Add(style);
                undoHelper.RollBack = false;
            }
            // Should be one PC.
            CheckChanges(1, 0, lp.Hvo, LangProjectTags.kflidStyles, 0, 1, 0);
            ClearChanges();

            var userWs = Cache.WritingSystemFactory.UserWs;
            var bldr   = TsPropsBldrClass.Create();

            bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Arial");
            bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);
            var tpp = bldr.GetTextProps();

            using (var undoHelper = new NonUndoableUnitOfWorkHelper(m_actionHandler))
            {
                style.Rules         = tpp;
                undoHelper.RollBack = false;
            }
            // Should be one PC.
            CheckChanges(1, 0, style.Hvo, StStyleTags.kflidRules, 0, 0, 0);
            ClearChanges();
        }
Esempio n. 15
0
		public AffixRuleFormulaVc(FdoCache cache, XCore.Mediator mediator)
			: base(cache, mediator)
		{
			ITsPropsBldr tpb = TsPropsBldrClass.Create();
			tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif);
			tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
			m_headerProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
			tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 24000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Charis SIL");
			tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
			m_arrowProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderTop, (int)FwTextPropVar.ktpvMilliPoint, 1000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderTrailing, (int)FwTextPropVar.ktpvMilliPoint, 1000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			m_ctxtProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderTrailing, (int)FwTextPropVar.ktpvMilliPoint, 1000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
			tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			m_indexProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			m_resultProps = tpb.GetTextProps();

			var tsf = m_cache.TsStrFactory;
			var userWs = m_cache.DefaultUserWs;
			m_inputStr = tsf.MakeString(MEStrings.ksAffixRuleInput, userWs);
			m_indexStr = tsf.MakeString(MEStrings.ksAffixRuleIndex, userWs);
			m_resultStr = tsf.MakeString(MEStrings.ksAffixRuleResult, userWs);
			m_doubleArrow = tsf.MakeString("\u21d2", userWs);
			m_space = tsf.MakeString(" ", userWs);
		}
Esempio n. 16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Returns paragraph textprops representing a paragraph style of the given name.
        /// </summary>
        /// <param name="styleName">The name of the paragraph style</param>
        /// <returns>A TsTextProps object wich will have exactly zero int props and one string
        /// prop: the named style, whose value will be the given styleName</returns>
        /// <remarks>This is useful for setting BaseStPara.StyleRules.</remarks>
        /// ------------------------------------------------------------------------------------
        public static ITsTextProps ParaStyleTextProps(string styleName)
        {
            Debug.Assert(!string.IsNullOrEmpty(styleName));

            // Build props for the given para style name
            ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create();

            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
            return(tsPropsBldr.GetTextProps());
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Set up some dummy styles for testing purposes
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            m_stylesheet = new TestFwStylesheet();
            m_wsManager  = new PalasoWritingSystemManager();

            // English
            IWritingSystem enWs;

            m_wsManager.GetOrSet("en", out enWs);
            m_hvoEnglishWs = enWs.Handle;
            Assert.IsTrue(m_hvoEnglishWs > 0, "Should have gotten an hvo for the English WS");
            // German
            IWritingSystem deWs;

            m_wsManager.GetOrSet("de", out deWs);
            m_hvoGermanWs = deWs.Handle;
            Assert.IsTrue(m_hvoGermanWs > 0, "Should have gotten an hvo for the German WS");
            Assert.IsTrue(m_hvoEnglishWs != m_hvoGermanWs, "Writing systems should have different IDs");

            // Create a couple of styles
            int          hvoStyle  = m_stylesheet.MakeNewStyle();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial");
            m_stylesheet.PutStyle("StyleA", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            hvoStyle = m_stylesheet.MakeNewStyle();
            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times New Roman");
            m_stylesheet.PutStyle("StyleB", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            // Override the font size for each writing system and each style.
            List <FontOverride> fontOverrides = new List <FontOverride>(2);
            FontOverride        fo;

            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 21;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 13;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleA", fontOverrides);

            fontOverrides.Clear();
            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 20;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 56;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleB", fontOverrides);
        }
Esempio n. 18
0
        public void Setup()
        {
            tsf   = TsStrFactoryClass.Create();
            wsf   = new MockWsf();
            wsEn  = wsf.GetWsFromStr("en");
            wsFrn = wsf.GetWsFromStr("fr");
            ITsPropsBldr propBldr = TsPropsBldrClass.Create();

            propBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsFrn);
            ttpFrn = propBldr.GetTextProps();
        }
Esempio n. 19
0
        protected ITsString MakeSimpleString(String str)
        {
            ITsStrBldr   builder = TsStrBldrClass.Create();
            ITsPropsBldr bldr    = TsPropsBldrClass.Create();

            bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                  (int)FwTextPropVar.ktpvMilliPoint, s_baseFontSize * 800);
            bldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial");
            builder.Replace(0, 0, str, bldr.GetTextProps());
            return(builder.GetString());
        }
Esempio n. 20
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Returns paragraph textprops representing a paragraph style of the given name.
        /// </summary>
        /// <param name="styleName">The name of the paragraph style</param>
        /// <returns>A TsTextProps object wich will have exactly zero int props and one string
        /// prop: the named style, whose value will be the given styleName</returns>
        /// <remarks>This is useful for setting BaseStPara.StyleRules.</remarks>
        /// ------------------------------------------------------------------------------------
        static public ITsTextProps ParaStyleTextProps(string styleName)
        {
            Debug.Assert(styleName != null && styleName.Length > 0);

            // Build props for the given para style name
            ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create();

            //ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create();
            tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                        styleName);
            return(tsPropsBldr.GetTextProps());
        }
Esempio n. 21
0
        public void SetupStyles()
        {
            m_stylesheet        = new TestFwStylesheet();
            m_wsf               = LgWritingSystemFactoryClass.Create();
            m_wsf.BypassInstall = true;

            // German
            IWritingSystem wsGerman = m_wsf.get_Engine("de");

            m_hvoGermanWs = wsGerman.WritingSystem;
            Assert.IsTrue(m_hvoGermanWs > 0, "Should have gotten an hvo for the German WS");
            // English
            IWritingSystem wsEnglish = m_wsf.get_Engine("en");

            m_hvoEnglishWs = wsEnglish.WritingSystem;
            Assert.IsTrue(m_hvoEnglishWs > 0, "Should have gotten an hvo for the English WS");
            Assert.IsTrue(m_hvoEnglishWs != m_hvoGermanWs, "Writing systems should have different IDs");

            // Create a couple of styles
            int          hvoStyle  = m_stylesheet.MakeNewStyle();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial");
            m_stylesheet.PutStyle("StyleA", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            hvoStyle = m_stylesheet.MakeNewStyle();
            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times New Roman");
            m_stylesheet.PutStyle("StyleB", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            // Override the font size for each writing system and each style.
            List <FontOverride> fontOverrides = new List <FontOverride>(2);
            FontOverride        fo;

            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 13;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 21;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleA", fontOverrides);

            fontOverrides.Clear();
            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 56;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 20;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleB", fontOverrides);
        }
Esempio n. 22
0
        protected ITsString MakeSimpleString(String str)
        {
            ITsStrBldr   builder = TsStrBldrClass.Create();
            ITsPropsBldr bldr    = TsPropsBldrClass.Create();

            bldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                  (int)FwTextPropVar.ktpvDefault, m_cache.DefaultUserWs);
            bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                  (int)FwTextPropVar.ktpvMilliPoint, s_baseFontSize * 800);
            bldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, MiscUtils.StandardSansSerif);
            builder.Replace(0, 0, str, bldr.GetTextProps());
            return(builder.GetString());
        }
        public void UnkPropWrongInterfaceTest()
        {
            // First, set up class id.
            const int hvo  = 1;
            var       clid = SilDataAccess.MetaDataCache.GetClassId("ClassG");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, clid);

            var tsPropsBuilder = TsPropsBldrClass.Create();
            var tag            = SilDataAccess.MetaDataCache.GetFieldId("ClassG", "TextPropsProp7", false);

            SilDataAccess.SetUnknown(hvo, tag, tsPropsBuilder);
        }
Esempio n. 24
0
        public void UnknownProp()
        {
            object obj = m_ISilDataAccess.get_UnknownProp(1120, 2220);

            Assert.IsNull(obj);

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
            ITsTextProps ttp       = propsBldr.GetTextProps();

            m_IVwCacheDa.CacheUnknown(1120, 2220, ttp);
            obj = m_ISilDataAccess.get_UnknownProp(1120, 2220);
            Assert.AreEqual(ttp, obj);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates the categories.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="ws">The writing system for setting the category names.</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        internal static ICmPossibilityList CreateCategories(FdoCache cache, int ws)
        {
            ICmPossibilityList list = cache.LangProject.TranslatedScriptureOA.NoteCategoriesOA;

            list.PossibilitiesOS.Clear();
            var possFactory = cache.ServiceLocator.GetInstance <ICmPossibilityFactory>();

            // Initialize text.
            ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();

            ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                     (int)FwTextPropVar.ktpvDefault, ws);
            ITsStrBldr tsStrBldr = TsStrBldrClass.Create();

            // Set possibilities on top level--"Level 1a"
            ICmPossibility possibility1a = possFactory.Create();

            list.PossibilitiesOS.Add(possibility1a);
            tsStrBldr.ReplaceRgch(0, 0, "Level 1a", 8, ttpBldr.GetTextProps());
            possibility1a.Name.set_String(ws, tsStrBldr.GetString());

            // Add another on top level--"Level 1b"
            ICmPossibility possibility1b = possFactory.Create();

            list.PossibilitiesOS.Add(possibility1b);
            tsStrBldr.ReplaceRgch(0, tsStrBldr.Length, "Level 1b", 8, ttpBldr.GetTextProps());
            possibility1b.Name.set_String(ws, tsStrBldr.GetString());

            // Add possibilities on second level under "Level 1b"--"Level 2a"
            ICmPossibility subPossibility2a = possFactory.Create();

            possibility1b.SubPossibilitiesOS.Add(subPossibility2a);
            tsStrBldr.ReplaceRgch(0, tsStrBldr.Length, "Level 2a, parent is 1b", 22, ttpBldr.GetTextProps());
            subPossibility2a.Name.set_String(ws, tsStrBldr.GetString());

            // Add "Level 2b" under "Level 1b"
            ICmPossibility subPossibility2b = possFactory.Create();

            possibility1b.SubPossibilitiesOS.Add(subPossibility2b);
            tsStrBldr.ReplaceRgch(0, tsStrBldr.Length, "Level 2b, parent is 1b", 22, ttpBldr.GetTextProps());
            subPossibility2b.Name.set_String(ws, tsStrBldr.GetString());

            // Add "Level 3" under "Level 2b"
            ICmPossibility subSubPossibility3 = possFactory.Create();

            subPossibility2b.SubPossibilitiesOS.Add(subSubPossibility3);
            tsStrBldr.ReplaceRgch(0, tsStrBldr.Length, "Level 3, parent is 2b", 21, ttpBldr.GetTextProps());
            subSubPossibility3.Name.set_String(ws, tsStrBldr.GetString());

            return(list);
        }
Esempio n. 26
0
        /// <summary>
        /// Make a TsString in the specified (typicaly UI) writing system, which is forced to be
        /// displayed in the default UIElement style.
        /// </summary>
        protected ITsString MakeUiElementString(string text, int uiWs, Action <ITsPropsBldr> SetAdditionalProps)
        {
            ITsStrBldr   bldr      = m_tsf.GetBldr();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, uiWs);
            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, StyleServices.UiElementStylename);
            if (SetAdditionalProps != null)
            {
                SetAdditionalProps(propsBldr);
            }
            bldr.Replace(0, 0, text, propsBldr.GetTextProps());
            return(bldr.GetString());
        }
Esempio n. 27
0
        public void ExportPicture_MultipleWS()
        {
            // Create a picture that has a caption with three different writing systems.
            ITsStrBldr   tssBldr   = TsStrBldrClass.Create();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, InMemoryFdoCache.s_wsHvos.De);
            tssBldr.ReplaceRgch(0, 0, "photo", 5, propsBldr.GetTextProps());
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, InMemoryFdoCache.s_wsHvos.Ur);
            tssBldr.ReplaceRgch(tssBldr.Length, tssBldr.Length, " tasvir", 7, propsBldr.GetTextProps());
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, Cache.DefaultVernWs);
            tssBldr.ReplaceRgch(tssBldr.Length, tssBldr.Length, " picture caption", 16, propsBldr.GetTextProps());
            CmPicture picture = new CmPicture(m_inMemoryCache.Cache, @"c:\filename.jpg", tssBldr.GetString(), "folder");

            // Set up for export
            StringWriter  stream = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(stream);

            writer.Formatting = Formatting.None;
            m_exporter        = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0,
                                              "ExportPicture_MultipleWS");
            ReflectionHelper.SetField(m_exporter, "m_writer", writer);

            // Export the picture to XML
            ReflectionHelper.CallMethod(m_exporter, "ExportPicture", picture);

            // Check the results of the exported picture.
            //   Set up expected results.
            string defaultDir = DirectoryFinder.FWDataDirectory;
            // TODO (TE-7756): Support OXES export and import of new properties that have been
            // added to the CmPicture model
            string strExpected = "<figure src=\"filename.jpg\"><!--path=\"" + defaultDir + "\\filename\"-->" +
                                 "<caption><trGroup><tr><foreign xml:lang=\"de\">photo</foreign>" +
                                 "<foreign xml:lang=\"ur\"> tasvir</foreign> picture caption</tr></trGroup></caption></figure>";
            XmlDocument expected = new XmlDocument();

            expected.Load(new StringReader(strExpected));

            //   Get actual results.
            XmlDocument actual = new XmlDocument();

            actual.Load(new StringReader(stream.ToString()));

            string strDifference;

            if (!XmlHelper.CompareXmlNodes(expected.ChildNodes, actual.ChildNodes, out strDifference))
            {
                Assert.Fail(strDifference);
            }
        }
        public void ParagraphBreak_RemoveCharStyleFromAdjacentWhiteSpace()
        {
            CheckDisposed();
            m_draftView.RefreshDisplay();

            // *** Test setup ***
            // Insert text with a character style.
            StTxtPara    para1   = (StTxtPara)m_exodus.SectionsOS[0].ContentOA.ParagraphsOS[0];
            ITsStrBldr   tssBldr = para1.Contents.UnderlyingTsString.GetBldr();
            ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();

            ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasis");
            tssBldr.ReplaceRgch(15, 15, "really,  really", 6, ttpBldr.GetTextProps());
            int paraCount = m_exodus.SectionsOS[0].ContentOA.ParagraphsOS.Count;

            // Set the IP in the white space within the inserted text.
            m_draftView.SetInsertionPoint(0, 0, 0, 23, true);
            IVwSelection sel0 = m_draftView.RootBox.Selection;

            Assert.IsNotNull(sel0);

            // Insert paragraph break
            m_draftView.OnKeyPress(new KeyPressEventArgs('\r'));

            Assert.AreEqual(paraCount + 1, m_exodus.SectionsOS[0].ContentOA.ParagraphsOS.Count,
                            "Should have one more paragraph in the intro section");

            // We expect that the last run of the first paragraph and first run of the new
            // paragraph will be a space character with no character style.
            ITsString tss1 = para1.Contents.UnderlyingTsString;

            Assert.AreEqual(3, tss1.RunCount, "First intro paragraph should have three runs");
            Assert.AreEqual("really,", tss1.get_RunText(1));
            ITsTextProps ttp = tss1.get_Properties(1);

            Assert.AreEqual("Emphasis", ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle));
            ttp = tss1.get_Properties(2);
            Assert.AreEqual(" ", tss1.get_RunText(2));
            Assert.AreEqual(null, ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle));

            ITsString tss2 = ((StTxtPara)m_exodus.SectionsOS[0].ContentOA.ParagraphsOS[1]).Contents.UnderlyingTsString;

            Assert.AreEqual(3, tss2.RunCount);
            Assert.AreEqual(" ", tss2.get_RunText(0));
            ttp = tss1.get_Properties(0);
            Assert.AreEqual(null, ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle));
            ttp = tss1.get_Properties(1);
            Assert.AreEqual("Emphasis", ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle));
            Assert.AreEqual("really", tss2.get_RunText(0));
        }
Esempio n. 29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Returns run textprops representing a character style of the given name.
        /// </summary>
        /// <param name="styleName">The name of the character style, or null to get props for
        /// "Default Paragraph Characters"</param>
        /// <param name="ws">The writing system</param>
        /// <returns>requested text props</returns>
        /// <remarks>If styleName is not given, the resulting props contains only the
        /// vernacular writing system.</remarks>
        /// <remarks>For char style, props should contain ws (writing system) and char style
        /// name. Without a char style, props should contain ws only.
        /// We'll use the vernacular ws.</remarks>
        /// <remarks>Useful for setting run props for an <see cref="ITsString"/>.</remarks>
        /// ------------------------------------------------------------------------------------
        public static ITsTextProps CharStyleTextProps(string styleName, int ws)
        {
            // Build props for the given writing system.
            Debug.Assert(ws != 0);
            ITsPropsBldr bldr = TsPropsBldrClass.Create();

            bldr.SetIntPropValues((int)FwTextPropType.ktptWs, ws == -1 ? -1 : 0, ws);
            // If a style name is given, set that too.
            if (!String.IsNullOrEmpty(styleName))
            {
                bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
            }
            return(bldr.GetTextProps());
        }
        public void UnkPropMisMatchedFlidTest()
        {
            // First, set up class id.
            const int hvo  = 1;
            var       clid = SilDataAccess.MetaDataCache.GetClassId("ClassE");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, clid);

            var tsPropsBuilder = TsPropsBldrClass.Create();
            var props          = tsPropsBuilder.GetTextProps();
            var tag            = SilDataAccess.MetaDataCache.GetFieldId("ClassE", "UnicodeProp4", false);

            SilDataAccess.SetUnknown(hvo, tag, props);
        }