/// <summary>
 /// setup the given control's WritingSystem[Factory] and Stylesheet related functionality
 /// </summary>
 /// <param name="control"></param>
 /// <param name="cache"></param>
 /// <param name="mediator">used to get stylesheet</param>
 /// <param name="wsDefault">used to set WritingSytemCode and Font for the control</param>
 public static void SetupWritingSystemAndStylesheetInfo(IWritingSystemAndStylesheet control,
                                                        FdoCache cache, Mediator mediator, int wsDefault)
 {
     control.WritingSystemFactory = cache.WritingSystemFactory;
     control.WritingSystemCode    = wsDefault;
     control.Font       = new System.Drawing.Font(cache.ServiceLocator.WritingSystemManager.Get(wsDefault).DefaultFontName, 10);
     control.StyleSheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// setup the given control's WritingSystem[Factory] and Stylesheet related functionality
 /// </summary>
 /// <param name="control"></param>
 /// <param name="cache"></param>
 /// <param name="mediator">used to get stylesheet</param>
 /// <param name="wsDefault">used to set WritingSytemCode and Font for the control</param>
 public static void SetupWritingSystemAndStylesheetInfo(IWritingSystemAndStylesheet control,
                                                        FdoCache cache, Mediator mediator, int wsDefault)
 {
     control.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor;
     control.WritingSystemCode    = wsDefault;
     control.Font       = new System.Drawing.Font(cache.LangProject.GetDefaultFontForWs(wsDefault), 10);
     control.StyleSheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// setup the given control's WritingSystem[Factory] and Stylesheet related functionality
 /// </summary>
 /// <param name="propertyTable"></param>
 /// <param name="control"></param>
 /// <param name="cache"></param>
 /// <param name="wsDefault">used to set WritingSytemCode and Font for the control</param>
 public static void SetupWritingSystemAndStylesheetInfo(PropertyTable propertyTable, IWritingSystemAndStylesheet control,
                                                        LcmCache cache, int wsDefault)
 {
     control.WritingSystemFactory = cache.WritingSystemFactory;
     control.WritingSystemCode    = wsDefault;
     control.Font       = new System.Drawing.Font(cache.ServiceLocator.WritingSystemManager.Get(wsDefault).DefaultFontName, 10);
     control.StyleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(propertyTable);
 }
Ejemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the font for the specified TsString and writing system.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private Font GetValuesFont(ITsString tss, int ws)
        {
            if (tss == null || tss.RunCount == 0 || m_cache == null)
            {
                return(null);
            }

            ITsTextProps ttp = tss.get_Properties(0);

            // Figure out what the font size of the string should be.
            int var;
            int fontSize = ttp.GetIntPropValues((int)FwTextPropType.ktptFontSize, out var);

            if (fontSize == -1)
            {
                fontSize = FontInfo.kDefaultFontSize;
            }
            else
            {
                // Font size, at this point, is in millipoints, so convert it to points.
                fontSize /= 1000;
            }
            // Figure out what the style name is and use it to get the font face name.
            string styleName = ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
            string faceName;

            if (m_styleSheet != null)
            {
                using (var font = FontHeightAdjuster.GetFontForStyle(styleName, m_styleSheet, ws, m_cache.WritingSystemFactory))
                {
                    faceName = font == null ? null : font.Name;
                }
            }
            else
            {
                // When there is no stylesheet, use the default serif font for the writing
                // system.
                faceName = m_cache.ServiceLocator.WritingSystemManager.Get(ws).DefaultFontName;
            }

            if (string.IsNullOrEmpty(faceName))
            {
                return(null);
            }

            // Check if the font is in our font cache. If not, add it.
            string key = string.Format("{0}{1}", faceName, fontSize);
            Font   fnt;

            if (!m_fontCache.TryGetValue(key, out fnt))
            {
                fnt = new Font(faceName, fontSize, GraphicsUnit.Point);
                m_fontCache[key] = fnt;
            }

            return(fnt);
        }
Ejemplo n.º 5
0
 public void TestGetFontHeightForStyle()
 {
     Assert.AreEqual(13000, FontHeightAdjuster.GetFontHeightForStyle("StyleA",
                                                                     m_stylesheet, m_hvoGermanWs, m_wsManager));
     Assert.AreEqual(21000, FontHeightAdjuster.GetFontHeightForStyle("StyleA",
                                                                     m_stylesheet, m_hvoEnglishWs, m_wsManager));
     Assert.AreEqual(56000, FontHeightAdjuster.GetFontHeightForStyle("StyleB",
                                                                     m_stylesheet, m_hvoGermanWs, m_wsManager));
     Assert.AreEqual(20000, FontHeightAdjuster.GetFontHeightForStyle("StyleB",
                                                                     m_stylesheet, m_hvoEnglishWs, m_wsManager));
 }
Ejemplo n.º 6
0
        public void TestGetAdjustedTsString()
        {
            ITsStrBldr   strBldr         = TsStrBldrClass.Create();
            ITsStrBldr   strBldrExpected = TsStrBldrClass.Create();
            ITsPropsBldr propsBldr       = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleA");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoGermanWs);
            strBldr.ReplaceRgch(0, 0, "Hello People", 12, propsBldr.GetTextProps());
            strBldrExpected.ReplaceRgch(0, 0, "Hello People", 12, propsBldr.GetTextProps());

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleA");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoEnglishWs);
            strBldr.ReplaceRgch(0, 0, "Hello numero dos", 16, propsBldr.GetTextProps());
            var propsBldrExpected = propsBldr;

            propsBldrExpected.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                               (int)FwTextPropVar.ktpvMilliPoint, 20500);
            strBldrExpected.ReplaceRgch(0, 0, "Hello numero dos", 16, propsBldrExpected.GetTextProps());

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleB");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoGermanWs);
            strBldr.ReplaceRgch(0, 0, "3 Hello", 7, propsBldr.GetTextProps());
            propsBldrExpected = propsBldr;
            propsBldrExpected.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                               (int)FwTextPropVar.ktpvMilliPoint, ExpectedFontHeightForArial);
            strBldrExpected.ReplaceRgch(0, 0, "3 Hello", 7, propsBldrExpected.GetTextProps());

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleB");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoEnglishWs);
            strBldr.ReplaceRgch(0, 0, "This is 4", 9, propsBldr.GetTextProps());
            strBldrExpected.ReplaceRgch(0, 0, "This is 4", 9, propsBldr.GetTextProps());

            var tss = FontHeightAdjuster.GetAdjustedTsString(strBldr.GetString(), 23000, m_stylesheet, m_wsManager);
            var propsWithWiggleRoom = new Dictionary <int, int>();

            if (GetUbuntuVersion() == 14)
            {
                propsWithWiggleRoom[(int)FwTextPropType.ktptFontSize] = 1000;                 // millipoints. for some reason, the result is sometimes a point smaller on Trusty
            }
            AssertEx.AreTsStringsEqual(strBldrExpected.GetString(), tss, propsWithWiggleRoom);
        }
Ejemplo n.º 7
0
        public void TestGetAdjustedTsString()
        {
            ITsStrBldr   strBldr         = TsStrBldrClass.Create();
            ITsStrBldr   strBldrExpected = TsStrBldrClass.Create();
            ITsPropsBldr propsBldr       = TsPropsBldrClass.Create();
            ITsPropsBldr propsBldrExpected;

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleA");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoGermanWs);
            strBldr.ReplaceRgch(0, 0, "Hello People", 12, propsBldr.GetTextProps());
            strBldrExpected.ReplaceRgch(0, 0, "Hello People", 12, propsBldr.GetTextProps());

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleA");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoEnglishWs);
            strBldr.ReplaceRgch(0, 0, "Hello numero dos", 16, propsBldr.GetTextProps());
            propsBldrExpected = propsBldr;
            propsBldrExpected.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                               (int)FwTextPropVar.ktpvMilliPoint, 20500);
            strBldrExpected.ReplaceRgch(0, 0, "Hello numero dos", 16, propsBldrExpected.GetTextProps());

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleB");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoGermanWs);
            strBldr.ReplaceRgch(0, 0, "3 Hello", 7, propsBldr.GetTextProps());
            propsBldrExpected = propsBldr;
            propsBldrExpected.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                               (int)FwTextPropVar.ktpvMilliPoint, GetExpectedFontHeightForArial());
            strBldrExpected.ReplaceRgch(0, 0, "3 Hello", 7, propsBldrExpected.GetTextProps());

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleB");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoEnglishWs);
            strBldr.ReplaceRgch(0, 0, "This is 4", 9, propsBldr.GetTextProps());
            strBldrExpected.ReplaceRgch(0, 0, "This is 4", 9, propsBldr.GetTextProps());

            ITsString tss = FontHeightAdjuster.GetAdjustedTsString(strBldr.GetString(), 23000, m_stylesheet, m_wsManager);

            AssertEx.AreTsStringsEqual(strBldrExpected.GetString(), tss);
        }