public void Save(string filename, FontService fontService) { Gdk.Pixbuf pixbuf = null; BinaryWriter file = null; try { pixbuf = BuildImage(fontService); //pixbuf.Save (String.Format("{0}.bmp", filename), "bmp"); file = new BinaryWriter(File.Create(String.Format("{0}.dft", filename)), Encoding.ASCII); TFontHeader header = new TFontHeader(1, pixbuf.Width, pixbuf.Height); file.Write(header); file.Write(boxes); file.Write(pixbuf); } finally { if (file != null) { file.Close(); } // manual dispose if (pixbuf != null) { (pixbuf as IDisposable).Dispose(); } } }
public void BuildPreview(FontService fontService) { tablePreviewBuf = dftUtil.BuildImage (fontService); base.SetSizeRequest (tablePreviewBuf.Width, tablePreviewBuf.Height); size = new Gdk.Size (tablePreviewBuf.Width, tablePreviewBuf.Height); fileSize = dftUtil.CalcFileSize (tablePreviewBuf); base.QueueDraw (); }
public void BuildPreview(FontService fontService) { tablePreviewBuf = DftUtil.BuildImage(fontService); base.SetSizeRequest(tablePreviewBuf.Width, tablePreviewBuf.Height); size = new Gdk.Size(tablePreviewBuf.Width, tablePreviewBuf.Height); FileSize = DftUtil.CalcFileSize(tablePreviewBuf); base.QueueDraw(); }
public Gdk.Pixbuf BuildImage(FontService fontService) { Cairo.ImageSurface image = new Cairo.ImageSurface(Cairo.Format.ARGB32, WIDTH, HEIGHT); Cairo.Context ctx = new Cairo.Context(image); Pango.Layout layout = Pango.CairoHelper.CreateLayout(ctx); fontService.AssignLayout(layout); // fill background ctx.Save(); ctx.Color = new Cairo.Color(0.0, 0.0, 0.0, 1.0); ctx.Paint(); ctx.Restore(); int charCode = 0; int maxHeight = 0; Cairo.Point pos = new Cairo.Point(PADDING, PADDING); while ((!fontService.OnlyEnglish && charCode < 224) || (fontService.OnlyEnglish && charCode < (224 - 66))) { layout.SetText(alphabet[charCode].ToString()); Pango.Rectangle te = GetTextExtents(layout, pos); // next line if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width) { pos.X = PADDING; pos.Y = te.Y + maxHeight + PADDING; } te = DrawText(ctx, layout, pos); boxes[charCode] = te; pos.X = te.X + te.Width + fontService.Spacing + PADDING; maxHeight = Math.Max(maxHeight, te.Height); charCode++; } int cropHeight = NextP2(boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf( image.Data, true, 8, image.Width, cropHeight, image.Stride); // manual dispose (image as IDisposable).Dispose(); (layout as IDisposable).Dispose(); (ctx.Target as IDisposable).Dispose(); (ctx as IDisposable).Dispose(); return(pixbuf); }
public void DrawLayout(Gdk.Drawable drawable, Gdk.GC gc, FontService fontService) { Gdk.Pixbuf pixbuf = BuildImage(fontService); int w = -1, h = -1; drawable.GetSize(out w, out h); pixbuf.RenderToDrawable(drawable, gc, 0, 0, 0, 0, w, h, Gdk.RgbDither.Normal, 0, 0); // manual dispose (pixbuf as IDisposable).Dispose(); }
public FontBuildWindow (FontService fontService) : base(Gtk.WindowType.Toplevel) { this.Build (); this.dftUtil = new DftUtil (); this.fontService = fontService; this.fileSaveWidget.SelectMultiple = false; using (FileFilter filter = new FileFilter()) { filter.Name = "DGLE2 Bitmap Fonts"; filter.AddMimeType ("font/dft"); filter.AddPattern ("*.dft"); this.fileSaveWidget.AddFilter (filter); } using (FileFilter filter = new FileFilter()) { filter.Name = "All"; filter.AddPattern ("*.*"); this.fileSaveWidget.AddFilter (filter); } this.fileSaveWidget.CurrentName = String.Format(@"{0}_{1}", fontService.Family.Name, fontService.Size); tablePreviewBuf = this.dftUtil.BuildImage (fontService); this.drawingarea3.SetSizeRequest (tablePreviewBuf.Width, tablePreviewBuf.Height); this.eWidth.Text = tablePreviewBuf.Width.ToString(); this.eHeight.Text = tablePreviewBuf.Height.ToString(); this.DeleteEvent += HandleDeleteEvent; this.drawingarea3.ExposeEvent += DrawPreviewFontTable; this.btnCancel.Clicked += delegate (object sender, EventArgs e) { this.Destroy(); }; this.btnSave.Clicked += HandleSave; }
public void Save(string filename, FontService fontService) { Gdk.Pixbuf pixbuf = BuildImage (fontService); //pixbuf.Save (String.Format("{0}.bmp", filename), "bmp"); BinaryWriter file = new BinaryWriter(File.Create(String.Format("{0}.dft", filename)), Encoding.ASCII); TFontHeader header = new TFontHeader(1, pixbuf.Width, pixbuf.Height); // extensions doesn;t work on mono2 DFTExtensions.Write(file, header); DFTExtensions.Write(file, boxes); DFTExtensions.Write(file, pixbuf); file.Close(); // manual dispose (pixbuf as IDisposable).Dispose (); }
public void DrawLayout(Gdk.Drawable drawable, Gdk.GC gc, FontService fontService) { Gdk.Pixbuf pixbuf = BuildImage(fontService); int w = -1, h = -1; drawable.GetSize(out w, out h); pixbuf.RenderToDrawable(drawable, gc, 0, 0, 0, 0, w, h, Gdk.RgbDither.Normal, 0, 0); // manual dispose (pixbuf as IDisposable).Dispose (); }
public Gdk.Pixbuf BuildImage(FontService fontService) { Cairo.ImageSurface image = new Cairo.ImageSurface (Cairo.Format.ARGB32, WIDTH, HEIGHT); Cairo.Context ctx = new Cairo.Context (image); Pango.Layout layout = Pango.CairoHelper.CreateLayout (ctx); fontService.AssignLayout (layout); // fill background ctx.Save (); ctx.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0); ctx.Paint (); ctx.Restore (); int charCode = 0; int maxHeight = 0; Cairo.Point pos = new Cairo.Point (PADDING, PADDING); while ((!fontService.OnlyEnglish && charCode < 224) || (fontService.OnlyEnglish && charCode < (224 - 66))) { layout.SetText (alphabet[charCode].ToString()); Pango.Rectangle te = GetTextExtents (layout, pos); // next line if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width) { pos.X = PADDING; pos.Y = te.Y + maxHeight + PADDING; } te = DrawText (ctx, layout, pos); boxes[charCode] = te; pos.X = te.X + te.Width + fontService.Spacing + PADDING; maxHeight = Math.Max (maxHeight, te.Height); charCode++; } int cropHeight = NextP2 (boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf ( image.Data, true, 8, image.Width, cropHeight, image.Stride); // manual dispose (image as IDisposable).Dispose (); (layout as IDisposable).Dispose (); (ctx.Target as IDisposable).Dispose (); (ctx as IDisposable).Dispose (); return pixbuf; }
public void Save(string filename, FontService fontService) { Gdk.Pixbuf pixbuf = null; BinaryWriter file = null; try { pixbuf = BuildImage(fontService); //pixbuf.Save (String.Format("{0}.bmp", filename), "bmp"); file = new BinaryWriter(File.Create(String.Format("{0}.dft", filename)), Encoding.ASCII); TFontHeader header = new TFontHeader(1, pixbuf.Width, pixbuf.Height); file.Write(header); file.Write(boxes); file.Write(pixbuf); } finally { if (file != null) file.Close(); // manual dispose if (pixbuf != null) (pixbuf as IDisposable).Dispose(); } }