static List <CharacterData> CreateCharacterData( string fontName, FontSlant fontSlant, FontWeight fontWeight, double fontSize, List <char> fontChars, out double bitmapWidth, out double bitmapHeight) { List <CharacterData> cds = new List <CharacterData>(); using (ImageSurface surface = new ImageSurface(Format.Argb32, 256, 256)) { using (Context g = new Context(surface)) { SetupContext(g, fontName, fontSlant, fontWeight, fontSize); FontExtents fe = g.FontExtents; double x = 0; double y = 0; for (int i = 0; i < fontChars.Count; i++) { CharacterData cd = new CharacterData(); cds.Add(cd); cd.Character = new String(fontChars[i], 1); TextExtents te = g.TextExtents(cd.Character); double aliasSpace; if (cd.Character == " ") { aliasSpace = 0.0; } else { aliasSpace = 1.0; } cd.Bearing = new PointD(-te.XBearing + aliasSpace, -te.YBearing + aliasSpace); cd.Location = new Cairo.Rectangle(x, 0, te.Width + aliasSpace * 2, te.Height + aliasSpace * 2); cd.Cropping = new Cairo.Rectangle(0, fe.Ascent + aliasSpace * 2 - cd.Bearing.Y, te.XAdvance + aliasSpace, cd.Location.Height); cd.Kerning = new Vector3(0, (float)cd.Location.Width, (float)(cd.Bearing.X + cd.Cropping.Width - cd.Location.Width)); x += cd.Location.Width; if (cd.Location.Height > y) { y = cd.Location.Height; } } bitmapWidth = x; bitmapHeight = y; } } return(cds); }
public static Rectangle DrawText(this Context g, PointD p, string family, FontSlant slant, FontWeight weight, double size, Color color, string text) { g.Save(); g.MoveTo(p.X, p.Y); g.SelectFontFace(family, slant, weight); g.SetFontSize(size); g.Color = color; TextExtents te = g.TextExtents(text); //TODO alignment // Center text on bottom /*// TODO cut the string in char array and for each center on bottom * TextExtents te = g.TextExtents("a"); * cr.MoveTo(0.5 - te.Width / 2 - te.XBearing, 0.5 - te.Height / 2 - te.YBearing); */ //// Draw g.ShowText(text); //or //g.TextPath(text); //g.Fill(); g.Restore(); return(new Rectangle(te.XBearing, te.YBearing, te.Width, te.Height)); }
public Font(string family, float size, FontWeight weight, FontSlant style) { this.Family = family; this.Size = size; this.Weight = weight; this.Style = style; }
public static Rectangle DrawText(this Context g, PointD p, string family, FontSlant slant, FontWeight weight, double size, Color color, string text, bool antiAliasing) { g.Save(); g.MoveTo(p.X, p.Y); g.Color = color; g.Antialias = antiAliasing ? Antialias.Subpixel : Antialias.None; Pango.Layout layout = Pango.CairoHelper.CreateLayout(g); Pango.FontDescription fd = new Pango.FontDescription(); fd.Family = family; fd.Style = CairoToPangoSlant(slant); fd.Weight = CairoToPangoWeight(weight); fd.AbsoluteSize = size * Pango.Scale.PangoScale; layout.FontDescription = fd; layout.SetText(text); Pango.CairoHelper.ShowLayoutLine(g, layout.Lines[0]); Pango.Rectangle unused = Pango.Rectangle.Zero; Pango.Rectangle te = Pango.Rectangle.Zero; layout.GetExtents(out unused, out te); (layout as IDisposable).Dispose(); g.Restore(); return(new Rectangle(te.X, te.Y, te.Width, te.Height)); }
public FontInfo(string family, FontSlant slant, FontWeight weight, double scale, double lineSpacing, Gdk.Color color, bool underline = false) { Family = family; Slant = slant; Weight = weight; Scale = scale; LineSpacing = lineSpacing; Color = new RGBA(color); Underline = underline; }
static BitmapContent CreateBitmapContent( double bitmapWidth, double bitmapHeight, string fontName, FontSlant fontSlant, FontWeight fontWeight, double fontSize, List <CharacterData> cds, ParsedPath pngFile) { using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)bitmapWidth, (int)bitmapHeight)) { using (Context g = new Context(surface)) { SetupContext(g, fontName, fontSlant, fontWeight, fontSize); double x = 0; for (int i = 0; i < cds.Count; i++) { CharacterData cd = cds[i]; if (cd.Location.Width == 0) { continue; } g.MoveTo(x + cd.Bearing.X, cd.Bearing.Y); g.ShowText(cd.Character); #if DEBUG g.Save(); g.Color = new Color(1.0, 0, 0, 0.5); g.Antialias = Antialias.None; g.LineWidth = 1; g.MoveTo(x + 0.5, 0.5); g.LineTo(x + cd.Location.Width - 0.5, 0); g.LineTo(x + cd.Location.Width - 0.5, cd.Location.Height - 0.5); g.LineTo(x + 0.5, cd.Location.Height - 0.5); g.LineTo(x + 0.5, 0.5); g.Stroke(); g.Restore(); #endif x += cd.Location.Width; } g.Restore(); } if (pngFile != null) { surface.WriteToPng(pngFile); } return(new BitmapContent(SurfaceFormat.Color, surface.Width, surface.Height, surface.Data)); } }
static void SetupContext(Context g, string fontName, FontSlant fontSlant, FontWeight fontWeight, double fontSize) { FontOptions fo = new FontOptions(); fo.Antialias = Antialias.Gray; fo.HintStyle = HintStyle.Full; g.FontOptions = fo; g.SelectFontFace(fontName, fontSlant, fontWeight); g.SetFontSize(fontSize); g.Color = new Color(1.0, 1.0, 1.0); }
private static Pango.Style CairoToPangoSlant(FontSlant slant) { switch (slant) { case FontSlant.Italic: return(Pango.Style.Italic); case FontSlant.Oblique: return(Pango.Style.Oblique); default: return(Pango.Style.Normal); } }
private SpriteFontContent CreateSpriteFontContent( string fontName, double fontSize, FontSlant fontSlant, FontWeight fontWeight, int spacing, char?defaultChar, List <char> fontChars, ParsedPath pngFile) { double bitmapWidth = 0; double bitmapHeight = 0; List <CharacterData> cds = CreateCharacterData( fontName, fontSlant, fontWeight, fontSize, fontChars, out bitmapWidth, out bitmapHeight); BitmapContent bitmapContent = CreateBitmapContent( bitmapWidth, bitmapHeight, fontName, fontSlant, fontWeight, fontSize, cds, pngFile); List <Microsoft.Xna.Framework.Rectangle> locations = new List <Microsoft.Xna.Framework.Rectangle>(); List <Microsoft.Xna.Framework.Rectangle> croppings = new List <Microsoft.Xna.Framework.Rectangle>(); List <Vector3> kernings = new List <Vector3>(); foreach (var cd in cds) { locations.Add(new Microsoft.Xna.Framework.Rectangle( (int)cd.Location.X, (int)cd.Location.Y, (int)cd.Location.Width, (int)cd.Location.Height)); croppings.Add(new Microsoft.Xna.Framework.Rectangle( (int)cd.Cropping.X, (int)cd.Cropping.Y, (int)cd.Location.Width, (int)cd.Location.Height)); kernings.Add(new Vector3( (float)Math.Round(cd.Kerning.X, MidpointRounding.AwayFromZero), (float)Math.Round(cd.Kerning.Y, MidpointRounding.AwayFromZero), (float)Math.Round(cd.Kerning.Z, MidpointRounding.AwayFromZero))); } int verticalSpacing = 0; float horizontalSpacing = spacing; return(new SpriteFontContent( new Texture2DContent(bitmapContent), locations, fontChars, croppings, verticalSpacing, horizontalSpacing, kernings, defaultChar)); }
public void Compile() { ParsedPath spriteFontFileName = Target.InputFiles.Where(f => f.Extension == ".spritefont").First(); ParsedPath stringsFileName = Target.InputFiles.Where(f => f.Extension == ".strings").First(); ParsedPath xnbFileName = Target.OutputFiles.Where(f => f.Extension == ".xnb").First(); SpriteFontFile sff = SpriteFontFileReader.ReadFile(spriteFontFileName); StringsFileV1 sf = StringsFileReaderV1.ReadFile(stringsFileName); HashSet <char> hs = new HashSet <char>(); foreach (var item in sf.Strings) { for (int i = 0; i < item.Value.Length; i++) { hs.Add(item.Value[i]); } } foreach (var region in sff.CharacterRegions) { for (char c = region.Start; c <= region.End; c++) { hs.Add(c); } } List <char> fontChars = hs.OrderBy(c => c).ToList(); FontSlant fontSlant = (sff.Style == SpriteFontFile.FontStyle.Italic ? FontSlant.Italic : FontSlant.Normal); FontWeight fontWeight = (sff.Style == SpriteFontFile.FontStyle.Bold ? FontWeight.Bold : FontWeight.Normal); ParsedPath pngFile = xnbFileName.WithExtension(".png"); SpriteFontContent sfc = CreateSpriteFontContent( sff.FontName, sff.Size, fontSlant, fontWeight, sff.Spacing, sff.DefaultCharacter, fontChars, pngFile); if (!Directory.Exists(xnbFileName.VolumeAndDirectory)) { Directory.CreateDirectory(xnbFileName.VolumeAndDirectory); } XnbFileWriterV5.WriteFile(sfc, xnbFileName); }
internal IntPtr _create (string family, FontSlant fcslant, FontWeight fcweight) { IntPtr font = IntPtr.Zero; IntPtr pattern = IntPtr.Zero; IntPtr library = IntPtr.Zero; int error = 0; pattern = FontConfig.FcPatternCreate (); if (pattern == IntPtr.Zero) return font; FontConfig.FcPatternAddString (pattern, FontConfig.FC_FAMILY, family); FontConfig.FcPatternAddInteger (pattern, FontConfig.FC_SLANT, (int) fcslant); FontConfig.FcPatternAddInteger (pattern, FontConfig.FC_WEIGHT, (int) fcweight); error = FreeType.FT_Init_FreeType (out library); if (error != 0) { FontConfig.FcPatternDestroy (pattern); return font; } font = CairoAPI.cairo_ft_font_create (library, pattern); if (font == IntPtr.Zero) return font; /* ft_font = (cairo_ft_font_t *) font; ft_font->owns_ft_library = 1; FT_Set_Char_Size (ft_font->face, DOUBLE_TO_26_6 (1.0), DOUBLE_TO_26_6 (1.0), 0, 0);*/ FontConfig.FcPatternDestroy (pattern); return font; }
public static Rectangle DrawText(this Context g, PointD p, string family, FontSlant slant, FontWeight weight, double size, Color color, string text, bool antiAliasing) { g.Save (); g.MoveTo (p.X, p.Y); g.Color = color; g.Antialias = antiAliasing ? Antialias.Subpixel : Antialias.None; Pango.Layout layout = Pango.CairoHelper.CreateLayout (g); Pango.FontDescription fd = new Pango.FontDescription (); fd.Family = family; fd.Style = CairoToPangoSlant (slant); fd.Weight = CairoToPangoWeight (weight); fd.AbsoluteSize = size * Pango.Scale.PangoScale; layout.FontDescription = fd; layout.SetText (text); Pango.CairoHelper.ShowLayoutLine (g, layout.Lines[0]); Pango.Rectangle unused = Pango.Rectangle.Zero; Pango.Rectangle te = Pango.Rectangle.Zero; layout.GetExtents (out unused, out te); (layout as IDisposable).Dispose (); g.Restore (); return new Rectangle (te.X, te.Y, te.Width, te.Height); }
private static Pango.Style CairoToPangoSlant(FontSlant slant) { switch (slant) { case FontSlant.Italic: return Pango.Style.Italic; case FontSlant.Oblique: return Pango.Style.Oblique; default: return Pango.Style.Normal; } }
static List<CharacterData> CreateCharacterData( string fontName, FontSlant fontSlant, FontWeight fontWeight, double fontSize, List<char> fontChars, out double bitmapWidth, out double bitmapHeight) { List<CharacterData> cds = new List<CharacterData>(); using (ImageSurface surface = new ImageSurface(Format.Argb32, 256, 256)) { using (Context g = new Context(surface)) { SetupContext(g, fontName, fontSlant, fontWeight, fontSize); FontExtents fe = g.FontExtents; double x = 0; double y = 0; for (int i = 0; i < fontChars.Count; i++) { CharacterData cd = new CharacterData(); cds.Add(cd); cd.Character = new String(fontChars[i], 1); TextExtents te = g.TextExtents(cd.Character); double aliasSpace; if (cd.Character == " ") aliasSpace = 0.0; else aliasSpace = 1.0; cd.Bearing = new PointD(-te.XBearing + aliasSpace, -te.YBearing + aliasSpace); cd.Location = new Cairo.Rectangle(x, 0, te.Width + aliasSpace * 2, te.Height + aliasSpace * 2); cd.Cropping = new Cairo.Rectangle(0, fe.Ascent + aliasSpace * 2 - cd.Bearing.Y, te.XAdvance + aliasSpace, cd.Location.Height); cd.Kerning = new Vector3(0, (float)cd.Location.Width, (float)(cd.Bearing.X + cd.Cropping.Width - cd.Location.Width)); x += cd.Location.Width; if (cd.Location.Height > y) y = cd.Location.Height; } bitmapWidth = x; bitmapHeight = y; } } return cds; }
private SpriteFontContent CreateSpriteFontContent( string fontName, double fontSize, FontSlant fontSlant, FontWeight fontWeight, int spacing, char? defaultChar, List<char> fontChars, ParsedPath pngFile) { double bitmapWidth = 0; double bitmapHeight = 0; List<CharacterData> cds = CreateCharacterData( fontName, fontSlant, fontWeight, fontSize, fontChars, out bitmapWidth, out bitmapHeight); BitmapContent bitmapContent = CreateBitmapContent( bitmapWidth, bitmapHeight, fontName, fontSlant, fontWeight, fontSize, cds, pngFile); List<Microsoft.Xna.Framework.Rectangle> locations = new List<Microsoft.Xna.Framework.Rectangle>(); List<Microsoft.Xna.Framework.Rectangle> croppings = new List<Microsoft.Xna.Framework.Rectangle>(); List<Vector3> kernings = new List<Vector3>(); foreach (var cd in cds) { locations.Add(new Microsoft.Xna.Framework.Rectangle( (int)cd.Location.X, (int)cd.Location.Y, (int)cd.Location.Width, (int)cd.Location.Height)); croppings.Add(new Microsoft.Xna.Framework.Rectangle( (int)cd.Cropping.X, (int)cd.Cropping.Y, (int)cd.Location.Width, (int)cd.Location.Height)); kernings.Add(new Vector3( (float)Math.Round(cd.Kerning.X, MidpointRounding.AwayFromZero), (float)Math.Round(cd.Kerning.Y, MidpointRounding.AwayFromZero), (float)Math.Round(cd.Kerning.Z, MidpointRounding.AwayFromZero))); } int verticalSpacing = 0; float horizontalSpacing = spacing; return new SpriteFontContent( new Texture2DContent(bitmapContent), locations, fontChars, croppings, verticalSpacing, horizontalSpacing, kernings, defaultChar); }
internal static extern void cairo_select_font_face(IntPtr cr, string family, FontSlant slant, FontWeight weight);
public void FontFace(string family, FontSlant slant, FontWeight weight) { SelectFontFace (family, slant, weight); }
internal static extern void cairo_select_font_face (IntPtr cr, string family, FontSlant slant, FontWeight weight);
public Font CreateFont([NotNull] string familyName, int weight, int width = (int)FontWidth.Normal, FontSlant slant = FontSlant.Normal) { Guard.NotNullOrEmpty(familyName, nameof(familyName)); var typeface = SKTypeface.FromFamilyName(familyName, weight, width, (SKFontStyleSlant)slant); Guard.NotNull(typeface, nameof(typeface)); var font = new Font(this, typeface); _loadedFonts.Add(font); return(font); }
internal static extern unsafe void SelectFontFace(FontWeight weight, FontSlant slant, sbyte *family, uint cr);
public void SelectFontFace(string family, FontSlant slant, FontWeight weight) { CairoAPI.cairo_select_font_face(state, family, slant, weight); }
public CairoFont WithSlant(FontSlant slant) { this.Slant = slant; return(this); }
public static Rectangle DrawText(this Context g, PointD p, string family, FontSlant slant, FontWeight weight, double size, Color color, string text) { g.Save (); g.MoveTo (p.X, p.Y); g.SelectFontFace (family, slant, weight); g.SetFontSize (size); g.Color = color; TextExtents te = g.TextExtents(text); //TODO alignment // Center text on bottom /*// TODO cut the string in char array and for each center on bottom * TextExtents te = g.TextExtents("a"); cr.MoveTo(0.5 - te.Width / 2 - te.XBearing, 0.5 - te.Height / 2 - te.YBearing); */ //// Draw g.ShowText (text); //or //g.TextPath(text); //g.Fill(); g.Restore (); return new Rectangle(te.XBearing, te.YBearing, te.Width, te.Height); }
void drawParsedCodeLine(Context gr, double x, double y, int i, int lineIndex) { int lPtr = 0; CodeLine cl = PrintedLines[i]; for (int t = 0; t < cl.Tokens.Count; t++) { string lstr = cl.Tokens [t].PrintableContent; if (lPtr < ScrollX) { if (lPtr - ScrollX + lstr.Length <= 0) { lPtr += lstr.Length; continue; } lstr = lstr.Substring(ScrollX - lPtr); lPtr += ScrollX - lPtr; } Color bg = this.Background; Color fg = this.Foreground; Color selbg = this.SelectionBackground; Color selfg = this.SelectionForeground; FontSlant fts = FontSlant.Normal; FontWeight ftw = FontWeight.Normal; if (formatting.ContainsKey((int)cl.Tokens [t].Type)) { TextFormatting tf = formatting [(int)cl.Tokens [t].Type]; bg = tf.Background; fg = tf.Foreground; if (tf.Bold) { ftw = FontWeight.Bold; } if (tf.Italic) { fts = FontSlant.Italic; } } gr.SelectFontFace(Font.Name, fts, ftw); gr.SetSourceColor(fg); gr.MoveTo(x, y + fe.Ascent); gr.ShowText(lstr); gr.Fill(); if (buffer.SelectionInProgress && lineIndex >= buffer.SelectionStart.Y && lineIndex <= buffer.SelectionEnd.Y && !(lineIndex == buffer.SelectionStart.Y && lPtr + lstr.Length <= selStartCol) && !(lineIndex == buffer.SelectionEnd.Y && selEndCol <= lPtr)) { double rLineX = x, rLineY = y, rLineW = lstr.Length * fe.MaxXAdvance; double startAdjust = 0.0; if ((lineIndex == buffer.SelectionStart.Y) && (selStartCol < lPtr + lstr.Length) && (selStartCol > lPtr)) { startAdjust = (selStartCol - lPtr) * fe.MaxXAdvance; } rLineX += startAdjust; if ((lineIndex == buffer.SelectionEnd.Y) && (selEndCol < lPtr + lstr.Length)) { rLineW = (selEndCol - lPtr) * fe.MaxXAdvance; } rLineW -= startAdjust; gr.Save(); gr.Operator = Operator.Source; gr.Rectangle(rLineX, rLineY, rLineW, fe.Height); gr.SetSourceColor(selbg); gr.FillPreserve(); gr.Clip(); gr.Operator = Operator.Over; gr.SetSourceColor(selfg); gr.MoveTo(x, y + fe.Ascent); gr.ShowText(lstr); gr.Fill(); gr.Restore(); } x += (int)lstr.Length * fe.MaxXAdvance; lPtr += lstr.Length; } }
/// <summary> /// Sets the current font. /// </summary> private void SetFont(string family, double scale, FontSlant slant, FontWeight weight) { Context.SelectFontFace(family, slant, weight); Context.SetFontSize(scale); }
static BitmapContent CreateBitmapContent( double bitmapWidth, double bitmapHeight, string fontName, FontSlant fontSlant, FontWeight fontWeight, double fontSize, List<CharacterData> cds, ParsedPath pngFile) { using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)bitmapWidth, (int)bitmapHeight)) { using (Context g = new Context(surface)) { SetupContext(g, fontName, fontSlant, fontWeight, fontSize); double x = 0; for (int i = 0; i < cds.Count; i++) { CharacterData cd = cds[i]; if (cd.Location.Width == 0) continue; g.MoveTo(x + cd.Bearing.X, cd.Bearing.Y); g.ShowText(cd.Character); #if DEBUG g.Save(); g.Color = new Color(1.0, 0, 0, 0.5); g.Antialias = Antialias.None; g.LineWidth = 1; g.MoveTo(x + 0.5, 0.5); g.LineTo(x + cd.Location.Width - 0.5, 0); g.LineTo(x + cd.Location.Width - 0.5, cd.Location.Height - 0.5); g.LineTo(x + 0.5, cd.Location.Height - 0.5); g.LineTo(x + 0.5, 0.5); g.Stroke(); g.Restore(); #endif x += cd.Location.Width; } g.Restore(); } if (pngFile != null) surface.WriteToPng(pngFile); return new BitmapContent(SurfaceFormat.Color, surface.Width, surface.Height, surface.Data); } }
public void SelectFontFace(string family, FontSlant slant, FontWeight weight) { CheckDisposed(); NativeMethods.cairo_select_font_face(handle, family, slant, weight); }
public void FontFace(string family, FontSlant slant, FontWeight weight) { SelectFontFace(family, slant, weight); }
public void SelectFontFace (string family, FontSlant slant, FontWeight weight) { CairoAPI.cairo_select_font_face (state, family, slant, weight); }
void printToken(string lstr, SyntaxKind kind, bool trivia = false) { checkPrintMargin(); TextFormatting tf = editor.formatting ["default"]; if (SyntaxFacts.IsTypeSyntax(kind)) { tf = editor.formatting ["TypeSyntax"]; } else if (SyntaxFacts.IsPreprocessorDirective(kind)) { tf = editor.formatting ["PreprocessorDirective"]; } else if (SyntaxFacts.IsDocumentationCommentTrivia(kind)) { tf = editor.formatting ["DocumentationCommentTrivia"]; } else if (kind == SyntaxKind.DisabledTextTrivia) { tf = editor.formatting ["DisabledTextTrivia"]; } else if (SyntaxFacts.IsTrivia(kind)) { tf = editor.formatting ["Trivia"]; } else if (SyntaxFacts.IsPunctuation(kind)) { tf = editor.formatting ["Punctuation"]; } else if (SyntaxFacts.IsName(kind)) { tf = editor.formatting ["Name"]; } else if (SyntaxFacts.IsLiteralExpression(kind)) { tf = editor.formatting ["LiteralExpression"]; } else if (SyntaxFacts.IsPredefinedType(kind)) { tf = editor.formatting ["PredefinedType"]; } else if (SyntaxFacts.IsPrimaryFunction(kind)) { tf = editor.formatting ["PrimaryFunction"]; } else if (SyntaxFacts.IsContextualKeyword(kind)) { tf = editor.formatting ["ContextualKeyword"]; } else if (SyntaxFacts.IsKeywordKind(kind)) { tf = editor.formatting ["keyword"]; } else if (SyntaxFacts.IsGlobalMemberDeclaration(kind)) { tf = editor.formatting ["GlobalMemberDeclaration"]; } else if (SyntaxFacts.IsInstanceExpression(kind)) { tf = editor.formatting ["InstanceExpression"]; } else if (SyntaxFacts.IsNamespaceMemberDeclaration(kind)) { tf = editor.formatting ["NamespaceMemberDeclaration"]; } else if (SyntaxFacts.IsTypeDeclaration(kind)) { tf = editor.formatting ["TypeDeclaration"]; } FontSlant fts = FontSlant.Normal; FontWeight ftw = FontWeight.Normal; if (tf.Bold) { ftw = FontWeight.Bold; } if (tf.Italic) { fts = FontSlant.Italic; } ctx.SelectFontFace(editor.Font.Name, fts, ftw); ctx.SetSourceColor(tf.Foreground); Console.WriteLine(tf.Foreground); int diffX = currentCol - editor.ScrollX; string str = lstr; if (diffX < 0) { if (diffX + lstr.Length > 0) { str = lstr.Substring(-diffX); } else { currentCol += lstr.Length; return; } } else { diffX = 0; } ctx.MoveTo(bounds.X + editor.leftMargin + (currentCol - editor.ScrollX - diffX) * fe.MaxXAdvance, y + fe.Ascent); ctx.ShowText(str); currentCol += lstr.Length; }
public async Task FontFamilyAndAttributesInitializesCorrectly(string family, FontWeight weight, FontSlant slant) { var label = new LabelStub { Text = "Test", Font = Font.OfSize(family, 30, weight, slant) }; var(isBold, isItalic) = await GetValueAsync(label, (handler) => { var isBold = GetNativeIsBold(handler); var isItalic = GetNativeIsItalic(handler); return(isBold, isItalic); }); Assert.Equal(weight == FontWeight.Bold, isBold); Assert.Equal(slant == FontSlant.Italic, isItalic); }
public static Size GetSize(this string value, string fontFamily, double fontSize, FontSlant fontSlant, FontWeight fontWeight) { if (string.IsNullOrEmpty(value)) { return(new Size(0, 0)); } using (ImageSurface surface = new ImageSurface(Format.Argb32, 0, 0)) { using (GraphicsContext context = new GraphicsContext(surface)) { context.SelectFontFace(fontFamily, fontSlant, fontWeight); context.SetFontSize(fontSize); TextExtents te = context.TextExtents(value); double width = te.Width; double height = te.Height; return(new Size(width, height)); } } }
private void UpdateImage() { float scale = Math.Min(Allocation.Width / _svgOriginalW, Allocation.Height / _svgOriginalH); int width = (int)(_svgOriginalW * scale); int height = (int)(_svgOriginalH * scale); Context cr = Gdk.CairoHelper.Create(this.GdkWindow); cr.SetSourceRGB(0, 0, 0); cr.Rectangle(0, 0, width, height); cr.Fill(); cr.Save(); using (MemoryStream ms = new MemoryStream()) { _svg.Draw(width, height).Save(ms, ImageFormat.Png); // imageView.Pixbuf = new Pixbuf(ms.ToArray()); CairoHelper.SetSourcePixbuf(cr, new Pixbuf(ms.ToArray()), 0, 0); } cr.Paint(); cr.Restore(); cr.SetSourceRGB(1, 1, 1); foreach (SvgText text in _svgTexts) { if (text.Text == null) { continue; } float dx = text.X[0].Value / _svgOriginalW * width; float dy = text.Y[0].Value / _svgOriginalH * height; cr.MoveTo(dx, dy); if (text.Color == warningColor) { cr.SetSourceColor(cWarningColor); } else if (text.Color == disabledColor) { cr.SetSourceColor(cDisabledColor); } else { cr.SetSourceColor(cNominalColor); } if (text.FontSize.Value is float size) { cr.SetFontSize(size * scale); } FontWeight weight = (text.FontWeight == SvgFontWeight.Bold) ? FontWeight.Bold : FontWeight.Normal; FontSlant slant = (text.FontStyle == SvgFontStyle.Italic) ? FontSlant.Italic : FontSlant.Normal; cr.SelectFontFace("sans serif", slant, weight); if (text.TextAnchor == SvgTextAnchor.Middle) { TextExtents te = cr.TextExtents(text.Text); cr.RelMoveTo(-te.Width / 2.0, 0); } cr.ShowText(text.Text); } // GC from example ((IDisposable)cr.GetTarget()).Dispose(); ((IDisposable)cr).Dispose(); }
public static Font CreateFontVariance([NotNull] this Font baseFont, int weight, int width = (int)FontWidth.Normal, FontSlant slant = FontSlant.Normal) { Guard.ArgumentNotNull(baseFont, nameof(baseFont)); return(baseFont.FontManager.CreateFont(baseFont.FamilyName, weight, width, slant)); }
public void SelectFontFace(string family, FontSlant slant, FontWeight weight) { NativeMethods.cairo_select_font_face (handle, family, slant, weight); }
public void SelectFont (string key, FontSlant slant, FontWeight weight) { CairoAPI.cairo_select_font (state, key, slant, weight); }
public Font (string family, FontSlant fcslant, FontWeight fcweight) { font = _create (family, fcslant, fcweight); }
public static extern void cairo_select_font (IntPtr cr, string key, FontSlant slant, FontWeight weight);
public void SelectFontFace(string family, FontSlant slant, FontWeight weight) { NativeMethods.cairo_select_font_face(state, family, slant, weight); }
public IFont GetFont(float size, FontSlant slant, Amity.FontWeight weight) { return(new Font(this, (int)size, slant != FontSlant.Roman, weight)); }