public void Label(FontSet fnt, PointD pos, string txt, double size, StringAlign alignment = StringAlign.CenterCenter, double strokewidth = 0.1, bool silk = true, bool copper = false, double angle = 0, bool backside = false, bool identiconstart = false, bool identiconend = false)
        {
            var therect = new RectangleD(TopSilk.MeasureString(pos, fnt, txt, size, strokewidth, alignment, backside, angle));

            if (!backside)
            {
                ArtExclusions.Add(new RectangleD(TopSilk.MeasureString(pos, fnt, txt, size, strokewidth, alignment, backside, angle)));

//                ArtExclusions.Add(Identicon(new PointD(therect.X - size * 0.7, therect.Y + therect.Height / 2), size, txt, true));



                if (silk)
                {
                    TopSilk.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
                }
                if (copper)
                {
                    TopCopper.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
                }
            }
            else
            {
                ArtExclusions.Add(new RectangleD(BottomSilk.MeasureString(pos, fnt, txt, size, strokewidth, alignment, backside, angle)));
                if (silk)
                {
                    BottomSilk.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
                }
                if (copper)
                {
                    BottomCopper.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
                }
            }
        }
Exemplo n.º 2
0
 public void Label(FontSet fnt, PointD pos, string txt, double size, StringAlign alignment = StringAlign.CenterCenter, double strokewidth = 0.1, bool silk = true, bool copper = false, double angle = 0, bool backside = false)
 {
     if (!backside)
     {
         ArtExclusions.Add(new RectangleD(TopSilk.MeasureString(pos, fnt, txt, size, strokewidth, alignment, backside, angle)));
         if (silk)
         {
             TopSilk.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
         }
         if (copper)
         {
             TopCopper.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
         }
     }
     else
     {
         ArtExclusions.Add(new RectangleD(BottomSilk.MeasureString(pos, fnt, txt, size, strokewidth, alignment, backside, angle)));
         if (silk)
         {
             BottomSilk.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
         }
         if (copper)
         {
             BottomCopper.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
         }
     }
 }
Exemplo n.º 3
0
 public static void Paste(this BitmapData data_bac, string s, object color = null, StringAlign stringalign = StringAlign.Left, StringRowAlign stringrowalign = StringRowAlign.Up, Font font = null)
 {
     Point p = new Point();
     Bitmap bmp = s.ToBitmap(font, color, stringalign);
     switch (stringalign)
     {
         case StringAlign.Left: p.X = 0; break;
         case StringAlign.Middle: p.X = (data_bac.Width - bmp.Width) / 2; break;
         case StringAlign.Right: p.X = data_bac.Width - bmp.Width; break;
         default: throw new ArgumentException("Can't handle this parameter : stringalign");
     }
     switch(stringrowalign)
     {
         case StringRowAlign.Up: p.Y = 0; break;
         case StringRowAlign.Middle: p.Y = (data_bac.Height - bmp.Height) / 2; break;
         case StringRowAlign.Down: p.Y = data_bac.Height - bmp.Height; break;
         default: throw new ArgumentException("Can't handle this parameter : stringrowalign");
     }
     data_bac.Paste(bmp, p, ImagePasteMode.Transparent);
 }
Exemplo n.º 4
0
 public static void Paste(this BitmapData data_bac, string s, PointD _p, object color = null, Font font = null, StringAlign stringalign = StringAlign.Left, StringRowAlign stringrowalign = StringRowAlign.Up)
 {
     PointD p = new PointD(_p);
     Bitmap bmp = s.ToBitmap(font, color, stringalign);
     switch (stringalign)
     {
         case StringAlign.Left: break;
         case StringAlign.Middle: p.X -= bmp.Half().X; break;
         case StringAlign.Right: p.X -= bmp.Width; break;
         default: throw new ArgumentException("Can't handle this parameter : stringalign");
     }
     switch (stringrowalign)
     {
         case StringRowAlign.Up: break;
         case StringRowAlign.Middle: p.Y -= bmp.Half().Y; break;
         case StringRowAlign.Down: p.Y -= bmp.Height; break;
         default: throw new ArgumentException("Can't handle this parameter : stringrowalign");
     }
     data_bac.Paste(bmp
         , p
         , color != null && !((Color)color).A.EqualsTo(byte.MinValue, byte.MaxValue)
         ? ImagePasteMode.Gradient
         : ImagePasteMode.Transparent);
 }
Exemplo n.º 5
0
 public static void Paste(this BitmapData data_bac, string s, Point p, object color = null, Font font = null, StringAlign stringalign = StringAlign.Left, StringRowAlign stringrowalign = StringRowAlign.Up)
 {
     data_bac.Paste(s, new PointD(p), color, font, stringalign, stringrowalign);
 }
Exemplo n.º 6
0
 public static Bitmap ToBitmap(this string _s, Font font = null, object color = null, StringAlign stringalign = StringAlign.Left, object backcolor = null)
 {
     if (font == null) font = Default.FONT;
     if (backcolor == null) backcolor = Color.FromArgb(0, 0, 0, 0);
     Color c = color == null ? Color.FromArgb(0, 0, 0) : (Color)color;
     SizeF szf = _s.MeasureSizeF(font);
     Bitmap bmp; BITMAP.New(out bmp,szf.Ceiling(), backcolor);
     Graphics g = Graphics.FromImage(bmp.GetDataBase());
     g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
     string[] s = _s.Split("\r\n");
     Rectangle rect = default(Rectangle);
     Size sz;
     using (StringFormat format = new StringFormat(StringFormatFlags.NoClip))
     {
         for (int i = 0; i < s.Length; i++)
         {
             sz = MeasureSizeF(s[i], font).Ceiling();
             rect.Size = sz;
             rect.Y = i * bmp.Height / s.Length;
             switch (stringalign)
             {
                 case StringAlign.Left: rect.X = 0; break;
                 case StringAlign.Middle: rect.X = (bmp.Width - sz.Width) / 2; break;
                 case StringAlign.Right: rect.X = bmp.Width - sz.Width; break;
                 default: throw new ArgumentException("Can't handle this parameter : stringalign");
             }
             using (SolidBrush newsolidbrush = new SolidBrush(c))
             {
                 g.DrawString(s[i], font.GetBaseData(), newsolidbrush, rect, format);
             }
         }
     }
     return bmp;
 }
Exemplo n.º 7
0
 public unsafe static Bitmap ToBitmap(this string _s, int maxwidth, Font font, object color = null,StringAlign stringalign=StringAlign.Left, object backcolor = null, Size minsize = default(Size))
 {
     if (color == null) color = Color.FromArgb(0, 0, 0);
     if (backcolor == null) backcolor = Color.FromArgb(0, 0, 0, 0);
     if (minsize == default(Size)) minsize = new Size(0, 0);
     List<string> LINES = new List<string>();
     string[] d = _s.Split("\r\n");
     for (int i = 0; i < d.Length; i++)
     {
         int idx = 0;
         while (idx < d[i].Length)
         {
             int len = d[i].MaxLength(font, maxwidth, idx);
             int ti;
             for (ti = idx + len; ti.AtRange(0, d[i].Length - 1) && !CHAR.IsEmpty(d[i][ti]); ti--) ;
             len = ti - idx;
             LINES.Add(d[i].Substring(idx, len));
             idx += len;
             while (idx < d[i].Length && CHAR.IsEmpty(d[i][idx])) idx++;
         }
     }
     double h=0;
     for (int i = 0; i < LINES.Count; i++) h = Math.Max(LINES[i].MeasureHeightF(font), h);
     int W = Math.Max(maxwidth, minsize.Width);
     int H = Math.Max((h * LINES.Count).Round(), minsize.Height);
     if (W <= 0 || H <= 0) return null;
     Bitmap ans; BITMAP.New(out ans,W, H, backcolor);
     BitmapData data_ans = ans.GetBitmapData();
     PointD p = new PointD(0, 0);
     if (stringalign == StringAlign.Middle) p.X = 0.5 * data_ans.Width;
     else if (stringalign == StringAlign.Right) p.X = data_ans.Width;
     for (int i = 0; i < LINES.Count; i++)
     {
         data_ans.Paste(LINES[i], p, color, font, stringalign);
         p.Y += h;
     }
     ans.UnlockBits(data_ans);
     return ans;
 }
Exemplo n.º 8
0
 public static Bitmap ToBitmap(this string s, int maxwidth, int maxheight, Font font = null, object color = null, StringAlign stringalign = StringAlign.Left, object backcolor = null)
 {
     return s.ToBitmap(new Size(maxwidth, maxheight), font, color, stringalign, backcolor);
 }
Exemplo n.º 9
0
 public static Bitmap ToBitmap(this string s, Size sz, Font font = null, object color = null, StringAlign stringalign = StringAlign.Left, object backcolor = null)
 {
     font = s.MaxFont(sz, font);
     return s.ToBitmap(font, color, stringalign, backcolor);
 }
Exemplo n.º 10
0
        private static string AlignString(string input, int chars, StringAlign stringAlign)
        {
            if (input == null)
                throw new ArgumentNullException("input");
            if (chars < 0)
                throw new ArgumentOutOfRangeException("chars");

            if (input.Length < chars)
                switch (stringAlign)
                {
                    default:
                    case StringAlign.Left:
                        return string.Concat(input, new string(' ', chars - input.Length));
                    case StringAlign.CenterLeft:
                        return string.Concat(new string(' ', (chars - input.Length) / 2), input, new string(' ', chars - input.Length - (chars - input.Length) / 2));
                    case StringAlign.CenterRight:
                        return string.Concat(new string(' ', chars - input.Length - (chars - input.Length) / 2), input, new string(' ', (chars - input.Length) / 2));
                    case StringAlign.Right:
                        return string.Concat(new string(' ', chars - input.Length), input);
                }
            else if (input.Length > chars && chars >= 3)
            {
                string output = string.Concat(input.Substring(0, (chars - 3) / 2), "...", input.Substring(input.Length - (chars - 3) / 2, (chars - 3) / 2));
                switch (stringAlign)
                {
                    default:
                    case StringAlign.Left:
                    case StringAlign.CenterLeft:
                        return string.Concat(output, new string(' ', chars - output.Length));
                    case StringAlign.CenterRight:
                    case StringAlign.Right:
                        return string.Concat(new string(' ', chars - output.Length), output);
                }
            }
            else if (input.Length > chars && chars < 3)
                switch (stringAlign)
                {
                    default:
                    case StringAlign.Left:
                    case StringAlign.CenterLeft:
                        return input.Substring(0, chars);
                    case StringAlign.CenterRight:
                    case StringAlign.Right:
                        return input.Substring(input.Length - chars, chars);
                }
            else
                return input;
        }