public async Task SetDescriptionFontFamily(System.Drawing.FontFamily value) { int lineSpacing = value.GetLineSpacing(FontStyle.Regular) / value.GetEmHeight(FontStyle.Regular); await ExecuteScript( "focusDescriptionElement.style.lineHeight = " + (lineSpacing == 0 ? 1 : lineSpacing) + ";" + "focusDescriptionElement.style.fontFamily = \"" + value.Name.Replace(":", "\\:") + "\";" + "textFit(focusDescriptionElement, { alignVert: true, alignHoriz: true });"); }
public float GetHeight(float dpi) { if (unit == GraphicsUnit.World || unit == GraphicsUnit.Pixel) { return(GetHeight(Graphics.DefaultGraphics)); } else { return(fontFamily.GetLineSpacing(fontStyle) * (size / fontFamily.GetEmHeight(fontStyle)) * dpi / 72f); } }
PixelFarm.Drawing.FontInfo RegisterFont(System.Drawing.Font newFont, FontKey fontKey) { //from ... //1. http://msdn.microsoft.com/en-us/library/xwf9s90b%28v=vs.100%29.aspx //3. Font metrics from http://msdn.microsoft.com/en-us/library/xwf9s90b(VS.71).aspx //2. http://stackoverflow.com/questions/1006069/how-do-i-get-the-position-of-the-text-baseline-in-a-label-and-a-numericupdown //cellHeight = font's ascent + descent //linespacing = cellHeight + external leading //em height (size)= cellHeight - internal leading //------------------- //evaluate this font, collect font matrix in pixel mode PixelFarm.Drawing.FontInfo fontInfo; if (!_fontInfoCache.TryGetValue(newFont, out fontInfo)) { System.Drawing.FontFamily ff = newFont.FontFamily; int lineSpacing = ff.GetLineSpacing(newFont.Style); //font height is expensive call **** int fontHeight = newFont.Height; //convert descent float fontSize = newFont.Size; int fontEmHeight = newFont.FontFamily.GetEmHeight(newFont.Style); int fontAscent = newFont.FontFamily.GetCellAscent(newFont.Style); float descent = newFont.FontFamily.GetCellDescent(newFont.Style); var myFont = new PixelFarm.Drawing.WinGdi.MyFont(newFont); fontInfo = new PixelFarm.Drawing.WinGdi.MyFontInfo( myFont, fontHeight, (fontAscent * fontSize / fontEmHeight), (descent * fontSize / fontEmHeight), fontHeight * fontAscent / lineSpacing, gdiFontHelper); myFont.SetFontInfo(fontInfo); //lineSpacing * newFont.FontFamily.GetCellAscent(newFont.Style) / linespace); //1. info _fontInfoCache.Add(newFont, fontInfo); _fontInfoCacheByFontKey.Add(fontKey, fontInfo); _fontsUnmanagedCache[newFont] = newFont.ToHfont(); //2. line cache _fontHeightCache[newFont] = fontHeight; return(fontInfo); } return(fontInfo); }
void ObtainFontMetrics(Graphics g) { string infoString = ""; // enough space for one line of output int ascent; // font family ascent in design units float ascentPixel; // ascent converted to pixels int descent; // font family descent in design units float descentPixel; // descent converted to pixels int lineSpacing; // font family line spacing in design units float lineSpacingPixel; // line spacing converted to pixels FontStyle fontStyle = FontStyle.Regular; //fontStyle = FontStyle.Italic | FontStyle.Bold; FontFamily fontFamily = new FontFamily("arial"); //fontFamily = FontFamily.GenericSansSerif; Font font = new Font( fontFamily, 16, fontStyle, GraphicsUnit.Pixel); PointF pointF = new PointF(10, 10); SolidBrush solidBrush = new SolidBrush(Color.Black); // Display the font size in pixels. infoString = "font family : " + font.FontFamily.Name + " " + fontStyle + "."; g.DrawString(infoString, font, solidBrush, pointF); // Move down one line. pointF.Y += font.Height; // Display the font size in pixels. infoString = "font.Size returns " + font.Size + "."; g.DrawString(infoString, font, solidBrush, pointF); // Move down one line. pointF.Y += font.Height; // Display the font family em height in design units. infoString = "fontFamily.GetEmHeight() returns " + fontFamily.GetEmHeight(fontStyle) + "."; g.DrawString(infoString, font, solidBrush, pointF); // Move down two lines. pointF.Y += 2 * font.Height; // Display the ascent in design units and pixels. ascent = fontFamily.GetCellAscent(fontStyle); // 14.484375 = 16.0 * 1854 / 2048 ascentPixel = font.Size * ascent / fontFamily.GetEmHeight(fontStyle); infoString = "The ascent is " + ascent + " design units, " + ascentPixel + " pixels."; g.DrawString(infoString, font, solidBrush, pointF); // Move down one line. pointF.Y += font.Height; // Display the descent in design units and pixels. descent = fontFamily.GetCellDescent(fontStyle); // 3.390625 = 16.0 * 434 / 2048 descentPixel = font.Size * descent / fontFamily.GetEmHeight(fontStyle); infoString = "The descent is " + descent + " design units, " + descentPixel + " pixels."; g.DrawString(infoString, font, solidBrush, pointF); // Move down one line. pointF.Y += font.Height; // Display the line spacing in design units and pixels. lineSpacing = fontFamily.GetLineSpacing(fontStyle); // 18.398438 = 16.0 * 2355 / 2048 lineSpacingPixel = font.Size * lineSpacing / fontFamily.GetEmHeight(fontStyle); infoString = "The line spacing is " + lineSpacing + " design units, " + lineSpacingPixel + " pixels."; g.DrawString(infoString, font, solidBrush, pointF); title = "ObtainFontMetrics"; }
/// <summary> /// Connects the specifications of a font from XFont to a real glyph type face. /// </summary> void Initialize() { XFontMetrics fm = null; #if DEBUG___ FontData[] fontDataArray = FontDataStock.Global.GetFontDataList(); if (fontDataArray.Length > 0) { //// GetType(); ////#if GDI //// var x = XPrivateFontCollection.global.GlobalPrivateFontCollection; //// families = x.Families; //// bool fff = families[0].IsStyleAvailable(System.Drawing.FontStyle.Regular); //// fff.GetType(); //// this.font = new Font(families[0].Name, 12, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); //// this.font = new Font("Oblivious", 12, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); //// this.font = new Font(families[0], 12, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); //// System.Drawing.FontFamily f = new System.Drawing.FontFamily(families[0].Name); //// f.GetType(); ////#endif } #endif #if GDI if (this.font == null) { if (this.gdifamily != null) { this.font = new Font(this.gdifamily, (float)this.emSize, (System.Drawing.FontStyle) this.style, GraphicsUnit.World); this.familyName = this.gdifamily.Name; // Do we need this??? } else { // First check private fonts this.font = XPrivateFontCollection.TryFindPrivateFont(this.familyName, this.emSize, (System.Drawing.FontStyle) this.style) ?? new Font(this.familyName, (float)this.emSize, (System.Drawing.FontStyle) this.style, GraphicsUnit.World); } #if DEBUG // new Font returns MSSansSerif if the requested font was not found ... //Debug.Assert(this.familyName == this.font.FontFamily.Name); #endif } fm = Metrics; System.Drawing.FontFamily fontFamily = this.font.FontFamily; this.unitsPerEm = fm.UnitsPerEm; System.Drawing.FontFamily fontFamily2 = this.font.FontFamily; this.cellSpace = fontFamily2.GetLineSpacing(font.Style); //Debug.Assert(this.cellSpace == fm.Ascent + Math.Abs(fm.Descent) + fm.Leading, "Value differs from information retrieved from font image."); this.cellAscent = fontFamily.GetCellAscent(font.Style); #pragma warning disable 1030 #warning delTHHO //!!!delTHHO 14.08.2008 Debug.Assert(this.cellAscent == fm.Ascent, "Value differs from information retrieved from font image."); //Debug.Assert(this.cellAscent == fm.Ascent, "Value differs from information retrieved from font image."); this.cellDescent = fontFamily.GetCellDescent(font.Style); #if DEBUG int desc = Math.Abs(fm.Descent); if (this.cellDescent != desc) { Debug.Assert(false, "Value differs from information retrieved from font image."); } #endif #endif #if WPF #if !SILVERLIGHT if (this.family == null) { Debug.Assert(this.typeface == null); this.typeface = XPrivateFontCollection.TryFindTypeface(Name, this.style, out this.family); #if true if (this.typeface != null) { GlyphTypeface glyphTypeface; ICollection <Typeface> list = this.family.GetTypefaces(); foreach (Typeface tf in list) { if (!tf.TryGetGlyphTypeface(out glyphTypeface)) { Debugger.Break(); } } if (!this.typeface.TryGetGlyphTypeface(out glyphTypeface)) { throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(Name)); } } #endif } if (this.family == null) { this.family = new System.Windows.Media.FontFamily(Name); } if (typeface == null) { this.typeface = FontHelper.CreateTypeface(this.family, style); } fm = Metrics; Debug.Assert(this.unitsPerEm == 0 || this.unitsPerEm == fm.UnitsPerEm); this.unitsPerEm = fm.UnitsPerEm; //Debug.Assert(this.cellSpace == 0 || this.cellSpace == fm.Ascent + Math.Abs(fm.Descent) + fm.Leading); this.cellSpace = fm.Ascent + Math.Abs(fm.Descent) + fm.Leading; Debug.Assert(this.cellAscent == 0 || this.cellAscent == fm.Ascent); this.cellAscent = fm.Ascent; Debug.Assert(this.cellDescent == 0 || this.cellDescent == Math.Abs(fm.Descent)); this.cellDescent = Math.Abs(fm.Descent); #else if (fm != null) { fm.GetType(); } #endif #endif }
/// <summary> /// Font object /// </summary> /// <param name="graphics">GDI+ drawing surface</param> /// <param name="fontFamilly">Font familly</param> /// <param name="style">Font style</param> /// <param name="name">Font name</param> public PdfFont(Graphics graphics, FontFamily fontFamilly, FontStyle style, string name) { this.CodeName = "/F" + id++; this.Name = name; this.HeightTs = (short)((fontFamilly.GetLineSpacing(style) * 1000) / fontFamilly.GetEmHeight(style)); this.WidthsTs = GetCharsWidth(graphics, fontFamilly, style); }
public void FontFamily_String () { HostIgnoreList.CheckTest ("MonoTests.System.Drawing.FontFamilyTest.FontFamily_String"); FontFamily ff = new FontFamily (name); CheckMono (ff); FontStyle style = FontStyle.Bold; Assert.AreEqual (ff.Name, ff.GetName (0), "GetName"); Assert.IsTrue ((ff.GetCellAscent (style) > 0), "GetCellAscent"); Assert.IsTrue ((ff.GetCellDescent (style) > 0), "GetCellDescent"); Assert.IsTrue ((ff.GetEmHeight (style) > 0), "GetEmHeight"); Assert.IsTrue ((ff.GetLineSpacing (style) > 0), "GetLineSpacing"); Assert.IsTrue (ff.IsStyleAvailable (style), "IsStyleAvailable"); }
public float GetHeight(float dpi) { return((FontFamily.GetLineSpacing(Style) / FontFamily.GetEmHeight(Style)) * (SizeInPoints / _screenResolutionConverter [(int)Unit]) * dpi); }
private void InitializeSizes() { _fretWidth = 4 * _size; _nutHeight = _fretWidth / 2f; _lineWidth = (int)Math.Ceiling(_size * 0.31); _dotWidth = (int)Math.Ceiling(0.9 * _fretWidth); _markerWidth = 0.7f * _fretWidth; _boxWidth = 5 * _fretWidth + 6 * _lineWidth; _boxHeight = FRET_COUNT * (_fretWidth + _lineWidth) + _lineWidth; //Find out font sizes FontFamily family = new FontFamily(FONT_NAME); float perc = family.GetCellAscent(FontStyle.Regular) / (float)family.GetLineSpacing(FontStyle.Regular); _fretFontSize = _fretWidth / perc; _fingerFontSize = _fretWidth * 0.8f; _nameFontSize = _fretWidth * 2f / perc; _superScriptFontSize = 0.7f * _nameFontSize; if (_size == 1) { _nameFontSize += 2; _fingerFontSize += 2; _fretFontSize += 2; _superScriptFontSize += 2; } _xstart = _fretWidth; _ystart = (float) Math.Round(0.2f * _superScriptFontSize + _nameFontSize + _nutHeight + 1.7f * _markerWidth); _imageWidth = (int)(_boxWidth + 5 * _fretWidth); _imageHeight = (int)(_boxHeight + _ystart + _fretWidth + _fretWidth); _signWidth = (int)(_fretWidth * 0.75); _signRadius = _signWidth / 2; }