コード例 #1
0
        /// <summary>
        /// Gets the character render properties for the given style name and writing system.
        /// </summary>
        /// <param name="styleName">The style name.</param>
        /// <param name="styleSheet">The stylesheet.</param>
        /// <param name="hvoWs">The HVO of the WS.</param>
        /// <param name="writingSystemFactory">The writing system factory.</param>
        /// <returns>The character render properties.</returns>
        public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet,
                                                        int hvoWs, ILgWritingSystemFactory writingSystemFactory)
        {
            if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs)))
            {
                try
                {
                    throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent. Call an expert (JohnT)");
                }
                catch (ArgumentException e)
                {
                    Logger.WriteError(e);
                    Debug.Fail("This is a hard-to-reproduce scenario (TE-6891) where writing system and factory are inconsistent. Call an expert (JohnT) while you have this Assert active!");
                    hvoWs = writingSystemFactory.UserWs;
                }
            }

            IVwPropertyStore vwps = VwPropertyStoreClass.Create();

            vwps.Stylesheet           = styleSheet;
            vwps.WritingSystemFactory = writingSystemFactory;

            ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();

            ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
            ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs);
            ITsTextProps ttp = ttpBldr.GetTextProps();

            LgCharRenderProps chrps = vwps.get_ChrpFor(ttp);
            IWritingSystem    ws    = writingSystemFactory.get_EngineOrNull(hvoWs);

            ws.InterpretChrp(ref chrps);
            return(chrps);
        }
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Set up a Chrp consistent with the current style sheet
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void MakeCharProps()
        {
            LangProject lp = m_Parent.LangProj;
            // Make a text property with the named style.
            ITsPropsBldr tsPropsBuilder = TsPropsBldrClass.Create();

            tsPropsBuilder.SetStrPropValue((int)VwStyleProperty.kspNamedStyle,
                                           m_FieldSpec.Style);
            tsPropsBuilder.SetIntPropValues((int)FwTextPropType.ktptWs,
                                            (int)FwTextPropVar.ktpvDefault, m_ws);
            ITsTextProps tsTextProps = tsPropsBuilder.GetTextProps();

            // Fill out the LgCharRenderProps.
            ILgWritingSystemFactory lgEncFactory;
            IVwPropertyStore        vwPropertyStore =
                VwPropertyStoreClass.Create();
            IVwStylesheet vwStylesheet = DeStyleSheet;

            if (vwStylesheet != null)
            {
                vwPropertyStore.Stylesheet = vwStylesheet;
            }
            if (lp != null)
            {
                lgEncFactory = lp.Cache.LanguageWritingSystemFactoryAccessor;
            }
            else
            {
                // Get default registry-based factory.
                lgEncFactory = LgWritingSystemFactoryClass.Create();
            }
            Debug.Assert(lgEncFactory != null);
            vwPropertyStore.WritingSystemFactory = lgEncFactory;
            m_CharacterRenderingProps            = vwPropertyStore.get_ChrpFor(tsTextProps);
            IWritingSystem writingSystem = lgEncFactory.get_EngineOrNull(m_CharacterRenderingProps.ws);

            Debug.Assert(writingSystem != null);
            writingSystem.InterpretChrp(ref m_CharacterRenderingProps);

            // For our purposes here, we don't want transparent backgrounds.
            if ((int)m_CharacterRenderingProps.clrBack == (int)FwTextColor.kclrTransparent)
            {
                m_CharacterRenderingProps.clrBack = (uint)SystemColors.Window.ToArgb();
            }

            // Make a brush for the background.
            m_BackgroundBrush = new SolidBrush(Color.FromArgb((int)m_CharacterRenderingProps.clrBack));
        }
コード例 #3
0
        public void TestOverrideFontForWritingSystem_ForStyleWithNullProps()
        {
            TestFwStylesheet stylesheet = new TestFwStylesheet();
            int hvoNewStyle1            = stylesheet.MakeNewStyle();

            stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, 0, 0, false, false, null);

            ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();

            try
            {
                wsf.BypassInstall = true;
                IWritingSystem ws          = wsf.get_Engine("de");
                int            hvoGermanWs = ws.WritingSystem;
                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);
            }
            finally
            {
                wsf.Shutdown();
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets the character render properties for the given style name and writing system.
        /// </summary>
        /// <param name="styleName">The style name.</param>
        /// <param name="styleSheet">The stylesheet.</param>
        /// <param name="hvoWs">The HVO of the WS.</param>
        /// <param name="writingSystemFactory">The writing system factory.</param>
        /// <returns>The character render properties.</returns>
        public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet,
                                                        int hvoWs, ILgWritingSystemFactory writingSystemFactory)
        {
            if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs)))
            {
                try
                {
                    //You may have forgotten to set the WritingSystemFactory in a recently added custom control?
                    throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent.");
                }
                catch (ArgumentException e)
                {
                    Logger.WriteError(e);
                    var msg = e.Message + " If we aren't called from a Widget, "
                              + "call an expert (JohnT) while you have this Assert active!";
                    Debug.Fail(msg);
                    hvoWs = writingSystemFactory.UserWs;
                }
            }

            IVwPropertyStore vwps = VwPropertyStoreClass.Create();

            vwps.Stylesheet           = styleSheet;
            vwps.WritingSystemFactory = writingSystemFactory;

            ITsPropsBldr ttpBldr = TsStringUtils.MakePropsBldr();

            ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName);
            ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs);
            ITsTextProps ttp = ttpBldr.GetTextProps();

            LgCharRenderProps chrps = vwps.get_ChrpFor(ttp);
            ILgWritingSystem  ws    = writingSystemFactory.get_EngineOrNull(hvoWs);

            ws.InterpretChrp(ref chrps);
            return(chrps);
        }
コード例 #5
0
        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);
        }