public int sceFontGetCharGlyphImage_Clip(FontHandle FontHandle, ushort CharCode, GlyphImage* GlyphImagePointer, int ClipX, int ClipY, int ClipWidth, int ClipHeight) { var Font = Fonts.Get(FontHandle); var Glyph = Font.GetGlyph(CharCode); var Face = Glyph.Face; var PixelFormat = GlyphImagePointer->PixelFormat; var Buffer = PspMemory.PspAddressToPointerSafe(GlyphImagePointer->Buffer); var BufferHeight = GlyphImagePointer->BufferHeight; var BufferWidth = GlyphImagePointer->BufferWidth; var Position = GlyphImagePointer->Position; var GlyphBitmap = Face.GetBitmap(); var OutputBitmap = new PspBitmap(PixelFormat, (int)BufferWidth, (int)BufferHeight, (byte*)Buffer); try { for (int y = 0; y < ClipHeight; y++) { for (int x = 0; x < ClipWidth; x++) { //Console.WriteLine(); OutputBitmap.SetPixel(x, y, new OutputPixel(GlyphBitmap.GetPixel(x + ClipX, y + ClipY))); //OutputBitmap.SetPixel(x, y, new OutputPixel(Color.Red)); } } } catch (Exception Exception) { Console.Error.WriteLine(Exception); } //for (int n = 0; n < ) //Console.Error.WriteLine("'{0}': {1}", (char)CharCode, Glyph); //throw (new NotImplementedException()); return 0; }
static void BuildFontGlyphs(PixelFarm.Drawing.RequestFont font, Typography.Rendering.SimpleFontAtlasBuilder atlasBuilder, int startAt, int endAt) { //font glyph for specific font face ActualFont nativeFont = GetActualFont(font.Name, font.SizeInPoints);// nativeFontStore.GetResolvedNativeFont(font); for (int i = startAt; i <= endAt; ++i) { char c = (char)i; FontGlyph fontGlyph = nativeFont.GetGlyph(c); //------------------- GlyphImage glyphImg = NativeMsdfGen.BuildMsdfFontImage(fontGlyph); // Console.WriteLine(c.ToString() + " ox,oy" + glyphImg.OffsetX + "," + glyphImg.OffsetY); int w = glyphImg.Width; int h = glyphImg.Height; int[] buffer = glyphImg.GetImageBuffer(); NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer); glyphImg.SetImageBuffer(buffer, false); // atlasBuilder.AddGlyph(fontGlyph.glyphMatrix.u c, fontGlyph, glyphImg); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_x1_" + (int)c + ".png"); //} } }
static void CreateSampleMsdfTextureFont( string fontfile, float sizeInPoint, char[] chars, string outputFile) { //sample var reader = new OpenFontReader(); using (var fs = new FileStream(fontfile, FileMode.Open)) { //1. read typeface from font file Typeface typeface = reader.Read(fs); //sample: create sample msdf texture //------------------------------------------------------------- var builder = new GlyphPathBuilder(typeface); //builder.UseTrueTypeInterpreter = this.chkTrueTypeHint.Checked; //builder.UseVerticalHinting = this.chkVerticalHinting.Checked; //------------------------------------------------------------- var atlasBuilder = new SimpleFontAtlasBuilder(); MsdfGenParams msdfGenParams = new MsdfGenParams(); int j = chars.Length; for (int i = 0; i < j; ++i) { //build glyph ushort gindex = typeface.LookupIndex(chars[i]); builder.BuildFromGlyphIndex(gindex, -1); var glyphToContour = new GlyphContourBuilder(); //glyphToContour.Read(builder.GetOutputPoints(), builder.GetOutputContours()); builder.ReadShapes(glyphToContour); msdfGenParams.shapeScale = 1f / 64; GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, msdfGenParams); atlasBuilder.AddGlyph(gindex, glyphImg); int w = glyphImg.Width; int h = glyphImg.Height; using (Bitmap bmp = new Bitmap(glyphImg.Width, glyphImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); int[] imgBuffer = glyphImg.GetImageBuffer(); System.Runtime.InteropServices.Marshal.Copy(imgBuffer, 0, bmpdata.Scan0, imgBuffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\a001_xn2_" + (chars[i]) + ".png"); } } var glyphImg2 = atlasBuilder.BuildSingleImage(); using (Bitmap bmp = new Bitmap(glyphImg2.Width, glyphImg2.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg2.Width, glyphImg2.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); int[] intBuffer = glyphImg2.GetImageBuffer(); System.Runtime.InteropServices.Marshal.Copy(intBuffer, 0, bmpdata.Scan0, intBuffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\a_total.png"); } atlasBuilder.SaveFontInfo("d:\\WImageTest\\a_info.xml"); } }
public FontAtlasTextPrinter(AggPainter painter) { StartDrawOnLeftTop = true; _painter = painter; this.PositionTechnique = PositionTechnique.OpenFont; _textServices = new LayoutFarm.OpenFontTextService(); //2. _bmpFontMx = new BitmapFontManager <MemBitmap>( _textServices, atlas => { GlyphImage totalGlyphImg = atlas.TotalGlyph; if (atlas.UseSharedGlyphImage) { if (!_sharedGlyphImgs.TryGetValue(totalGlyphImg, out MemBitmap found)) { found = MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer()); _sharedGlyphImgs.Add(totalGlyphImg, found); } return(found); } else { return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer())); } } ); //3. ChangeFont(painter.CurrentFont); SetupMaskPixelBlender(painter.Width, painter.Height); }
public int sceFontGetCharGlyphImage_Clip(Font Font, ushort CharCode, ref GlyphImage GlyphImage, int ClipX, int ClipY, int ClipWidth, int ClipHeight) { try { var Glyph = Font.GetGlyph(CharCode); var CharInfo = Font.GetCharInfo(CharCode); var Face = Glyph.Face; var PixelFormat = GlyphImage.PixelFormat; var Buffer = Memory.PspAddressToPointerSafe(GlyphImage.Buffer); var BufferHeight = GlyphImage.BufferHeight; var BufferWidth = GlyphImage.BufferWidth; var BytesPerLine = GlyphImage.BytesPerLine; var Position = GlyphImage.Position; var GlyphBitmap = Face.GetBitmap(); var OutputBitmap = new FontBitmap((byte *)Buffer, PixelFormat, (int)BufferWidth, (int)BufferHeight, BytesPerLine); Console.WriteLine( "sceFontGetCharGlyphImage_Clip({0}, ({1}, {2})-({3}, {4}) : {5}) : {6}", CharCode, ClipX, ClipY, ClipWidth, ClipHeight, PixelFormat, Position ); ClipWidth = Math.Min(ClipWidth, BufferWidth - ClipX); ClipHeight = Math.Min(ClipHeight, BufferHeight - ClipY); ClipWidth = Math.Min(ClipWidth, GlyphBitmap.Width - ClipX); ClipHeight = Math.Min(ClipHeight, GlyphBitmap.Height - ClipY); try { for (int y = 0; y < ClipHeight; y++) { for (int x = 0; x < ClipWidth; x++) { //Console.WriteLine(); var Pixel = GlyphBitmap.GetPixel(x + ClipX, y + ClipY); OutputBitmap.SetPixel(x + (int)Position.X, y + (int)Position.Y, new OutputPixel(Pixel)); //Console.Write(Pixel.R > 0x7F ? "X" : "."); //OutputBitmap.SetPixel(x, y, new OutputPixel(Color.Red)); } //Console.WriteLine(""); } } catch (Exception Exception) { Console.Error.WriteLine(Exception); } //for (int n = 0; n < ) //Console.Error.WriteLine("'{0}': {1}", (char)CharCode, Glyph); //throw (new NotImplementedException()); return(0); } catch (Exception Exception) { Console.Error.WriteLine(Exception); return(-1); } }
public FontAtlasTextPrinter(AggPainter painter) { StartDrawOnLeftTop = true; _painter = painter; this.PositionTechnique = PositionTechnique.OpenFont; _textServices = new LayoutFarm.OpenFontTextService(); //2. create manager _bmpFontMx = new BitmapFontManager <MemBitmap>( TextureKind.StencilLcdEffect, _textServices, atlas => { GlyphImage totalGlyphImg = atlas.TotalGlyph; return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer())); } ); //3. ChangeFont(new RequestFont("tahoma", 10)); SetupMaskPixelBlender(painter.Width, painter.Height); }
public static FontFace LoadFont(string fontfile, ScriptLang scriptLang, WriteDirection writeDirection, out SimpleFontAtlas fontAtlas) { //1. read font info ManagedFontFace openFont = (ManagedFontFace)OpenFontLoader.LoadFont(fontfile, scriptLang, writeDirection); //2. build texture font on the fly! OR load from prebuilt file // //2.1 test build texture on the fly SimpleFontAtlasBuilder atlas1 = CreateSampleMsdfTextureFont(fontfile, 14, 0, 255); GlyphImage glyphImg2 = atlas1.BuildSingleImage(); fontAtlas = atlas1.CreateSimpleFontAtlas(); fontAtlas.TotalGlyph = glyphImg2; //string xmlFontFileInfo = ""; //GlyphImage glyphImg = null; //MySimpleFontAtlasBuilder atlasBuilder = new MySimpleFontAtlasBuilder(); //SimpleFontAtlas fontAtlas = atlasBuilder.LoadFontInfo(xmlFontFileInfo); //glyphImg = atlasBuilder.BuildSingleImage(); //we can create a new glyph or load from prebuilt file //fontAtlas.TotalGlyph = glyphImg; var textureFontFace = new TextureFontFace(openFont, fontAtlas); return(textureFontFace); }
internal void WriteGlyphList(Dictionary <ushort, CacheGlyph> glyphs) { _writer.Write((ushort)FontTextureObjectKind.GlyphList); //total number int totalNum = glyphs.Count; #if DEBUG if (totalNum >= ushort.MaxValue) { throw new NotSupportedException(); } #endif _writer.Write((ushort)totalNum); // foreach (CacheGlyph g in glyphs.Values) { //1. code point _writer.Write((ushort)g.glyphIndex); //2. area, left,top,width,height _writer.Write((ushort)g.area.Left); _writer.Write((ushort)g.area.Top); _writer.Write((ushort)g.area.Width); _writer.Write((ushort)g.area.Height); //3. texture offset GlyphImage img = g.img; _writer.Write((short)img.TextureOffsetX); //short _writer.Write((short)img.TextureOffsetY); //short } }
public override void Init() { //steps : detail ... //1. create a text service (or get it from a singleton class) _textServices = new LayoutFarm.OpenFontTextService(); //2. create manager _bmpFontMx = new BitmapFontManager <MemBitmap>( TextureKind.StencilLcdEffect, _textServices, atlas => { GlyphImage totalGlyphImg = atlas.TotalGlyph; return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer())); } ); //3. _font = new RequestFont("tahoma", 10); _fontAtlas = _bmpFontMx.GetFontAtlas(_font, out _fontBmp); //---------- }
public static FontFace LoadFont( Typeface typeface, TextureFontCreationParams creationParams, out SimpleFontAtlas fontAtlas) { //1. read font info NOpenFontFace openFont = (NOpenFontFace)OpenFontLoader.LoadFont(typeface, creationParams.scriptLang, creationParams.writeDirection); //------------------------ SimpleFontAtlasBuilder atlas1 = null; switch (creationParams.textureKind) { default: throw new System.NotSupportedException(); case TextureKind.AggSubPixel: atlas1 = CreateAggSubPixelRenderingTextureFont( typeface, creationParams.originalFontSizeInPoint, creationParams.hintTechnique, GetGlyphIndexIter(typeface, creationParams.langBits) ); break; case TextureKind.AggGrayScale: atlas1 = CreateAggTextureFont( typeface, creationParams.originalFontSizeInPoint, creationParams.hintTechnique, GetGlyphIndexIter(typeface, creationParams.langBits) ); break; case TextureKind.Msdf: atlas1 = CreateSampleMsdfTextureFont( typeface, creationParams.originalFontSizeInPoint, creationParams.hintTechnique, GetGlyphIndexIter(typeface, creationParams.langBits) ); break; } GlyphImage glyphImg2 = atlas1.BuildSingleImage(); fontAtlas = atlas1.CreateSimpleFontAtlas(); fontAtlas.TotalGlyph = glyphImg2; //string xmlFontFileInfo = ""; //GlyphImage glyphImg = null; //MySimpleFontAtlasBuilder atlasBuilder = new MySimpleFontAtlasBuilder(); //SimpleFontAtlas fontAtlas = atlasBuilder.LoadFontInfo(xmlFontFileInfo); //glyphImg = atlasBuilder.BuildSingleImage(); //we can create a new glyph or load from prebuilt file //fontAtlas.TotalGlyph = glyphImg; return(openFont); //var textureFontFace = new TextureFontFace(openFont, fontAtlas); //return textureFontFace; }
public int sceFontGetCharGlyphImage_Clip(FontHandle FontHandle, ushort CharCode, ref GlyphImage GlyphImage, int ClipX, int ClipY, int ClipWidth, int ClipHeight) { try { var Font = Fonts.Get(FontHandle); var Glyph = Font.GetGlyph(CharCode); var CharInfo = Font.GetCharInfo(CharCode); var Face = Glyph.Face; var PixelFormat = GlyphImage.PixelFormat; var Buffer = PspMemory.PspAddressToPointerSafe(GlyphImage.Buffer); var BufferHeight = GlyphImage.BufferHeight; var BufferWidth = GlyphImage.BufferWidth; var BytesPerLine = GlyphImage.BytesPerLine; var Position = GlyphImage.Position; var GlyphBitmap = Face.GetBitmap(); var OutputBitmap = new FontBitmap((byte*)Buffer, PixelFormat, (int)BufferWidth, (int)BufferHeight, BytesPerLine); Console.WriteLine( "sceFontGetCharGlyphImage_Clip({0}, ({1}, {2})-({3}, {4}) : {5}) : {6}", CharCode, ClipX, ClipY, ClipWidth, ClipHeight, PixelFormat, Position ); ClipWidth = Math.Min(ClipWidth, BufferWidth - ClipX); ClipHeight = Math.Min(ClipHeight, BufferHeight - ClipY); ClipWidth = Math.Min(ClipWidth, GlyphBitmap.Width - ClipX); ClipHeight = Math.Min(ClipHeight, GlyphBitmap.Height - ClipY); try { for (int y = 0; y < ClipHeight; y++) { for (int x = 0; x < ClipWidth; x++) { //Console.WriteLine(); var Pixel = GlyphBitmap.GetPixel(x + ClipX, y + ClipY); OutputBitmap.SetPixel(x + (int)Position.X, y + (int)Position.Y, new OutputPixel(Pixel)); //Console.Write(Pixel.R > 0x7F ? "X" : "."); //OutputBitmap.SetPixel(x, y, new OutputPixel(Color.Red)); } //Console.WriteLine(""); } } catch (Exception Exception) { Console.Error.WriteLine(Exception); } //for (int n = 0; n < ) //Console.Error.WriteLine("'{0}': {1}", (char)CharCode, Glyph); //throw (new NotImplementedException()); return 0; } catch (Exception Exception) { Console.Error.WriteLine(Exception); return -1; } }
/// <summary> /// get from cache or create a new one /// </summary> /// <param name="reqFont"></param> /// <returns></returns> public SimpleFontAtlas GetFontAtlas(RequestFont reqFont, out GLBitmap glBmp) { int fontKey = reqFont.FontKey; SimpleFontAtlas fontAtlas; if (!_createdAtlases.TryGetValue(fontKey, out fontAtlas)) { Typeface resolvedTypeface = textServices.ResolveTypeface(reqFont); //if we don't have //the create it SimpleFontAtlasBuilder atlasBuilder = null; var textureGen = new GlyphTextureBitmapGenerator(); textureGen.CreateTextureFontFromScriptLangs( resolvedTypeface, reqFont.SizeInPoints, _textureKind, _currentScriptLangs, (glyphIndex, glyphImage, outputAtlasBuilder) => { if (outputAtlasBuilder != null) { //finish atlasBuilder = outputAtlasBuilder; } } ); GlyphImage totalGlyphsImg = atlasBuilder.BuildSingleImage(); //create atlas fontAtlas = atlasBuilder.CreateSimpleFontAtlas(); fontAtlas.TotalGlyph = totalGlyphsImg; #if DEBUG //save glyph image for debug //PixelFarm.Agg.ActualImage.SaveImgBufferToPngFile( // totalGlyphsImg.GetImageBuffer(), // totalGlyphsImg.Width * 4, // totalGlyphsImg.Width, totalGlyphsImg.Height, // "d:\\WImageTest\\total_" + reqFont.Name + "_" + reqFont.SizeInPoints + ".png"); #endif //cache the atlas _createdAtlases.Add(fontKey, fontAtlas); // //calculate some commonly used values fontAtlas.SetTextureScaleInfo( resolvedTypeface.CalculateScaleToPixelFromPointSize(fontAtlas.OriginalFontSizePts), resolvedTypeface.CalculateScaleToPixelFromPointSize(reqFont.SizeInPoints)); //TODO: review here, use scaled or unscaled values fontAtlas.SetCommonFontMetricValues( resolvedTypeface.Ascender, resolvedTypeface.Descender, resolvedTypeface.LineGap, resolvedTypeface.CalculateRecommendLineSpacing()); } glBmp = _loadedGlyphs.GetOrCreateNewOne(fontAtlas); return(fontAtlas); }
public override int GetHashCode() { int hash = 1; if (Id.Length != 0) { hash ^= Id.GetHashCode(); } if (Name.Length != 0) { hash ^= Name.GetHashCode(); } hash ^= chargeUpEffect_.GetHashCode(); if (Pattern.Length != 0) { hash ^= Pattern.GetHashCode(); } if (GlyphImage.Length != 0) { hash ^= GlyphImage.GetHashCode(); } if (ProtegoPlayerSucceedTl.Length != 0) { hash ^= ProtegoPlayerSucceedTl.GetHashCode(); } if (ProtegoPlayerFailedTl.Length != 0) { hash ^= ProtegoPlayerFailedTl.GetHashCode(); } if (ProtegoPlayerSucceedIntroTl.Length != 0) { hash ^= ProtegoPlayerSucceedIntroTl.GetHashCode(); } if (EndBurstEffect.Length != 0) { hash ^= EndBurstEffect.GetHashCode(); } if (RngVfxTl.Length != 0) { hash ^= RngVfxTl.GetHashCode(); } if (SpellRngLoopTl.Length != 0) { hash ^= SpellRngLoopTl.GetHashCode(); } if (SpellRngSucceedTl.Length != 0) { hash ^= SpellRngSucceedTl.GetHashCode(); } if (SpellRngFailTl.Length != 0) { hash ^= SpellRngFailTl.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
void CreateTextureFontFromGlyphIndices( Typeface typeface, float sizeInPoint, HintTechnique hintTechnique, SimpleFontAtlasBuilder atlasBuilder, bool applyFilter, ushort[] glyphIndices) { //sample: create sample msdf texture //------------------------------------------------------------- var builder = new GlyphPathBuilder(typeface); builder.SetHintTechnique(hintTechnique); // if (atlasBuilder.TextureKind == TextureKind.Msdf) { MsdfGenParams msdfGenParams = new MsdfGenParams(); int j = glyphIndices.Length; for (int i = 0; i < j; ++i) { ushort gindex = glyphIndices[i]; //create picture with unscaled version set scale=-1 //(we will create glyph contours and analyze them) builder.BuildFromGlyphIndex(gindex, -1); var glyphToContour = new GlyphContourBuilder(); builder.ReadShapes(glyphToContour); //msdfgen with scale the glyph to specific shapescale msdfGenParams.shapeScale = 1f / 64; //as original GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, msdfGenParams); // atlasBuilder.AddGlyph(gindex, glyphImg); } } else { AggGlyphTextureGen aggTextureGen = new AggGlyphTextureGen(); aggTextureGen.TextureKind = atlasBuilder.TextureKind; int j = glyphIndices.Length; for (int i = 0; i < j; ++i) { //build glyph ushort gindex = glyphIndices[i]; builder.BuildFromGlyphIndex(gindex, sizeInPoint); GlyphImage glyphImg = aggTextureGen.CreateGlyphImage(builder, 1); if (applyFilter) { glyphImg = Sharpen(glyphImg, 1); //TODO: //the filter make the image shift x and y 1 px //temp fix with this, glyphImg.TextureOffsetX += 1; glyphImg.TextureOffsetY += 1; } // atlasBuilder.AddGlyph(gindex, glyphImg); } } }
static void CreateSampleMsdfTextureFont(string fontfile, float sizeInPoint, ushort startGlyphIndex, ushort endGlyphIndex, string outputFile) { //sample var reader = new OpenFontReader(); using (var fs = new FileStream(fontfile, FileMode.Open)) { //1. read typeface from font file Typeface typeface = reader.Read(fs); //sample: create sample msdf texture //------------------------------------------------------------- var builder = new GlyphPathBuilder(typeface); //builder.UseTrueTypeInterpreter = this.chkTrueTypeHint.Checked; //builder.UseVerticalHinting = this.chkVerticalHinting.Checked; //------------------------------------------------------------- var atlasBuilder = new SimpleFontAtlasBuilder(); for (ushort gindex = startGlyphIndex; gindex <= endGlyphIndex; ++gindex) { //build glyph builder.BuildFromGlyphIndex(gindex, sizeInPoint); var glyphToContour = new GlyphContourBuilder(); //glyphToContour.Read(builder.GetOutputPoints(), builder.GetOutputContours()); var genParams = new MsdfGenParams(); builder.ReadShapes(glyphToContour); genParams.shapeScale = 1f / 64; //we scale later (as original C++ code use 1/64) GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, genParams); atlasBuilder.AddGlyph(gindex, glyphImg); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png"); //} } var glyphImg2 = atlasBuilder.BuildSingleImage(); using (Bitmap bmp = new Bitmap(glyphImg2.Width, glyphImg2.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg2.Width, glyphImg2.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); int[] intBuffer = glyphImg2.GetImageBuffer(); System.Runtime.InteropServices.Marshal.Copy(intBuffer, 0, bmpdata.Scan0, intBuffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\a_total.png"); } atlasBuilder.SaveFontInfo("d:\\WImageTest\\a_info.xml"); } }
private void cmdMakeFromScriptLangs_Click(object sender, EventArgs e) { //create a simple stencil texture font //string sampleFontFile = "../../../TestFonts/tahoma.ttf"; if (this.textBox1.Text == null || _typeface == null) { return; } if (SelectedScriptLangs.Count == 0) { return; } // string sampleFontFile = _typeface.Filename ?? ""; TextureKind selectedTextureKind = (TextureKind)lstTextureType.SelectedItem; char[] chars = this.textBox1.Text.ToCharArray(); string bitmapImgSaveFileName = "d:\\WImageTest\\sample_" + selectedTextureKind + "_" + System.IO.Path.GetFileNameWithoutExtension(sampleFontFile); bool saveEachGlyphSeparatly = chkSaveEachGlyph.Checked; var textureGen = new GlyphTextureBitmapGenerator(); textureGen.CreateTextureFontFromScriptLangs( _typeface, FontSizeInPoints, selectedTextureKind, SelectedScriptLangs.ToArray(), (gindex, glyphImg, atlasBuilder) => { if (atlasBuilder != null) { atlasBuilder.CompactGlyphSpace = chkCompactGlyphSpace.Checked; GlyphImage totalGlyphs = atlasBuilder.BuildSingleImage(); SaveImgBufferToFile(totalGlyphs, bitmapImgSaveFileName + ".png"); atlasBuilder.SaveFontInfo(bitmapImgSaveFileName + ".xml"); MessageBox.Show("glyph gen " + bitmapImgSaveFileName); } else { //save each glyph if (saveEachGlyphSeparatly) { SaveImgBufferToFile(glyphImg, bitmapImgSaveFileName + "_" + gindex + ".png"); } } }); }
void imageContextShowInfo_Click(object sender, EventArgs e) { GlyphImage GI = new GlyphImage(((sender as ToolStripMenuItem).GetCurrentParent() as ContextMenuStrip).SourceControl.Name); using (Tiff input = Tiff.Open(db.DataDirectory + GI.Path, "r")) { int GlyphWidth = input.GetField(TiffTag.IMAGEWIDTH)[0].ToInt(); int GlyphHeight = input.GetField(TiffTag.IMAGELENGTH)[0].ToInt(); int GlyphScanSize = input.ScanlineSize(); MessageBox.Show("Width: " + GlyphWidth + Environment.NewLine + "Height: " + GlyphHeight + Environment.NewLine + "Scansize: " + GlyphScanSize + Environment.NewLine + "Path: " + db.DataDirectory + GI.Path); } }
public int sceFontGetCharGlyphImage(Font Font, ushort CharCode, ref GlyphImage GlyphImagePointer) { var CharInfo = Font.GetCharInfo(CharCode); return(sceFontGetCharGlyphImage_Clip( Font, CharCode, ref GlyphImagePointer, //(int)CharInfo.BitmapLeft, //(int)CharInfo.BitmapTop, 0, 0, (int)CharInfo.BitmapWidth, (int)CharInfo.BitmapHeight )); }
public int sceFontGetCharGlyphImage(FontHandle FontHandle, ushort CharCode, GlyphImage* GlyphImagePointer) { var Font = Fonts.Get(FontHandle); var CharInfo = Font.GetCharInfo(CharCode); return sceFontGetCharGlyphImage_Clip( FontHandle, CharCode, GlyphImagePointer, //(int)CharInfo.BitmapLeft, //(int)CharInfo.BitmapTop, 0, 0, (int)CharInfo.BitmapWidth, (int)CharInfo.BitmapHeight ); }
private void button1_Click_1(object sender, EventArgs e) { PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new PixelFarm.Drawing.WinGdi.GdiBitmapIO(); var storageProvider = new LocalFileStorageProvider("", true); PixelFarm.Platforms.StorageService.RegisterProvider(storageProvider); var bmpFontMx = new BitmapFontManager <MemBitmap>( _textServices, atlas => { GlyphImage totalGlyphImg = atlas.TotalGlyph; return(MemBitmap.CreateFromCopy(totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer())); } ); string multiSizeFontAtlasFilename = "tahoma_set1.multisize_fontAtlas"; string totalImgAtlasFilename = "tahoma_set1.multisize_fontAtlas.png"; //in this version, mutlsize font texture must use the same typeface { MultiSizeFontAtlasBuilder multiSizeFontAtlasBuilder = new MultiSizeFontAtlasBuilder(); { bmpFontMx.TextureKindForNewFont = PixelFarm.Drawing.BitmapAtlas.TextureKind.StencilLcdEffect; AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 10), bmpFontMx); AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 11), bmpFontMx); AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 12), bmpFontMx); AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 13), bmpFontMx); AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 14), bmpFontMx); bmpFontMx.TextureKindForNewFont = PixelFarm.Drawing.BitmapAtlas.TextureKind.Msdf; AddExistingOrCreateNewSimpleFontAtlas(multiSizeFontAtlasBuilder, new RequestFont("tahoma", 24), bmpFontMx); } //------- multiSizeFontAtlasBuilder.BuildMultiFontSize(multiSizeFontAtlasFilename, totalImgAtlasFilename); } { //test load the font altas back FontAtlasFile atlasFile = new FontAtlasFile(); using (FileStream fs = new FileStream(multiSizeFontAtlasFilename, FileMode.Open)) { atlasFile.Read(fs); } } }
private void button11_Click(object sender, EventArgs e) { unsafe { GlyphImage g1 = BuildMsdfFontImage(); int[] buffer = g1.GetImageBuffer(); using (Bitmap bmp = new Bitmap(g1.Width, g1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, g1.Width, g1.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\a001_xn1_.png"); } } }
static void SaveImgBufferToFile(GlyphImage glyphImg, string filename) { int[] intBuffer = glyphImg.GetImageBuffer(); using (System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(glyphImg.Width, glyphImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { unsafe { fixed(int *head = &intBuffer[0]) { CopyToGdiPlusBitmapSameSize((IntPtr)head, newBmp); } } //save newBmp.Save(filename); } }
/// <summary> /// test only, shapen org image with Paint.net sharpen filter /// </summary> /// <param name="org"></param> /// <param name="radius"></param> /// <returns></returns> static GlyphImage Sharpen(GlyphImage org, int radius) { GlyphImage newImg = new GlyphImage(org.Width, org.Height); Agg.Imaging.ShapenFilterPdn sharpen1 = new Agg.Imaging.ShapenFilterPdn(); int[] orgBuffer = org.GetImageBuffer(); unsafe { fixed(int *orgHeader = &orgBuffer[0]) { int[] output = sharpen1.Sharpen(orgHeader, org.Width, org.Height, org.Width * 4, radius); newImg.SetImageBuffer(output, org.IsBigEndian); } } return(newImg); }
private void button4_Click(object sender, EventArgs e) { string fontfilename = "d:\\WImageTest\\a_total.xml"; var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder(); SimpleFontAtlas fontAtlas = atlasBuilder.LoadFontInfo(fontfilename); using (Bitmap totalImg = new Bitmap("d:\\WImageTest\\a_total.png")) { var bmpdata = totalImg.LockBits(new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, totalImg.PixelFormat); var buffer = new int[totalImg.Width * totalImg.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpdata.Scan0, buffer, 0, buffer.Length); totalImg.UnlockBits(bmpdata); var glyImage = new GlyphImage(totalImg.Width, totalImg.Height); glyImage.SetImageBuffer(buffer, false); fontAtlas.TotalGlyph = glyImage; } }
void RenderWithMsdfImg(Typeface typeface, char testChar, float sizeInPoint) { painter.FillColor = PixelFarm.Drawing.Color.Black; //p.UseSubPixelRendering = chkLcdTechnique.Checked; painter.Clear(PixelFarm.Drawing.Color.White); //---------------------------------------------------- var builder = new GlyphPathBuilder(typeface); builder.SetHintTechnique(_glyphRenderOptions.HintTechnique); //---------------------------------------------------- builder.Build(testChar, sizeInPoint); //---------------------------------------------------- var glyphToContour = new GlyphContourBuilder(); var msdfGenPars = new MsdfGenParams(); builder.ReadShapes(glyphToContour); //glyphToContour.Read(builder.GetOutputPoints(), builder.GetOutputContours()); MsdfGenParams genParams = new MsdfGenParams(); GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(glyphToContour, genParams); var actualImg = ActualImage.CreateFromBuffer(glyphImg.Width, glyphImg.Height, PixelFormat.ARGB32, glyphImg.GetImageBuffer()); painter.DrawImage(actualImg, 0, 0); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png"); //} if (_contourAnalysisOpts.ShowGrid) { //render grid RenderGrids(800, 600, _gridSize, painter); } //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp); //--------------- //7. just render our bitmap g.Clear(Color.White); g.DrawImage(winBmp, new Point(30, 20)); }
static GlyphImage ReadGlyphImages(string filename) { using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Open)) { Hjg.Pngcs.PngReader reader = new Hjg.Pngcs.PngReader(fs, filename); Hjg.Pngcs.ImageInfo imgInfo = reader.ImgInfo; Hjg.Pngcs.ImageLine iline2 = new Hjg.Pngcs.ImageLine(imgInfo, Hjg.Pngcs.ImageLine.ESampleType.BYTE); int imgH = imgInfo.Rows; int imgW = imgInfo.Cols; int stride = imgInfo.BytesPerRow; int widthPx = imgInfo.Cols; int[] buffer = new int[(stride / 4) * imgH]; //read each row //and fill the glyph image int startWriteAt = (imgW * (imgH - 1)); int destIndex = startWriteAt; for (int row = 0; row < imgH; row++) { Hjg.Pngcs.ImageLine iline = reader.ReadRowByte(row); byte[] scline = iline.ScanlineB; int b_src = 0; destIndex = startWriteAt; for (int mm = 0; mm < imgW; ++mm) { byte b = scline[b_src]; byte g = scline[b_src + 1]; byte r = scline[b_src + 2]; byte a = scline[b_src + 3]; b_src += 4; buffer[destIndex] = (b << 16) | (g << 8) | (r) | (a << 24); destIndex++; } startWriteAt -= imgW; } GlyphImage img = new GlyphImage(imgW, imgH); img.SetImageBuffer(buffer, true); return(img); } }
static void CreateSampleMsdfImg(ContourBuilder tx, string outputFile) { //sample MsdfGenParams msdfGenParams = new MsdfGenParams(); GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(tx, msdfGenParams); int w = glyphImg.Width; int h = glyphImg.Height; using (Bitmap bmp = new Bitmap(glyphImg.Width, glyphImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); int[] imgBuffer = glyphImg.GetImageBuffer(); System.Runtime.InteropServices.Marshal.Copy(imgBuffer, 0, bmpdata.Scan0, imgBuffer.Length); bmp.UnlockBits(bmpdata); bmp.Save(outputFile); } }
public MySimpleGLBitmapFontManager(TextureKind textureKind, LayoutFarm.OpenFontTextService textServices) : base(textureKind, textServices) { SetLoadNewBmpDel(atlas => { //create new one GlyphImage totalGlyphImg = atlas.TotalGlyph; //load to glbmp GLBitmap found = new GLBitmap( PixelFarm.CpuBlit.MemBitmap.CreateFromCopy( totalGlyphImg.Width, totalGlyphImg.Height, totalGlyphImg.GetImageBuffer()), true); //set true=> glbmp is the original owner of the membmp, when glbmp is disposed => the membmp is disposed too found.IsYFlipped = false; return(found); }); }
private void button5_Click(object sender, EventArgs e) { //1. load font string fontName = "tahoma"; string fontfile = "c:\\Windows\\Fonts\\tahoma.ttf"; //string fontfile = @"D:\WImageTest\THSarabunNew\THSarabunNew.ttf"; ActualFont font = GetActualFont(fontfile, 18);// nativeFontStore.LoadFont(fontName, fontfile, 28); //2. get glyph var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder(); //for (int i = 0; i < 256; ++i) //BuildFontGlyphsByIndex(font, atlasBuilder, 0, 255); //BuildFontGlyphs(font, atlasBuilder, 0x0e00, 0x0e5b); //BuildFontGlyphsByIndex(font, atlasBuilder, 0, 3417); //BuildFontGlyphsByIndex(font, atlasBuilder, 0, 509); //BuildFontGlyphsByIndex(font, atlasBuilder, 97, 97); BuildFontGlyph(font, atlasBuilder, 'B'); //---------------------------------------------------- //GlyphImage totalImg = atlasBuilder.BuildSingleImage(); GlyphImage totalImg = atlasBuilder.BuildSingleImage(); using (Bitmap bmp = new Bitmap(totalImg.Width, totalImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { int[] buffer = totalImg.GetImageBuffer(); if (totalImg.IsBigEndian) { NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer); totalImg.SetImageBuffer(buffer, false); } var bmpdata = bmp.LockBits( new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\a_total.png"); } string fontfilename = "d:\\WImageTest\\a_total.xml"; atlasBuilder.SaveFontInfo(fontfilename); //---------------------------------- }
private void button1_Click(object sender, EventArgs e) { //1. MsdfGenParams msdfGenParams = new MsdfGenParams(); //GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(tx, msdfGenParams); Msdfgen.Shape shape1 = new Msdfgen.Shape(); // Msdfgen.Contour cnt = new Msdfgen.Contour(); //cnt.AddLine(0, 0, 50, 0); //cnt.AddLine(50, 0, 50, 50); //cnt.AddLine(50, 50, 0, 50); //cnt.AddLine(0, 50, 0, 0); //cnt.AddLine(10, 20, 50, 0); //cnt.AddLine(50, 0, 80, 20); //cnt.AddLine(80, 20, 50, 60); //cnt.AddLine(50, 60, 10, 20); //for msdf we draw shape clock-wise cnt.AddLine(10, 20, 50, 60); cnt.AddLine(50, 60, 80, 20); cnt.AddLine(80, 20, 50, 0); cnt.AddLine(50, 0, 10, 20); shape1.contours.Add(cnt); // // var genParams = new MsdfGenParams(); GlyphImage glyphImg = MsdfGlyphGen.CreateMsdfImage(shape1, genParams); using (Bitmap bmp = new Bitmap(glyphImg.Width, glyphImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { int[] buffer = glyphImg.GetImageBuffer(); var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, glyphImg.Width, glyphImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); bmp.UnlockBits(bmpdata); bmp.Save("d:\\WImageTest\\msdf_shape.png"); // } }
public void WriteGlyphList(Dictionary <ushort, CacheGlyph> glyphs) { _writer.Write((ushort)FontTextureObjectKind.GlyphList); //total number int totalNum = glyphs.Count; #if DEBUG if (totalNum >= ushort.MaxValue) { throw new NotSupportedException(); } #endif _writer.Write((ushort)totalNum); // foreach (CacheGlyph g in glyphs.Values) { //1. code point _writer.Write((ushort)g.glyphIndex); //2. area, left,top,width,height _writer.Write((ushort)g.area.Left); _writer.Write((ushort)g.area.Top); _writer.Write((ushort)g.area.Width); _writer.Write((ushort)g.area.Height); //3. border x,y if ((g.borderX > byte.MaxValue) || (g.borderY > byte.MaxValue)) { throw new NotSupportedException(); } _writer.Write((ushort)(((g.borderY & 0xff) << 8) | (g.borderX & 0xff))); //4. texture offset GlyphImage img = g.img; _writer.Write((float)img.TextureOffsetX); _writer.Write((float)img.TextureOffsetY); } }
static void SaveImgBufferToFile(GlyphImage glyphImg, string filename) { //------------- int[] intBuffer = glyphImg.GetImageBuffer(); using (System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create)) { int imgW = glyphImg.Width; int imgH = glyphImg.Height; Hjg.Pngcs.ImageInfo imgInfo = new Hjg.Pngcs.ImageInfo(imgW, imgH, 8, true); //8 bits per channel with alpha Hjg.Pngcs.PngWriter writer = new Hjg.Pngcs.PngWriter(fs, imgInfo); Hjg.Pngcs.ImageLine iline = new Hjg.Pngcs.ImageLine(imgInfo, Hjg.Pngcs.ImageLine.ESampleType.BYTE); int startReadAt = 0; int imgStride = imgW * 4; int srcIndex = 0; int srcIndexRowHead = intBuffer.Length - imgW; for (int row = 0; row < imgH; row++) { byte[] scanlineBuffer = iline.ScanlineB; srcIndex = srcIndexRowHead; for (int b = 0; b < imgStride;) { int srcInt = intBuffer[srcIndex]; srcIndex++; scanlineBuffer[b] = (byte)((srcInt >> 16) & 0xff); scanlineBuffer[b + 1] = (byte)((srcInt >> 8) & 0xff); scanlineBuffer[b + 2] = (byte)((srcInt) & 0xff); scanlineBuffer[b + 3] = (byte)((srcInt >> 24) & 0xff); b += 4; } srcIndexRowHead -= imgW; startReadAt += imgStride; writer.WriteRow(iline, row); } writer.End(); } }
static void BuildFontGlyph(ActualFont nativefont, Typography.Rendering.SimpleFontAtlasBuilder atlasBuilder, char c) { //font glyph for specific font face FontGlyph fontGlyph = nativefont.GetGlyph(c); GlyphImage glyphImg = NativeMsdfGen.BuildMsdfFontImage(fontGlyph); int w = glyphImg.Width; int h = glyphImg.Height; int[] buffer = glyphImg.GetImageBuffer(); NativeMsdfGen.SwapColorComponentFromBigEndianToWinGdi(buffer); glyphImg.SetImageBuffer(buffer, false); atlasBuilder.AddGlyph(0, glyphImg); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_x1_" + (int)c + ".png"); //} }