Ejemplo n.º 1
0
        private static Graphicsstrsizetype getGraphicsstrsize(Graphics g, string word, Font font)
        {
            Graphicsstrsizetype graphicsstrsizetype = new Graphicsstrsizetype
            {
                ziwidth  = 0f,
                ziheight = 0f
            };
            Graphicsstrsizetype result;

            if (word == "")
            {
                result = graphicsstrsizetype;
            }
            else
            {
                Rectangle        r = new Rectangle(0, 0, 32768, 1000);
                CharacterRange[] measurableCharacterRanges = new CharacterRange[]
                {
                    new CharacterRange(0, word.Length)
                };
                Region[] array = new Region[1];
                gdizi.measureStringFormat.SetMeasurableCharacterRanges(measurableCharacterRanges);
                array = g.MeasureCharacterRanges(word, font, r, gdizi.measureStringFormat);
                graphicsstrsizetype.ziwidth  = array[0].GetBounds(g).Right;
                graphicsstrsizetype.ziheight = array[0].GetBounds(g).Height + array[0].GetBounds(g).Top;
                result = graphicsstrsizetype;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static showzitype_ GetGraphicszipos(string str, showzitype_ zipos, int width, int height)
        {
            Bitmap      image       = new Bitmap(1, 1);
            showzitype_ showzitype_ = zipos;
            showzitype_ result;

            if (str == "" || width < 2 || height < 2)
            {
                showzitype_.zisize = 1f;
                result             = showzitype_;
            }
            else
            {
                if (showzitype_.zisize < (float)(height / 4) || showzitype_.zisize > (float)(height * 3 / 2))
                {
                    showzitype_.zisize = (float)height;
                }
                gdizi.gc = Graphics.FromImage(image);
                Font font = new Font(showzitype_.ziti, showzitype_.zisize, showzitype_.fonstyl);
                Graphicsstrsizetype graphicsstrsize = gdizi.getGraphicsstrsize(gdizi.gc, str, font);
                if (graphicsstrsize.ziwidth < 1f)
                {
                    showzitype_.zisize = 1f;
                    result             = showzitype_;
                }
                else
                {
                    if ((float)width - graphicsstrsize.ziwidth > 1f && (float)height - graphicsstrsize.ziheight > 1f)
                    {
                        while ((float)width - graphicsstrsize.ziwidth > 1f && (float)height - graphicsstrsize.ziheight > 1f)
                        {
                            showzitype_.zisize += 0.5f;
                            font            = new Font(showzitype_.ziti, showzitype_.zisize, showzitype_.fonstyl);
                            graphicsstrsize = gdizi.getGraphicsstrsize(gdizi.gc, str, font);
                        }
                    }
                    if (graphicsstrsize.ziwidth > (float)width || graphicsstrsize.ziheight > (float)height)
                    {
                        while (graphicsstrsize.ziwidth > (float)width || graphicsstrsize.ziheight > (float)height)
                        {
                            showzitype_.zisize -= 0.5f;
                            font            = new Font(showzitype_.ziti, showzitype_.zisize, showzitype_.fonstyl);
                            graphicsstrsize = gdizi.getGraphicsstrsize(gdizi.gc, str, font);
                        }
                    }
                    result = showzitype_;
                }
            }
            return(result);
        }