private void CreateNativeFont(FontFamily familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont ) { // convert to 96 Dpi to be consistent with Windows var dpiSize = emSize * dpiScale; try { nativeFont = new CTFont(familyName.NativeDescriptor,dpiSize); } catch { nativeFont = new CTFont("Helvetica",dpiSize); } CTFontSymbolicTraits tMask = CTFontSymbolicTraits.None; if ((style & FontStyle.Bold) == FontStyle.Bold) tMask |= CTFontSymbolicTraits.Bold; if ((style & FontStyle.Italic) == FontStyle.Italic) tMask |= CTFontSymbolicTraits.Italic; strikeThrough = (style & FontStyle.Strikeout) == FontStyle.Strikeout; underLine = (style & FontStyle.Underline) == FontStyle.Underline; var nativeFont2 = nativeFont.WithSymbolicTraits(dpiSize,tMask,tMask); if (nativeFont2 != null) nativeFont = nativeFont2; bold = (nativeFont.SymbolicTraits & CTFontSymbolicTraits.Bold) == CTFontSymbolicTraits.Bold; italic = (nativeFont.SymbolicTraits & CTFontSymbolicTraits.Italic) == CTFontSymbolicTraits.Italic; sizeInPoints = emSize; this.unit = unit; // FIXME // I do not like the hard coded 72 but am just trying to boot strap the Font class right now size = ConversionHelpers.GraphicsUnitConversion(GraphicsUnit.Point, unit, 72.0f, sizeInPoints); }
static internal CTFont CreateFont (string familyName, float emSize, FontStyle style, byte gdiCharSet, bool gdiVerticalFont ) { if (emSize <= 0) throw new ArgumentException("emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.","emSize"); CTFont nativeFont; // convert to 96 Dpi to be consistent with Windows var dpiSize = emSize * dpiScale; try { nativeFont = new CTFont(familyName,dpiSize); } catch { nativeFont = new CTFont("Helvetica",dpiSize); } CTFontSymbolicTraits tMask = CTFontSymbolicTraits.None; if ((style & FontStyle.Bold) == FontStyle.Bold) tMask |= CTFontSymbolicTraits.Bold; if ((style & FontStyle.Italic) == FontStyle.Italic) tMask |= CTFontSymbolicTraits.Italic; strikeThrough = (style & FontStyle.Strikeout) == FontStyle.Strikeout; underLine = (style & FontStyle.Underline) == FontStyle.Underline; var nativeFont2 = nativeFont.WithSymbolicTraits(dpiSize,tMask,tMask); if (nativeFont2 != null) nativeFont = nativeFont2; return nativeFont; }
private int GetNativeMetric(Metric metric, FontStyle style) { // we are going to actually have to create a font object here // will not create an actual variable for this yet. We may // want to do this in the future so that we do not have to keep // creating it over and over again. CTFontSymbolicTraits tMask = CTFontSymbolicTraits.None; if ((style & FontStyle.Bold) == FontStyle.Bold) tMask |= CTFontSymbolicTraits.Bold; if ((style & FontStyle.Italic) == FontStyle.Italic) tMask |= CTFontSymbolicTraits.Italic; var font = new CTFont (nativeFontDescriptor,0); font = font.WithSymbolicTraits (0, tMask, tMask); switch (metric) { case Metric.EMHeight: return (int)font.UnitsPerEmMetric; case Metric.CellAscent: return (int)Math.Round(font.AscentMetric / font.Size * font.UnitsPerEmMetric); case Metric.CellDescent: return (int)Math.Round(font.DescentMetric / font.Size * font.UnitsPerEmMetric); case Metric.LineSpacing: float lineHeight = 0; lineHeight += font.AscentMetric; lineHeight += font.DescentMetric; lineHeight += font.LeadingMetric; return (int)Math.Round(lineHeight / font.Size * font.UnitsPerEmMetric); } return 0; }
private bool NativeStyleAvailable(FontStyle style) { // we are going to actually have to create a font object here // will not create an actual variable for this yet. We may // want to do this in the future so that we do not have to keep // creating it over and over again. var font = new CTFont (nativeFontDescriptor,0); switch (style) { case FontStyle.Bold: var tMaskBold = CTFontSymbolicTraits.None; tMaskBold |= CTFontSymbolicTraits.Bold; var bFont = font.WithSymbolicTraits (0, tMaskBold, tMaskBold); if (bFont == null) return false; var bold = (bFont.SymbolicTraits & CTFontSymbolicTraits.Bold) == CTFontSymbolicTraits.Bold; return bold; case FontStyle.Italic: //return (font.SymbolicTraits & CTFontSymbolicTraits.Italic) == CTFontSymbolicTraits.Italic; var tMaskItalic = CTFontSymbolicTraits.None; tMaskItalic |= CTFontSymbolicTraits.Italic; var iFont = font.WithSymbolicTraits (0, tMaskItalic, tMaskItalic); if (iFont == null) return false; var italic = (iFont.SymbolicTraits & CTFontSymbolicTraits.Italic) == CTFontSymbolicTraits.Italic; return italic; case FontStyle.Regular: // Verify if this is correct somehow - we may need to add Bold here as well not sure if ((font.SymbolicTraits & CTFontSymbolicTraits.Condensed) == CTFontSymbolicTraits.Condensed || (font.SymbolicTraits & CTFontSymbolicTraits.Expanded) == CTFontSymbolicTraits.Expanded) return false; else return true; case FontStyle.Underline: return font.UnderlineThickness > 0; case FontStyle.Strikeout: // not implemented yet return false; } return false; }
public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont ) { if (emSize <= 0) throw new ArgumentException("emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.","emSize"); // convert to 96 Dpi to be consistent with Windows var dpiSize = emSize * dpiScale; try { nativeFont = new CTFont(familyName,dpiSize); } catch { //nativeFont = new CTFont("Lucida Grande",emSize); nativeFont = new CTFont("Helvetica",dpiSize); } CTFontSymbolicTraits tMask = CTFontSymbolicTraits.None; if ((style & FontStyle.Bold) == FontStyle.Bold) tMask |= CTFontSymbolicTraits.Bold; if ((style & FontStyle.Italic) == FontStyle.Italic) tMask |= CTFontSymbolicTraits.Italic; strikeThrough = (style & FontStyle.Strikeout) == FontStyle.Strikeout; underLine = (style & FontStyle.Underline) == FontStyle.Underline; var nativeFont2 = nativeFont.WithSymbolicTraits(dpiSize,tMask,tMask); if (nativeFont2 != null) nativeFont = nativeFont2; sizeInPoints = emSize; this.unit = unit; // FIXME // I do not like the hard coded 72 but am just trying to boot strap the Font class right now size = ConversionHelpers.GraphicsUnitConversion(GraphicsUnit.Point, unit, 72.0f, sizeInPoints); }