Example #1
0
        public override void OnGLPaint(C2DGraphics gr)
        {
            base.OnGLPaint(gr);
            if ((Text == null) || (Text.Length == 0))
                return;
            if (mGLFontCache == null)
            {
                mGLFontCache =  gr.GetFont(mGLFont);
                if (mGLFontCache == null)
                    return;
            }

            gr.SetColor(Style.ForeColor);
            int dlen = mGLFontCache.DispLength(Text);
            int x = (Width - dlen) / 2;
            if (mTextAlign == ContentAlignment.MiddleLeft)
            {
                x = 0;
            }
            else if (mTextAlign == ContentAlignment.MiddleRight)
            {
                x = Width - dlen;
            }
            int y = (Height - mGLFontCache.height) / 2;
            gr.Text(mGLFontCache, x, y, Text);
        }
        public C2DFont LoadFont(string name, string metrics)
        {
            if ((name == null) || (metrics == null))
            {
                return(null);
            }
            C2DImage img = GetImage(name);

            if (img == null)
            {
                return(null);
            }
            // string metrics = global::UV_DLP_3D_Printer.Properties.Resources.ResourceManager.GetString(name + "_metrics");
            try
            {
                MemoryStream ms   = new MemoryStream(Encoding.UTF8.GetBytes(metrics));
                XmlDocument  xdoc = new XmlDocument();
                xdoc.Load(ms);
                XmlNode rootnode = xdoc.ChildNodes[1];
                if (rootnode.Name != "fontMetrics")
                {
                    return(null);
                }

                C2DFont font = new C2DFont();
                font.image = img;
                font.chars = new C2DChar[256];
                for (int i = 0; i < 256; i++)
                {
                    font.chars[0] = null;
                }
                C2DChar chr = null;
                int     chrnum;

                foreach (XmlNode xnode in rootnode.ChildNodes)
                {
                    chrnum             = int.Parse(xnode.Attributes["key"].Value);
                    chr                = new C2DChar();
                    chr.x              = int.Parse(xnode["x"].InnerText);
                    chr.y              = int.Parse(xnode["y"].InnerText);
                    chr.w              = int.Parse(xnode["width"].InnerText);
                    chr.h              = int.Parse(xnode["height"].InnerText);
                    font.chars[chrnum] = chr;
                }
                if (chr != null)
                {
                    font.height = chr.h;
                }
                FontDbase[name] = font;
                return(font);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public void Text(C2DFont fnt, float x, float y, string text)
        {
            C2DChar chr = null;

            foreach (char ch in text)
            {
                if ((ch > 255) || (fnt.chars[ch] == null))
                {
                    continue;
                }
                chr = fnt.chars[ch];
                Image(fnt.image, chr.x, chr.y, chr.w, chr.h, x, y, chr.w, chr.h);
                x += chr.w;
            }
        }
 public void Text(C2DFont fnt, float x, float y, string text)
 {
     C2DChar chr = null;
     foreach (char ch in text)
     {
         if ((ch > 255) || (fnt.chars[ch] == null))
             continue;
         chr = fnt.chars[ch];
         Image(fnt.image, chr.x, chr.y, chr.w, chr.h, x, y, chr.w, chr.h);
         x += chr.w;
     }
 }
        public C2DFont LoadFont(string name, string metrics)
        {
            if ((name == null) || (metrics == null))
                return null;
            C2DImage img = GetImage(name);
            if (img == null)
                return null;
            // string metrics = global::UV_DLP_3D_Printer.Properties.Resources.ResourceManager.GetString(name + "_metrics");
            try
            {
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metrics));
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(ms);
                XmlNode rootnode = xdoc.ChildNodes[1];
                if (rootnode.Name != "fontMetrics")
                    return null;

                C2DFont font = new C2DFont();
                font.image = img;
                font.chars = new C2DChar[256];
                for (int i = 0; i < 256; i++)
                    font.chars[0] = null;
                C2DChar chr = null;
                int chrnum;

                foreach (XmlNode xnode in rootnode.ChildNodes)
                {
                    chrnum = int.Parse(xnode.Attributes["key"].Value);
                    chr = new C2DChar();
                    chr.x = int.Parse(xnode["x"].InnerText);
                    chr.y = int.Parse(xnode["y"].InnerText);
                    chr.w = int.Parse(xnode["width"].InnerText);
                    chr.h = int.Parse(xnode["height"].InnerText);
                    font.chars[chrnum] = chr;
                }
                if (chr != null)
                    font.height = chr.h;
                FontDbase[name] = font;
                return font;
            }
            catch (Exception)
            {
                return null;
            }
        }