The configuration used when building a font drop shadow.
예제 #1
0
 public Builder(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig)
 {
     this.charSet = config.charSet;
     this.config = config;
     this.shadowConfig = shadowConfig;
     this.font = font;
 }
예제 #2
0
 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();
		}
예제 #4
0
        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;
        }
예제 #5
0
        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);
        }
예제 #6
0
        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;
            }
        }
예제 #7
0
        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;
        }
예제 #8
0
 public QFont(string fontname, byte[] fontresource, float size, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) : this(fontname, fontresource, size, FontStyle.Regular, config, shadowConfig)
 {
 }
예제 #9
0
        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;
        }
예제 #10
0
 public QFont(Font font, QFontShadowConfiguration shadowConfig)
     : this(font, null, shadowConfig)
 {
 }
예제 #11
0
        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);
        }
예제 #12
0
 public static QFont FromQFontFile(string filePath, QFontShadowConfiguration shadowConfig)
 {
     return FromQFontFile(filePath, 1.0f, shadowConfig);
 }
예제 #13
0
파일: Builder.cs 프로젝트: vescon/QuickFont
        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);
        }
예제 #14
0
 public static QFont FromQFontFile(string filePath, QFontShadowConfiguration shadowConfig)
 {
     return(FromQFontFile(filePath, 1.0f, shadowConfig));
 }
예제 #15
0
 private static QFontData BuildFont(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig, string saveName)
 {
     Builder builder = new Builder(font, config, shadowConfig);
     return builder.BuildFontData(saveName);
 }
예제 #16
0
 public QFont(string fileName, float size, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig)
     : this(fileName, size, FontStyle.Regular, config, shadowConfig)
 {
 }
예제 #17
0
        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;
            }
        }
예제 #18
0
 public QFont(string fileName, float size, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig) : this(fileName, size, FontStyle.Regular, config, shadowConfig)
 {
 }
예제 #19
0
 public QFont(string fileName, float size, FontStyle style, QFontShadowConfiguration shadowConfig) : this(fileName, size, style, null, shadowConfig)
 {
 }
예제 #20
0
        private static QFontData BuildFont(Font font, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig, string saveName)
        {
            Builder builder = new Builder(font, config, shadowConfig);

            return(builder.BuildFontData(saveName));
        }
예제 #21
0
 public QFont(Font font, QFontShadowConfiguration shadowConfig) : this(font, null, shadowConfig)
 {
 }
예제 #22
0
 public QFont(string fileName, float size, FontStyle style, QFontShadowConfiguration shadowConfig)
     : this(fileName, size, style, null, shadowConfig)
 {
 }
예제 #23
0
        /*
         * 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);
        }
예제 #24
0
        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));
        }
예제 #25
0
 public QFont(string fontname, byte[] fontresource, float size, FontStyle style, QFontShadowConfiguration shadowConfig) : this(fontname, fontresource, size, style, null, shadowConfig)
 {
 }
예제 #26
0
        /*
        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;
        }
예제 #27
0
        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);
        }
예제 #28
0
파일: Builder.cs 프로젝트: rumkex/QuickFont
        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;
        }
예제 #29
0
 public QFont(string fontname, byte[] fontresource, float size, FontStyle style, QFontShadowConfiguration shadowConfig)
     : this(fontname, fontresource, size, style, null, shadowConfig)
 {
 }
예제 #30
0
        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));
        }
예제 #31
0
 public QFont(string fontname, byte[] fontresource, float size, QFontBuilderConfiguration config, QFontShadowConfiguration shadowConfig)
     : this(fontname, fontresource, size, FontStyle.Regular, config, shadowConfig)
 {
 }