public Builder(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) { this.charSet = config.charSet; this.config = config; this.shadowConfig = shadowConfig; this.font = font; }
public NxFontLoaderConfiguration (IDrawCommandList charOutput, Matrix4 transform, bool addDropShadow) { CharacterOutput = charOutput; Transform = transform; if (addDropShadow) this.ShadowConfig = new QFontShadowConfiguration(); }
public QFont(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) { if (config == null) config = new QFontBuilderConfiguration(); fontData = BuildFont(font, config, shadowConfig, null); if (shadowConfig != null) options.DropShadowActive = true; }
public static QFont FromQFontFile(string filePath, float downSampleFactor, QFontShadowConfiguration shadowConfig) { QFont qfont = new QFont(); qfont.fontData = Builder.LoadQFontDataFromFile(filePath, downSampleFactor, shadowConfig); if (shadowConfig != null) { qfont.options.DropShadowActive = true; } return(qfont); }
public QFont(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) { if (config == null) { config = new QFontBuilderConfiguration(); } fontData = BuildFont(font, config, shadowConfig, null); if (shadowConfig != null) { options.DropShadowActive = true; } }
public QFont(string fileName, float size, FontStyle style, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) { PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile(fileName); var fontFamily = pfc.Families[0]; if (!fontFamily.IsStyleAvailable(style)) throw new ArgumentException("Font file: " + fileName + " does not support style: " + style ); if (config == null) config = new QFontBuilderConfiguration(); using (var font = new Font(fontFamily, size * config.SuperSampleLevels, style)) { fontData = BuildFont(font, config, shadowConfig, null); } if (shadowConfig != null) options.DropShadowActive = true; }
public QFont(string fontname, byte[] fontresource, float size, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) : this(fontname, fontresource, size, FontStyle.Regular, config, shadowConfig) { }
public static QFont FromQFontFile(string filePath,float downSampleFactor, QFontShadowConfiguration shadowConfig) { QFont qfont = new QFont(); qfont.fontData = Builder.LoadQFontDataFromFile(filePath,downSampleFactor,shadowConfig); if (shadowConfig != null) qfont.options.DropShadowActive = true; return qfont; }
public QFont(Font font, QFontShadowConfiguration shadowConfig) : this(font, null, shadowConfig) { }
public QFont(string fontname, byte[] fontresource, float size, FontStyle style, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) { // This should be probably a field of some class PrivateFontCollection pfc = new PrivateFontCollection(); // allocate memory and copy byte[] to the location IntPtr data = Marshal.AllocCoTaskMem(fontresource.Length); Marshal.Copy(fontresource, 0, data, fontresource.Length); // pass the font to the font collection pfc.AddMemoryFont(data, fontresource.Length); var fontFamily = pfc.Families[0]; if (!fontFamily.IsStyleAvailable(style)) throw new ArgumentException("Font Resource: " + fontname + " does not support style: " + style); if (config == null) config = new QFontBuilderConfiguration(); using (var font = new Font(fontFamily, size * config.SuperSampleLevels, style)) { fontData = BuildFont(font, config, shadowConfig, null); } if (shadowConfig != null) options.DropShadowActive = true; // Free the unsafe memory Marshal.FreeCoTaskMem(data); }
public static QFont FromQFontFile(string filePath, QFontShadowConfiguration shadowConfig) { return FromQFontFile(filePath, 1.0f, shadowConfig); }
private static QFont BuildDropShadow(List<QBitmap> sourceFontSheets, QFontGlyph[] sourceFontGlyphs, QFontShadowConfiguration shadowConfig, char[] charSet, byte alphaTolerance) { QFontGlyph[] newGlyphs; var sourceBitmapData = new List<BitmapData>(); foreach(var sourceSheet in sourceFontSheets) sourceBitmapData.Add(sourceSheet.bitmapData); var bitmapSheets = GenerateBitmapSheetsAndRepack(sourceFontGlyphs, sourceBitmapData.ToArray(), shadowConfig.PageMaxTextureSize, shadowConfig.PageMaxTextureSize, out newGlyphs, shadowConfig.GlyphMargin + shadowConfig.blurRadius*3); //scale up in case we wanted bigger/smaller shadows if (shadowConfig.Scale != 1.0f) ScaleSheetsAndGlyphs(bitmapSheets, newGlyphs, shadowConfig.Scale); //no point in retargeting yet, since we will do it after blur //whiten and blur foreach (var bitmapSheet in bitmapSheets) { bitmapSheet.Colour32(255, 255, 255); if (shadowConfig.Type == ShadowType.Blurred) bitmapSheet.BlurAlpha(shadowConfig.blurRadius, shadowConfig.blurPasses); else bitmapSheet.ExpandAlpha(shadowConfig.blurRadius, shadowConfig.blurPasses); } //retarget after blur and scale RetargetAllGlyphs(bitmapSheets, newGlyphs, alphaTolerance); //create list of texture pages var newTextureSheets = new List<TexturePage>(); foreach (var page in bitmapSheets) newTextureSheets.Add(new TexturePage(page.bitmapData)); var fontData = new QFontData(); fontData.CharSetMapping = new Dictionary<char, QFontGlyph>(); for(int i = 0; i < charSet.Length; i++) fontData.CharSetMapping.Add(charSet[i],newGlyphs[i]); fontData.Pages = newTextureSheets.ToArray(); fontData.CalculateMeanWidth(); fontData.CalculateMaxHeight(); foreach (var sheet in bitmapSheets) sheet.Free(); fontData.isDropShadow = true; return new QFont(fontData); }
public static QFont FromQFontFile(string filePath, QFontShadowConfiguration shadowConfig) { return(FromQFontFile(filePath, 1.0f, shadowConfig)); }
private static QFontData BuildFont(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig, string saveName) { Builder builder = new Builder(font, config, shadowConfig); return builder.BuildFontData(saveName); }
public QFont(string fileName, float size, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) : this(fileName, size, FontStyle.Regular, config, shadowConfig) { }
public QFont(string fileName, float size, FontStyle style, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) { PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile(fileName); var fontFamily = pfc.Families[0]; if (!fontFamily.IsStyleAvailable(style)) { throw new ArgumentException("Font file: " + fileName + " does not support style: " + style); } if (config == null) { config = new QFontBuilderConfiguration(); } using (var font = new Font(fontFamily, size * config.SuperSampleLevels, style)) { fontData = BuildFont(font, config, shadowConfig, null); } if (shadowConfig != null) { options.DropShadowActive = true; } }
public QFont(string fileName, float size, FontStyle style, QFontShadowConfiguration shadowConfig) : this(fileName, size, style, null, shadowConfig) { }
private static QFontData BuildFont(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig, string saveName) { Builder builder = new Builder(font, config, shadowConfig); return(builder.BuildFontData(saveName)); }
/* * public static QFontData LoadQFontDataFromFile(string filePath) * { * return LoadQFontDataFromFile(filePath, 1.0f); * }*/ public static QFontData LoadQFontDataFromFile(string filePath, float downSampleFactor, QFontShadowConfiguration shadowConfig) { var lines = new List <String>(); StreamReader reader = new StreamReader(filePath); string line; while ((line = reader.ReadLine()) != null) { lines.Add(line); } reader.Close(); var data = new QFontData(); int pageCount = 0; char[] charSet; data.Deserialize(lines, out pageCount, out charSet); string namePrefix = filePath.Replace(".qfont", "").Replace(" ", ""); data.Pages = new TexturePage[pageCount]; var bitmapPages = new List <QBitmap>(); if (pageCount == 1) { bitmapPages.Add(new QBitmap(namePrefix + ".png")); } else { for (int i = 0; i < pageCount; i++) { bitmapPages.Add(new QBitmap(namePrefix + "_sheet_" + i)); } } if (downSampleFactor != 1.0f) { foreach (var page in bitmapPages) { page.DownScale32((int)(page.bitmap.Width * downSampleFactor), (int)(page.bitmap.Height * downSampleFactor)); } } for (int i = 0; i < pageCount; i++) { data.Pages[i] = new TexturePage(bitmapPages[i].bitmapData); } foreach (var glyph in data.CharSetMapping.Values) { glyph.rect = new Rectangle((int)(glyph.rect.X * downSampleFactor), (int)(glyph.rect.Y * downSampleFactor), (int)(glyph.rect.Width * downSampleFactor), (int)(glyph.rect.Height * downSampleFactor)); RetargetGlyphRectangleOutwards(bitmapPages[glyph.page].bitmapData, glyph, false); glyph.yOffset = (int)(glyph.yOffset * downSampleFactor); } var intercept = FirstIntercept(data.CharSetMapping); if (intercept != null) { throw new Exception("Failed to load font from file. Glyphs '" + intercept[0] + "' and '" + intercept[1] + "' were overlapping. If you are texturing your font without locking pixel opacity, then consider using a larger glyph margin. This can be done by setting QFontBuilderConfiguration myQfontBuilderConfig.GlyphMargin, and passing it into CreateTextureFontFiles."); } var glyphList = new List <QFontGlyph>(); foreach (var c in charSet) { glyphList.Add(data.CharSetMapping[c]); } if (shadowConfig != null) { data.dropShadow = BuildDropShadow(bitmapPages, glyphList.ToArray(), shadowConfig, charSet.ToArray()); } data.KerningPairs = KerningCalculator.CalculateKerning(charSet.ToArray(), glyphList.ToArray(), bitmapPages); data.CalculateMeanWidth(); data.CalculateMaxHeight(); for (int i = 0; i < pageCount; i++) { bitmapPages[i].Free(); } return(data); }
private static QFont BuildDropShadow(List <QBitmap> sourceFontSheets, QFontGlyph[] sourceFontGlyphs, QFontShadowConfiguration shadowConfig, char[] charSet, byte alphaTolerance) { QFontGlyph[] newGlyphs; var sourceBitmapData = new List <BitmapData>(); foreach (var sourceSheet in sourceFontSheets) { sourceBitmapData.Add(sourceSheet.bitmapData); } //GenerateBitmapSheetsAndRepack(QFontGlyph[] sourceGlyphs, BitmapData[] sourceBitmaps, int destSheetWidth, int destSheetHeight, out QFontGlyph[] destGlyphs, int destMargin, bool usePowerOfTwo) var bitmapSheets = GenerateBitmapSheetsAndRepack(sourceFontGlyphs, sourceBitmapData.ToArray(), shadowConfig.PageWidth, shadowConfig.PageHeight, out newGlyphs, shadowConfig.GlyphMargin + shadowConfig.blurRadius * 3, shadowConfig.ForcePowerOfTwo); //scale up in case we wanted bigger/smaller shadows if (shadowConfig.Scale != 1.0f) { ScaleSheetsAndGlyphs(bitmapSheets, newGlyphs, shadowConfig.Scale); //no point in retargeting yet, since we will do it after blur } //blacken and blur foreach (var bitmapSheet in bitmapSheets) { bitmapSheet.Colour32(0, 0, 0); bitmapSheet.BlurAlpha(shadowConfig.blurRadius, shadowConfig.blurPasses); } //retarget after blur and scale RetargetAllGlyphs(bitmapSheets, newGlyphs, alphaTolerance); //create list of texture pages var newTextureSheets = new List <TexturePage>(); foreach (var page in bitmapSheets) { newTextureSheets.Add(new TexturePage(page.bitmapData)); } var fontData = new QFontData(); fontData.CharSetMapping = new Dictionary <char, QFontGlyph>(); for (int i = 0; i < charSet.Length; i++) { fontData.CharSetMapping.Add(charSet[i], newGlyphs[i]); } fontData.Pages = newTextureSheets.ToArray(); fontData.CalculateMeanWidth(); fontData.CalculateMaxHeight(); foreach (var sheet in bitmapSheets) { sheet.Free(); } return(new QFont(fontData)); }
public QFont(string fontname, byte[] fontresource, float size, FontStyle style, QFontShadowConfiguration shadowConfig) : this(fontname, fontresource, size, style, null, shadowConfig) { }
/* public static QFontData LoadQFontDataFromFile(string filePath) { return LoadQFontDataFromFile(filePath, 1.0f); }*/ public static QFontData LoadQFontDataFromFile(string filePath, float downSampleFactor, QFontShadowConfiguration shadowConfig) { var lines = new List<String>(); StreamReader reader = new StreamReader(filePath); string line; while((line = reader.ReadLine()) != null) lines.Add(line); reader.Close(); var data = new QFontData(); int pageCount = 0; char[] charSet; data.Deserialize(lines, out pageCount, out charSet); string namePrefix = filePath.Replace(".qfont","").Replace(" ", ""); data.Pages = new TexturePage[pageCount]; var bitmapPages = new List<QBitmap>(); if (pageCount == 1) { bitmapPages.Add(new QBitmap(namePrefix + ".png")); } else { for (int i = 0; i < pageCount; i++) bitmapPages.Add(new QBitmap(namePrefix + "_sheet_" + i)); } if (downSampleFactor != 1.0f) { foreach (var page in bitmapPages) page.DownScale32((int)(page.bitmap.Width * downSampleFactor), (int)(page.bitmap.Height * downSampleFactor)); } for(int i = 0; i < pageCount; i ++ ) data.Pages[i] = new TexturePage(bitmapPages[i].bitmapData); foreach (var glyph in data.CharSetMapping.Values) { glyph.rect = new Rectangle((int)(glyph.rect.X * downSampleFactor), (int)(glyph.rect.Y * downSampleFactor), (int)(glyph.rect.Width * downSampleFactor), (int)(glyph.rect.Height * downSampleFactor)); RetargetGlyphRectangleOutwards(bitmapPages[glyph.page].bitmapData, glyph,false); glyph.yOffset = (int)(glyph.yOffset * downSampleFactor); } var intercept = FirstIntercept(data.CharSetMapping); if (intercept != null) { throw new Exception("Failed to load font from file. Glyphs '" + intercept[0] + "' and '" + intercept[1] + "' were overlapping. If you are texturing your font without locking pixel opacity, then consider using a larger glyph margin. This can be done by setting QFontBuilderConfiguration myQfontBuilderConfig.GlyphMargin, and passing it into CreateTextureFontFiles."); } var glyphList = new List<QFontGlyph>(); foreach (var c in charSet) glyphList.Add(data.CharSetMapping[c]); if (shadowConfig != null) data.dropShadow = BuildDropShadow(bitmapPages, glyphList.ToArray(), shadowConfig, charSet.ToArray()); data.KerningPairs = KerningCalculator.CalculateKerning(charSet.ToArray(), glyphList.ToArray(), bitmapPages); data.CalculateMeanWidth(); data.CalculateMaxHeight(); for (int i = 0; i < pageCount; i++) bitmapPages[i].Free(); return data; }
public QFont(string fontname, byte[] fontresource, float size, FontStyle style, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) { // This should be probably a field of some class PrivateFontCollection pfc = new PrivateFontCollection(); // allocate memory and copy byte[] to the location IntPtr data = Marshal.AllocCoTaskMem(fontresource.Length); Marshal.Copy(fontresource, 0, data, fontresource.Length); // pass the font to the font collection pfc.AddMemoryFont(data, fontresource.Length); var fontFamily = pfc.Families[0]; if (!fontFamily.IsStyleAvailable(style)) { throw new ArgumentException("Font Resource: " + fontname + " does not support style: " + style); } if (config == null) { config = new QFontBuilderConfiguration(); } using (var font = new Font(fontFamily, size * config.SuperSampleLevels, style)) { fontData = BuildFont(font, config, shadowConfig, null); } if (shadowConfig != null) { options.DropShadowActive = true; } // Free the unsafe memory Marshal.FreeCoTaskMem(data); }
private static QFontData BuildDropShadow(List<QBitmap> sourceFontSheets, QFontGlyph[] sourceFontGlyphs, QFontShadowConfiguration shadowConfig, char[] charSet, byte alphaTolerance) { QFontGlyph[] newGlyphs; var sourceBitmapData = new List<BitmapData>(); foreach(var sourceSheet in sourceFontSheets) sourceBitmapData.Add(sourceSheet.BitmapData); //GenerateBitmapSheetsAndRepack(QFontGlyph[] sourceGlyphs, BitmapData[] sourceBitmaps, int destSheetWidth, int destSheetHeight, out QFontGlyph[] destGlyphs, int destMargin, bool usePowerOfTwo) var bitmapSheets = GenerateBitmapSheetsAndRepack(sourceFontGlyphs, sourceBitmapData.ToArray(), shadowConfig.PageWidth, shadowConfig.PageHeight, out newGlyphs, shadowConfig.GlyphMargin + shadowConfig.blurRadius*3, shadowConfig.ForcePowerOfTwo); //scale up in case we wanted bigger/smaller shadows if (shadowConfig.Scale != 1.0f) ScaleSheetsAndGlyphs(bitmapSheets, newGlyphs, shadowConfig.Scale); //no point in retargeting yet, since we will do it after blur //blacken and blur foreach (var bitmapSheet in bitmapSheets) { bitmapSheet.Colour32(0, 0, 0); bitmapSheet.BlurAlpha(shadowConfig.blurRadius, shadowConfig.blurPasses); } //retarget after blur and scale RetargetAllGlyphs(bitmapSheets, newGlyphs, alphaTolerance); var fontData = new QFontData(); fontData.CharSetMapping = new Dictionary<char, QFontGlyph>(); for(int i = 0; i < charSet.Length; i++) fontData.CharSetMapping.Add(charSet[i],newGlyphs[i]); fontData.Pages = bitmapSheets.ToArray(); fontData.CalculateMeanWidth(); fontData.CalculateMaxHeight(); return fontData; }
private static QFont BuildDropShadow(List <QBitmap> sourceFontSheets, QFontGlyph[] sourceFontGlyphs, QFontShadowConfiguration shadowConfig, char[] charSet, byte alphaTolerance) { QFontGlyph[] newGlyphs; var sourceBitmapData = new List <BitmapData>(); foreach (var sourceSheet in sourceFontSheets) { sourceBitmapData.Add(sourceSheet.bitmapData); } var bitmapSheets = GenerateBitmapSheetsAndRepack(sourceFontGlyphs, sourceBitmapData.ToArray(), shadowConfig.PageMaxTextureSize, shadowConfig.PageMaxTextureSize, out newGlyphs, shadowConfig.GlyphMargin + shadowConfig.blurRadius * 3); //scale up in case we wanted bigger/smaller shadows if (shadowConfig.Scale != 1.0f) { ScaleSheetsAndGlyphs(bitmapSheets, newGlyphs, shadowConfig.Scale); //no point in retargeting yet, since we will do it after blur } //whiten and blur foreach (var bitmapSheet in bitmapSheets) { bitmapSheet.Colour32(255, 255, 255); if (shadowConfig.Type == ShadowType.Blurred) { bitmapSheet.BlurAlpha(shadowConfig.blurRadius, shadowConfig.blurPasses); } else { bitmapSheet.ExpandAlpha(shadowConfig.blurRadius, shadowConfig.blurPasses); } } //retarget after blur and scale RetargetAllGlyphs(bitmapSheets, newGlyphs, alphaTolerance); //create list of texture pages var newTextureSheets = new List <TexturePage>(); foreach (var page in bitmapSheets) { newTextureSheets.Add(new TexturePage(page.bitmapData)); } var fontData = new QFontData(); fontData.CharSetMapping = new Dictionary <char, QFontGlyph>(); for (int i = 0; i < charSet.Length; i++) { fontData.CharSetMapping.Add(charSet[i], newGlyphs[i]); } fontData.Pages = newTextureSheets.ToArray(); fontData.CalculateMeanWidth(); fontData.CalculateMaxHeight(); foreach (var sheet in bitmapSheets) { sheet.Free(); } fontData.isDropShadow = true; return(new QFont(fontData)); }