Пример #1
0
 private static H2FontClass.H2Font getFont(string fontName)
 {
     foreach (H2FontClass.H2Font H2f in H2fonts)
     {
         if (H2f.ToString() == fontName)
         {
             return(H2f);
         }
     }
     H2FontClass.H2Font H2font = new H2FontClass.H2Font(Prefs.pathFontsFolder + fontName);
     H2fonts.Add(H2font);
     return(H2font);
 }
Пример #2
0
        public static bitmapData createText(Map map, textBlockData td, string Text, bool wrapText)
        {
            if (Text == string.Empty || td.customFont == -1)
            {
                return(null);
            }
            bitmapData bdt      = new bitmapData(td.order);
            int        width    = (td.right - td.left);
            Bitmap     textBitm = new Bitmap(width, Math.Abs(td.top - td.bottom));

            H2FontClass.H2Font H2font = getFont(fontNames[td.customFont]);

            // For Tiny text, just use our default font as it doens't really matter
            if (H2font.isLoaded && !td.tinyText)
            {
                // Replace codes such as <GamerTag>, but not "A button" and medals, etc
                Text = entity.MetaFuncs.MEStringsSelector.ReplaceCodes(Text, false);
                using (Graphics g = Graphics.FromImage(textBitm))
                {
                    Bitmap fontBitm = wrapText ?
                                      H2font.writeString(Text, width) :
                                      H2font.writeString(Text);
                    if (fontBitm != null)
                    {
                        #region Text alignment

                        int textLeft;
                        if (td.leftAligned)
                        {
                            textLeft = 0;
                        }
                        else if (td.rightAligned)
                        {
                            textLeft = (int)(width - fontBitm.Width);
                        }
                        else  // center aligned
                        {
                            textLeft = (int)(width / 2 - fontBitm.Width / 2);
                        }

                        #endregion

                        if (!wrapText)
                        {
                            g.DrawImage(fontBitm, new Point(textLeft, 0));
                            bdt.top = (short)(td.bottom);
                        }
                        else
                        {
                            g.DrawImage(fontBitm, new Point(textLeft, 0));
                            bdt.top = (short)td.top;
                        }
                        fontBitm.Dispose();
                    }
                }
            }
            else
            {
                // Replace all codes internal and font contained as windows
                // fonts will not contain the special H2 codes
                Text = entity.MetaFuncs.MEStringsSelector.ReplaceCodes(Text, true);
                using (Graphics g = Graphics.FromImage(textBitm))
                {
                    Font font = new Font(FontFamily.GenericMonospace, 5.0f);
                    if (!td.tinyText)
                    {
                        switch (td.customFont)
                        {
                        case 0:         // fixedsys-9
                            font = new Font(FontFamily.GenericMonospace, 9.0f);
                            break;

                        case 1:         // conduit-12
                            font = new Font("Arial Narrow", 12.0f);
                            break;

                        case 2:         // handel_gothic-11
                            font = new Font(FontFamily.GenericSerif, 11.0f);
                            break;

                        case 3:         // handel_gothic-24
                            font = new Font(FontFamily.GenericSerif, 24.0f);
                            break;

                        case 4:         // conduit-13
                            font = new Font(FontFamily.GenericMonospace, 13.0f);
                            break;

                        case 5:         // conduit-12
                            font = new Font(FontFamily.GenericMonospace, 12.0f);
                            break;

                        case 6:         // conduit-13
                            font = new Font(FontFamily.GenericMonospace, 13.0f);
                            break;

                        case 7:         // conduit-12
                            font = new Font(FontFamily.GenericMonospace, 12.0f);
                            break;

                        case 8:         // MSLCD-14
                            font = new Font(FontFamily.GenericSerif, 14.0f);
                            break;

                        case 9:         // conduit-16
                            font = new Font(FontFamily.GenericMonospace, 16.0f);
                            break;

                        case 10:         // handel_gothic-13
                            font = new Font(FontFamily.GenericSerif, 13.0f);
                            break;
                        }
                    }

                    #region Text alignment

                    SizeF textInfo = g.MeasureString(Text, font);
                    int   textLeft;
                    if (td.leftAligned)
                    {
                        textLeft = 0;
                    }
                    else if (td.rightAligned)
                    {
                        textLeft = (int)(width - textInfo.Width);
                    }
                    else  // center aligned
                    {
                        textLeft = (int)(width / 2 - textInfo.Width / 2);
                    }

                    #endregion

                    #region Text color
                    Brush brush = new SolidBrush(
                        Color.FromArgb(
                            (byte)(td.h2color.A == 0 ? 255 : td.h2color.A * byte.MaxValue),
                            (byte)(td.h2color.R * byte.MaxValue),
                            (byte)(td.h2color.G * byte.MaxValue),
                            (byte)(td.h2color.B * byte.MaxValue)
                            ));
                    #endregion

                    if (!wrapText)
                    {
                        g.DrawString(Text, font, brush, textLeft, 0);
                        bdt.top = (short)(td.bottom);// + textInfo.Height);
                    }
                    else
                    {
                        g.DrawString(Text, font, brush, new RectangleF(0, 0, textBitm.Width, textBitm.Height));
                        bdt.top = (short)td.top;
                    }
                }
            }
            bdt.left        = td.left;
            bdt.link        = textBitm;
            bdt.meta        = new Meta(map); // We use a null meta for drawing checks, so  make sure we have something.
            bdt.renderDepth = td.renderDepth;
            return(bdt);
        }