示例#1
0
        /// <summary>
        /// Applies a new set of rendered glyphs to the <see cref="Font"/>, adjusts its typeface metadata
        /// re-generates texture and material.
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="atlas"></param>
        /// <param name="glyphs"></param>
        /// <param name="metrics"></param>
        public void SetGlyphData(FontData fontData)
        {
            this.ReleaseResources();

            this.fontData = fontData;

            this.GenerateCharLookup();
            this.GeneratePixmap();
            this.GenerateTexture();
            this.GenerateMaterial();
            this.GenerateKerningLookup();
        }
示例#2
0
        /// <summary>
        /// Applies a new set of rendered glyphs to the <see cref="Font"/>, adjusts its typeface metadata
        /// re-generates texture and material.
        /// </summary>
        public void SetGlyphData(FontData fontData)
        {
            this.ReleaseResources();

            // We always expect a valid data instance, fall back to
            // an internal empty one in case of null.
            this.fontData = fontData ?? EmptyData;

            this.GenerateCharLookup();
            this.GeneratePixmap();
            this.GenerateTexture();
            this.GenerateMaterial();
            this.GenerateKerningLookup();
        }
示例#3
0
        protected override void OnLoaded()
        {
            // Fall back to a default-initialized data instance, in case the actual
            // data failed to load.
            if (this.fontData == null)
            {
                this.fontData = EmptyData;
            }

            this.GenerateCharLookup();
            this.GeneratePixmap();
            this.GenerateTexture();
            this.GenerateMaterial();
            this.GenerateKerningLookup();
            base.OnLoaded();
        }
示例#4
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);
        }