示例#1
0
        private void GenerateMaterial()
        {
            if (this.material != null)
            {
                this.material.Dispose();
            }

            if (this.texture == null)
            {
                return;
            }

            // Select DrawTechnique to use
            ContentRef <DrawTechnique> technique;

            if (this.renderMode == FontRenderMode.MonochromeBitmap)
            {
                technique = DrawTechnique.Mask;
            }
            else if (this.renderMode == FontRenderMode.GrayscaleBitmap)
            {
                technique = DrawTechnique.Alpha;
            }
            else if (this.renderMode == FontRenderMode.SmoothBitmap)
            {
                technique = DrawTechnique.Alpha;
            }
            else
            {
                technique = DrawTechnique.SharpAlpha;
            }

            // Create and configure internal BatchInfo
            BatchInfo matInfo = new BatchInfo(technique, this.texture);

            if (technique == DrawTechnique.SharpAlpha)
            {
                matInfo.SetValue("smoothness", this.fontData.Metrics.Size * 4.0f);
            }
            this.material = new Material(matInfo);
        }
示例#2
0
        public FontRasterizer(FontFamily fontFamily, float emSize, FontStyle style, string extendedSet, bool antialiasing, bool monospace, FontRenderMode renderMode)
        {
            fontData = this.RenderGlyphs(
                fontFamily,
                emSize,
                style,
                !string.IsNullOrEmpty(extendedSet) ? new FontCharSet(extendedSet) : null,
                renderMode,
                antialiasing,
                monospace);

            FontGlyphData[] glyphs = fontData.Glyphs;
            if (glyphs == null)
            {
                this.charLookup = new int[0];
                return;
            }

            int maxCharVal = 0;

            for (int i = 0; i < glyphs.Length; i++)
            {
                maxCharVal = Math.Max(maxCharVal, (int)glyphs[i].Glyph);
            }

            this.charLookup = new int[maxCharVal + 1];
            for (int i = 0; i < glyphs.Length; i++)
            {
                this.charLookup[(int)glyphs[i].Glyph] = i;
            }


            this.pixmap       = new Pixmap(fontData.Bitmap);
            this.pixmap.Atlas = fontData.Atlas.ToList();

            bool isPixelGridAligned =
                renderMode == FontRenderMode.MonochromeBitmap || renderMode == FontRenderMode.GrayscaleBitmap || renderMode == FontRenderMode.ClearType;

            this.texture = new Texture(this.pixmap,
                                       TextureSizeMode.Enlarge,
                                       isPixelGridAligned ? TextureMagFilter.Nearest : TextureMagFilter.Linear,
                                       isPixelGridAligned ? TextureMinFilter.Nearest : TextureMinFilter.LinearMipmapLinear);

            // Select DrawTechnique to use
            ContentRef <DrawTechnique> technique;

            if (renderMode == FontRenderMode.ClearType)
            {
                technique = DrawTechnique.Alpha;
            }
            else if (renderMode == FontRenderMode.MonochromeBitmap)
            {
                technique = DrawTechnique.Mask;
            }
            else if (renderMode == FontRenderMode.GrayscaleBitmap)
            {
                technique = DrawTechnique.Alpha;
            }
            else if (renderMode == FontRenderMode.SmoothBitmap)
            {
                technique = DrawTechnique.Alpha;
            }
            else
            {
                technique = DrawTechnique.SharpAlpha;
            }

            // Create and configure internal BatchInfo
            BatchInfo matInfo = new BatchInfo(technique, this.texture);

            if (technique == DrawTechnique.SharpAlpha)
            {
                matInfo.SetValue("smoothness", this.fontData.Metrics.Size * 4.0f);
            }
            this.material = new Material(matInfo);

            this.kerningLookup = new FontKerningLookup(this.fontData.KerningPairs);
        }