The configuraiton used when loading a font from a qfont file.
Inheritance: QFontConfiguration
        public FontLoadDescription(String Path, float DownSampleFactor, QFontLoaderConfiguration LoaderConfig){
            Method = FontLoadMethod.QFontFile;

            this.Path = Path;
            this.DownSampleFactor = DownSampleFactor;
            this.LoaderConfig = LoaderConfig;
        }
		public QFont Load(string path, float downSampleFactor, QFontLoaderConfiguration loaderConfig)
		{
			if (loaderConfig == null)
				loaderConfig = new QFontLoaderConfiguration();

			TransformViewport? transToVp = null;
			float fontScale = 1f;
			if (loaderConfig.TransformToCurrentOrthogProjection)
				transToVp = QFont.OrthogonalTransform(out fontScale);

			QFont qfont = new QFont();
			qfont.fontData = new QFontData ();

			QFontDataInformation fontInfo = null;
			using (var fs = File.OpenRead (path))
			{
				fontInfo = qfont.fontData.LoadFromStream (fs);
			}
			var bitmapFiles = fontInfo.GenerateBitmapPageNames (path);

			var bitmapPages = new List<QBitmap> ();
			foreach (var bitmapFileName in bitmapFiles)
			{
				// TODO : GDI+ require the bitmap files to be locked as indexed image
				// during the lifetime i.e. maybe reloaded from disk
				using (var fs = File.OpenRead (bitmapFileName))
				using (var b = new Bitmap(fs))				
				{
					var qb = new QBitmap (bitmapFileName);
					bitmapPages.Add (qb);
				}
			}
			var glyphList = qfont.fontData.InitialiseQFontData (fontInfo, ref bitmapPages, downSampleFactor, loaderConfig);

			if (loaderConfig.ShadowConfig != null)
			{
				qfont.DropShadow = Helper.BuildDropShadow<QFont, QBitmap> (
					bitmapPages,
					glyphList.ToArray (),
					loaderConfig.ShadowConfig,
					Helper.ToArray (fontInfo.CharSet),
					loaderConfig.KerningConfig.alphaEmptyPixelTolerance);
			}
			qfont.fontData.InitialiseKerningPairs (fontInfo, bitmapPages, glyphList, loaderConfig);

			if (loaderConfig.ShadowConfig != null)
				qfont.Options.DropShadowActive = true;
			if (transToVp != null)
				qfont.Options.TransformToViewport = transToVp;

			return qfont;
		}
Esempio n. 3
0
        public static QFont FromQFontFile(string filePath, float downSampleFactor, QFontLoaderConfiguration loaderConfig)
        {
            if (loaderConfig == null)
                loaderConfig = new QFontLoaderConfiguration();

            TransformViewport? transToVp = null;
            float fontScale = 1f;
            if (loaderConfig.TransformToCurrentOrthogProjection)
                transToVp = OrthogonalTransform(out fontScale);

            QFont qfont = new QFont();
            qfont.fontData = Builder.LoadQFontDataFromFile(filePath, downSampleFactor * fontScale, loaderConfig);

            if (loaderConfig.ShadowConfig != null)
                qfont.Options.DropShadowActive = true;
            if (transToVp != null)
                qfont.Options.TransformToViewport = transToVp;

            return qfont;
        }
Esempio n. 4
0
 public static QFont FromQFontFile(string filePath, QFontLoaderConfiguration loaderConfig)
 {
     return FromQFontFile(filePath, 1.0f, loaderConfig);
 }
Esempio n. 5
0
 public static QFont FromQFontFile(string filePath, float downSampleFactor, QFontLoaderConfiguration loaderConfig)
 {
     QFont qfont = new QFont();
     qfont.fontLoadDescription = new FontLoadDescription(filePath,downSampleFactor,loaderConfig);
     qfont.LoadQFontFromQFontFile(qfont.fontLoadDescription);
     return qfont;
 }
Esempio n. 6
0
        private void LoadQFontFromQFontFile(FontLoadDescription loadDescription)
        {
            var loaderConfig = loadDescription.LoaderConfig;
            var filePath = loadDescription.Path;
            var downSampleFactor = loadDescription.DownSampleFactor;


            if (loaderConfig == null)
                loaderConfig = new QFontLoaderConfiguration();

            TransformViewport? transToVp = null;
            float fontScale = 1f;
            if (loaderConfig.TransformToCurrentOrthogProjection)
                transToVp = OrthogonalTransform(out fontScale);

            fontData = Builder.LoadQFontDataFromFile(filePath, downSampleFactor * fontScale, loaderConfig);
            fontData.scaleDueToTransformToViewport = fontScale;

            if (loaderConfig.ShadowConfig != null)
                Options.DropShadowActive = true;
            if (transToVp != null)
                Options.TransformToViewport = transToVp;
        }
Esempio n. 7
0
 public static QFont FromQFontFile(string filePath, QFontLoaderConfiguration loaderConfig = null, ProjectionStack proj = null)
 {
     return FromQFontFile(filePath, 1.0f, loaderConfig, proj);
 }
Esempio n. 8
0
        private void LoadQFontFromQFontFile(FontLoadDescription loadDescription)
        {
            var loaderConfig = loadDescription.LoaderConfig;
            var filePath = loadDescription.Path;
            var downSampleFactor = loadDescription.DownSampleFactor;

            if (loaderConfig == null)
                loaderConfig = new QFontLoaderConfiguration();

            fontData = Builder.LoadQFontDataFromFile(filePath, downSampleFactor, loaderConfig);
            LoadTextures(fontData);
            fontData.scaleDueToTransformToViewport = 1f;

            if (loaderConfig.ShadowConfig != null)
                Options.DropShadowActive = true;
        }
Esempio n. 9
0
 public static QFont FromQFontFile(IFontRenderer renderer, string filePath, float downSampleFactor = 1.0f, QFontLoaderConfiguration loaderConfig = null)
 {
     QFont qfont = new QFont(renderer);
     qfont.fontLoadDescription = new FontLoadDescription(filePath,downSampleFactor,loaderConfig);
     qfont.LoadQFontFromQFontFile(qfont.fontLoadDescription);
     return qfont;
 }
Esempio n. 10
0
        public static QFontData LoadQFontDataFromFile(string filePath, float downSampleFactor, QFontLoaderConfiguration loaderConfig)
        {
            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(" ", "");

            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));
            }

            foreach (var glyph in data.CharSetMapping.Values)
                RetargetGlyphRectangleOutwards(bitmapPages[glyph.page].BitmapData, glyph, false, loaderConfig.KerningConfig.alphaEmptyPixelTolerance);

            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.");
            }

            if (downSampleFactor > 1.0f)
            {
                foreach (var page in bitmapPages)
                    page.DownScale32((int)(page.Bitmap.Width * downSampleFactor), (int)(page.Bitmap.Height * downSampleFactor));

                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));
                    glyph.yOffset = (int)(glyph.yOffset * downSampleFactor);
                }
            }
            else if (downSampleFactor < 1.0f )
            {
                // If we were simply to shrink the entire texture, then at some point we will make glyphs overlap, breaking the font.
                // For this reason it is necessary to copy every glyph to a separate bitmap, and then shrink each bitmap individually.
                QFontGlyph[] shrunkGlyphs;
                QBitmap[] shrunkBitmapsPerGlyph;
                CreateBitmapPerGlyph(Helper.ToArray(data.CharSetMapping.Values), bitmapPages.ToArray(), out shrunkGlyphs, out shrunkBitmapsPerGlyph);

                //shrink each bitmap
                for (int i = 0; i < shrunkGlyphs.Length; i++)
                {
                    var bmp = shrunkBitmapsPerGlyph[i];
                    bmp.DownScale32(Math.Max((int)(bmp.Bitmap.Width * downSampleFactor),1), Math.Max((int)(bmp.Bitmap.Height * downSampleFactor),1));
                    shrunkGlyphs[i].rect = new Rectangle(0, 0, bmp.Bitmap.Width, bmp.Bitmap.Height);
                    shrunkGlyphs[i].yOffset = (int)(shrunkGlyphs[i].yOffset * downSampleFactor);
                }

                var shrunkBitmapData = new BitmapData[shrunkBitmapsPerGlyph.Length];
                for(int i = 0; i < shrunkBitmapsPerGlyph.Length; i ++ ){
                    shrunkBitmapData[i] = shrunkBitmapsPerGlyph[i].BitmapData;
                }

                //use roughly the same number of pages as before..
                int newWidth = (int)(bitmapPages[0].Bitmap.Width * (0.1f + downSampleFactor));
                int newHeight = (int)(bitmapPages[0].Bitmap.Height * (0.1f + downSampleFactor));

                //free old bitmap pages since we are about to chuck them away
                for (int i = 0; i < pageCount; i++)
                    bitmapPages[i].Free();

                QFontGlyph[] shrunkRepackedGlyphs;
                bitmapPages = GenerateBitmapSheetsAndRepack(shrunkGlyphs, shrunkBitmapData, newWidth, newHeight, out shrunkRepackedGlyphs, 4, false);
                data.CharSetMapping = CreateCharGlyphMapping(shrunkRepackedGlyphs);

                pageCount = bitmapPages.Count;
            }

            data.Pages = bitmapPages.ToArray();

            if (downSampleFactor != 1.0f)
            {
                foreach (var glyph in data.CharSetMapping.Values)
                    RetargetGlyphRectangleOutwards(bitmapPages[glyph.page].BitmapData, glyph, false, loaderConfig.KerningConfig.alphaEmptyPixelTolerance);

                intercept = FirstIntercept(data.CharSetMapping);
                if (intercept != null)
                {
                    throw new Exception("Failed to load font from file. Glyphs '" + intercept[0] + "' and '" + intercept[1] + "' were overlapping. This occurred only after resizing your texture font, implying that there is a bug in QFont. ");
                }
            }

            var glyphList = new List<QFontGlyph>();

            foreach (var c in charSet)
                glyphList.Add(data.CharSetMapping[c]);

            if (loaderConfig.ShadowConfig != null)
                data.dropShadow = BuildDropShadow(bitmapPages, glyphList.ToArray(), loaderConfig.ShadowConfig, Helper.ToArray(charSet),loaderConfig.KerningConfig.alphaEmptyPixelTolerance);

            data.KerningPairs = KerningCalculator.CalculateKerning(Helper.ToArray(charSet), glyphList.ToArray(), bitmapPages, loaderConfig.KerningConfig);

            data.CalculateMeanWidth();
            data.CalculateMaxHeight();

            return data;
        }
		public NxFont Load(string filePath, float height, float downSampleFactor, NxFontLoaderConfiguration loaderConfig)
		{
			if (loaderConfig == null)
			{
				throw new ArgumentNullException ("loaderConfig");
			}

			float fontScale;
			TransformViewport? transToVp = NxFont.SetupTransformViewport (height, loaderConfig.TransformToCurrentOrthogProjection, loaderConfig.Transform, out fontScale);

			var qfont = new NxFont();
			var internalConfig = new QFontLoaderConfiguration();		
			var fontData = new QFontData ();
			qfont.SetData (fontData);

			QFontDataInformation fontInfo = null;
			using (var fs = File.OpenRead (filePath))
			{
				fontInfo = fontData.LoadFromStream (fs);
			}
			var bitmapFiles = fontInfo.GenerateBitmapPageNames (filePath);

			var bitmapPages = new List<NxBitmap> ();
			foreach (var bitmapFileName in bitmapFiles)
			{
				// TODO : STREAM BASED REPLACEMENT 
				// https://support.microsoft.com/en-us/kb/814675
				// GDI+ require the bitmap files to be locked as indexed image
				// during the lifetime i.e. maybe reloaded from disk				
				using (var fs = File.OpenRead (bitmapFileName))	
				{
					var parent = new Bitmap (fs);
					var data = parent.LockBits (
							new Rectangle(0,0, parent.Width, parent.Height)
							,System.Drawing.Imaging.ImageLockMode.ReadWrite
							,parent.PixelFormat);
					var target = new QBitmapData (data);
					var qb = new NxBitmap (parent, target);
					bitmapPages.Add (qb);
				}
			}
			var glyphList = fontData.InitialiseQFontData (fontInfo, ref bitmapPages, downSampleFactor, internalConfig);

			if (loaderConfig.ShadowConfig != null)
			{
				qfont.DropShadow = Helper.BuildDropShadow<NxFont, NxBitmap> (
					bitmapPages,
					glyphList.ToArray (),
					loaderConfig.ShadowConfig,
					Helper.ToArray (fontInfo.CharSet),
					internalConfig.KerningConfig.alphaEmptyPixelTolerance);
			}
			fontData.InitialiseKerningPairs (fontInfo, bitmapPages, glyphList, internalConfig);

			if (loaderConfig.ShadowConfig != null)
				qfont.Options.DropShadowActive = true;
			if (transToVp != null)
				qfont.Options.TransformToViewport = transToVp;

			qfont.InitialiseGlyphRenderer(loaderConfig.CharacterOutput, loaderConfig.FontGlyphRenderer, loaderConfig.DropShadowRenderer);

			return qfont;
		}
		public QFont Load(string path, QFontLoaderConfiguration loaderConfig) 
		{
			return Load(path, 1.0f, loaderConfig); 
		}
Esempio n. 13
0
 public static QFont FromQFontFile(string filePath, QFontLoaderConfiguration loaderConfig)
 {
     return(FromQFontFile(filePath, 1.0f, loaderConfig));
 }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new <see cref="FontConstructionConfig" /> with a builder configuration
 /// and optional loader configuration.
 /// </summary>
 /// <param name="buildConfig">The builder configuration to use.</param>
 /// <param name="loadConfig">Optional loader configuration to set.</param>
 public FontConstructionConfig(QFontBuilderConfiguration buildConfig, QFontLoaderConfiguration loadConfig = null)
 {
     BuildConfig = buildConfig;
     LoadConfig = loadConfig;
 }
Esempio n. 15
0
 /// <summary>
 /// Initialize a new <see cref="FontConstructionConfig" /> with a load configuration.
 /// </summary>
 /// <param name="loadConfig">The <see cref="QFontLoaderConfiguration" /> to use.</param>
 public FontConstructionConfig(QFontLoaderConfiguration loadConfig)
     : this(null, loadConfig)
 {
 }