Beispiel #1
0
        public static string GetStringValue(IGraphics g, string s, int width, Font2 font)
        {
            if (width < 20)
            {
                return("");
            }
            if (g.MeasureString(s, font).Width < width - 7)
            {
                return(s);
            }
            StringBuilder sb = new StringBuilder();

            foreach (char t in s)
            {
                if (g.MeasureString(sb.ToString(), font).Width < width - 21)
                {
                    sb.Append(t);
                }
                else
                {
                    break;
                }
            }
            return(sb + "...");
        }
Beispiel #2
0
        public static string[] WrapString(IGraphics g, string s, int width, Font2 font)
        {
            if (width < 20)
            {
                return(new[] { s });
            }
            if (g.MeasureString(s, font).Width < width - 7)
            {
                return(new[] { s });
            }
            s = StringUtils.ReduceWhitespace(s);
            string[]      q       = s.Split(' ');
            List <string> result  = new List <string>();
            string        current = q[0];

            for (int i = 1; i < q.Length; i++)
            {
                string next = current + " " + q[i];
                if (g.MeasureString(next, font).Width > width - 7)
                {
                    result.Add(current);
                    current = q[i];
                }
                else
                {
                    current += " " + q[i];
                }
            }
            result.Add(current);
            return(result.ToArray());
        }
Beispiel #3
0
 private static iTextSharp.text.Font GetFont(Font2 font)
 {
     iTextSharp.text.Font f = FontFactory.GetFont("c:/windows/fonts/arial.ttf", BaseFont.CP1252, BaseFont.EMBEDDED,
         font.Size*0.667f, font.Bold ? 1 : 0);
     try{
         string file;
         switch (font.Name){
             case "Lucida Sans Unicode":
                 file = "c:/windows/fonts/L_10646.TTF";
                 f = FontFactory.GetFont(file, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, font.Size*0.667f, font.Bold ? 1 : 0);
                 break;
             case "Arial Unicode MS":
                 file = "c:/windows/fonts/ARIALUNI.TTF";
                 f = FontFactory.GetFont(file, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, font.Size*0.667f, font.Bold ? 1 : 0);
                 break;
             default:
                 file = $"c:/windows/fonts/{font.Name}.ttf";
                 if (File.Exists(file)){
                     f = FontFactory.GetFont(file, BaseFont.CP1252, BaseFont.EMBEDDED, font.Size*0.667f, font.Bold ? 1 : 0);
                 }
                 break;
         }
     } catch (Exception){
         // do nothing
     }
     return f;
 }
Beispiel #4
0
 public Size2 MeasureString(string text, Font2 font, float width)
 {
     return MeasureString(text, font);
 }
Beispiel #5
0
 public Size2 MeasureString(string text, Font2 font)
 {
     SetFont(font);
     Chunk chunk = new Chunk(text, GetFont(font));
     return new Size2(chunk.GetWidthPoint()*1.5f, font.Height*0.5f*1.5f);
 }
Beispiel #6
0
 /// <summary>
 /// Draws the specified text string at the specified location with the specified Brush and Font objects.
 /// </summary>
 /// <param name="s">String to draw.</param>
 /// <param name="font">Font that defines the text format of the string.</param>
 /// <param name="brush">Brush that determines the color and texture of the drawn text.</param>
 /// <param name="rectangleF">System.Drawing.RectangleF structure that specifies the location of the drawn text.</param>
 /// <param name="format">System.Drawing.StringFormat that specifies formatting attributes, such as line spacing and alignment, that are applied to the drawn text.</param>
 public void DrawString(string s, Font2 font, Brush2 brush, Rectangle2 rectangleF, StringFormat2 format)
 {
     if (format != null && rectangleF.Width > 0){
         switch (format.Alignment){
             case StringAlignment2.Center:
                 rectangleF.X += (rectangleF.Width - MeasureString(s, font, (int) rectangleF.Width, format).Width)*0.5f;
                 break;
             case StringAlignment2.Far:
                 rectangleF.X += rectangleF.Width - MeasureString(s, font, (int) rectangleF.Width, format).Width;
                 break;
         }
     }
     textList.Add(new Text{
         X = rectangleF.X,
         Y = rectangleF.Y + (font.Height*0.5f),
         FontFamily = font.Name,
         FontSize = font.Size*1.2f,
         FontWeight = font.Bold ? "bold" : "normal",
         Value = s,
         Fill = BrushColor(brush),
         Transform = Transform
     });
 }
 public void OnPaint(IGraphics g, int xm, int ym, int width, int height)
 {
     if (!Visible){
         return;
     }
     if (TotalMax == double.NegativeInfinity){
         return;
     }
     if ((indicator1 != -1 && indicator2 != -1) || (ZoomType == AxisZoomType.Indicate && !IsFullZoom())){
         if (IsValid()){
             PaintIndicator(g, width, height);
         }
     }
     Pen2 forePen = new Pen2(ForeColor, LineWidth);
     Pen2 majorTicPen = new Pen2(ForeColor, MajorTickLineWidth);
     Pen2 minorTicPen = new Pen2(ForeColor, MinorTickLineWidth);
     Brush2 brush = new Brush2(ForeColor);
     g.SmoothingMode = SmoothingMode2.AntiAlias;
     string label = Text ?? "";
     float x0;
     float y0;
     int decade = 0;
     double[][] tics = null;
     double max = 0;
     if (IsValid()){
         decade = (int) Math.Floor(Math.Log(Math.Max(Math.Abs(VisibleMax), Math.Abs(VisibleMin)))/Math.Log(10));
         if (decade > 0 && decade < MaxNumIntegerDigits){
             decade = 0;
         }
         if (decade != 0 && !IsLogarithmic){
             label += " [1" + ToSuperscript(decade) + ']';
         }
         tics = GetTics(GetLength(width, height));
         if (tics == null){
             return;
         }
         max = Math.Max(Math.Abs(ArrayUtils.Max(tics[0])), Math.Abs(ArrayUtils.Min(tics[0])));
     }
     Font2 font = labelFont;
     while (g.MeasureString(label, font).Width > Math.Max(width, height)*0.95f && font.Size > 5f){
         font = new Font2(font.Name, font.Size - 0.5f, font.Style);
     }
     switch (Positioning){
         case AxisPositioning.Top:
             y0 = height - 1;
             g.DrawLine(forePen, xm, ym + y0, xm + width, ym + y0);
             if (IsValid() && tics != null){
                 int previousstringEnd = -Sign*int.MaxValue;
                 for (int i = 0; i < tics[0].Length; i++){
                     x0 = ModelToView(tics[0][i], width, height);
                     g.DrawLine(majorTicPen, xm + x0, ym + y0, xm + x0, ym + y0 - MajorTickLength);
                     string s = GetTicLabel(tics[0][i], decade, max);
                     int w = (int) g.MeasureString(s, numbersFont).Width;
                     int pos = (int) (x0 - w/2.0);
                     pos = Math.Max(-2, pos);
                     pos = Math.Min(width - w + 2, pos);
                     if (Sign*pos > Sign*previousstringEnd){
                         DrawString(g, s, numbersFont, brush, xm + pos + 1, ym + y0 - MajorTickLength - numbersFont.Height);
                         previousstringEnd = pos + Sign*w;
                     }
                 }
                 for (int i = 0; i < tics[1].Length; i++){
                     x0 = ModelToView(tics[1][i], width, height);
                     g.DrawLine(minorTicPen, xm + x0, ym + y0, xm + x0, ym + y0 - MinorTickLength);
                 }
             }
             DrawString(g, label, font, brush, xm + (width)/2 - (int) g.MeasureString(label, font).Width/2,
                 ym + y0 - MajorTickLength - labelFont.Height - 12);
             break;
         case AxisPositioning.Left:
             x0 = width - 1;
             g.DrawLine(forePen, xm + x0, ym, xm + x0, ym + height);
             if (IsValid() && tics != null){
                 int previousstringEnd = -Sign*Int32.MaxValue;
                 for (int i = 0; i < tics[0].Length; i++){
                     y0 = ModelToView(tics[0][i], width, height);
                     g.DrawLine(majorTicPen, xm + x0, ym + y0, xm + x0 - MajorTickLength, ym + y0);
                     string s = GetTicLabel(tics[0][i], decade, max);
                     int w = (int) g.MeasureString(s, numbersFont).Width;
                     int pos = (int) (y0 + w/2.0) + 1;
                     pos = Math.Max(w - 2, pos);
                     pos = Math.Min(height + 2, pos);
                     if (Sign*pos > Sign*previousstringEnd){
                         g.RotateTransform(-90);
                         DrawString(g, s, numbersFont, brush, -pos - ym, xm + x0 - MajorTickLength - numbersFont.Height);
                         g.RotateTransform(90);
                         previousstringEnd = pos + Sign*w;
                     }
                 }
                 for (int i = 0; i < tics[1].Length; i++){
                     y0 = ModelToView(tics[1][i], width, height);
                     g.DrawLine(minorTicPen, xm + x0, ym + y0, xm + x0 - MinorTickLength, ym + y0);
                 }
             }
             g.RotateTransform(-90);
             float x = -height/2 - (int) g.MeasureString(label, font).Width/2;
             float y = x0 - MajorTickLength - labelFont.Height - numbersFont.Height - 10;
             if (y < 0){
                 y = 0;
             }
             DrawString(g, label, font, brush, -ym + x, xm + y - 2);
             g.RotateTransform(90);
             break;
         case AxisPositioning.Bottom:
             y0 = 0;
             g.DrawLine(forePen, xm, ym + y0, xm + width, ym + y0);
             if (IsValid() && tics != null){
                 int previousstringEnd = -Sign*Int32.MaxValue;
                 for (int i = 0; i < tics[0].Length; i++){
                     x0 = ModelToView(tics[0][i], width, height);
                     g.DrawLine(majorTicPen, xm + x0, ym + y0, xm + x0, ym + y0 + MajorTickLength);
                     string s = GetTicLabel(tics[0][i], decade, max);
                     int w = (int) g.MeasureString(s, numbersFont).Width;
                     int pos = (int) (x0 - w/2.0);
                     pos = Math.Max(-2, pos);
                     pos = Math.Min(width - w + 2, pos);
                     if (Sign*pos > Sign*previousstringEnd){
                         DrawString(g, s, numbersFont, brush, xm + pos + 1, ym + y0 + 1 + MajorTickLength - 1);
                         previousstringEnd = pos + Sign*w;
                     }
                 }
                 for (int i = 0; i < tics[1].Length; i++){
                     x0 = ModelToView(tics[1][i], width, height);
                     g.DrawLine(minorTicPen, xm + x0, ym + y0, xm + x0, ym + y0 + MinorTickLength);
                 }
             }
             DrawString(g, label, font, brush, xm + (width)/2 - (int) g.MeasureString(label, font).Width/2,
                 ym + y0 + MajorTickLength + 12);
             break;
         case AxisPositioning.Right:
             x0 = 0;
             g.DrawLine(forePen, xm + x0, ym, xm + x0, ym + height);
             if (IsValid() && tics != null){
                 int previousstringEnd = -Sign*Int32.MaxValue;
                 for (int i = 0; i < tics[0].Length; i++){
                     y0 = ModelToView(tics[0][i], width, height);
                     g.DrawLine(majorTicPen, xm + x0, ym + y0, xm + x0 + MajorTickLength, ym + y0);
                     string s = GetTicLabel(tics[0][i], decade, max);
                     int w = (int) g.MeasureString(s, numbersFont).Width;
                     int pos = (int) (y0 - w/2.0);
                     pos = Math.Max(-2, pos);
                     pos = Math.Min(height - w + 2, pos);
                     if (Sign*pos > Sign*previousstringEnd){
                         g.RotateTransform(90);
                         DrawString(g, s, numbersFont, brush, ym + pos + 1, -xm - MajorTickLength - numbersFont.Height*0.99f);
                         g.RotateTransform(-90);
                         previousstringEnd = pos + Sign*w;
                     }
                 }
                 for (int i = 0; i < tics[1].Length; i++){
                     y0 = ModelToView(tics[1][i], width, height);
                     g.DrawLine(minorTicPen, xm + x0, ym + y0, xm + x0 + MinorTickLength, ym + y0);
                 }
             }
             g.RotateTransform(90);
             DrawString(g, label, font, brush, ym + height/2 - (int) g.MeasureString(label, font).Width/2,
                 -xm - MajorTickLength - numbersFont.Height - labelFont.Height - 3);
             g.RotateTransform(-90);
             break;
     }
 }
Beispiel #8
0
 public static string[] WrapString(IGraphics g, string s, int width, Font2 font)
 {
     if (width < 20){
         return new[]{s};
     }
     if (g.MeasureString(s, font).Width < width - 7){
         return new[]{s};
     }
     s = StringUtils.ReduceWhitespace(s);
     string[] q = s.Split(' ');
     List<string> result = new List<string>();
     string current = q[0];
     for (int i = 1; i < q.Length; i++){
         string next = current + " " + q[i];
         if (g.MeasureString(next, font).Width > width - 7){
             result.Add(current);
             current = q[i];
         } else{
             current += " " + q[i];
         }
     }
     result.Add(current);
     return result.ToArray();
 }
Beispiel #9
0
 public void DrawString(string s, Font2 font, Brush2 brush, float x, float y)
 {
     StringFormat2 format = new StringFormat2{Alignment = StringAlignment2.Near, LineAlignment = StringAlignment2.Near};
     DrawString(s, font, brush, new Rectangle2(new Point2(x, y), MeasureString(s, font)), format);
 }
Beispiel #10
0
 public Size2 MeasureString(string text, Font2 font, float width)
 {
     return GraphUtils.ToSizeF2(TextRenderer.MeasureText(text, GraphUtils.ToFont(font)));
 }
Beispiel #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="text"></param>
 /// <param name="font"></param>
 /// <param name="width"></param>
 /// <param name="format"></param>
 /// <returns></returns>
 public SizeF MeasureString(string text, Font2 font, int width, StringFormat2 format)
 {
     TextFormatFlags flags = new TextFormatFlags();
     if (format != null){
         switch (format.Alignment){
             case StringAlignment2.Center:
                 flags = TextFormatFlags.HorizontalCenter;
                 break;
             case StringAlignment2.Near:
                 flags = TextFormatFlags.Left | TextFormatFlags.Top;
                 break;
             case StringAlignment2.Far:
                 flags = TextFormatFlags.Right | TextFormatFlags.Bottom;
                 break;
         }
     }
     return TextRenderer.MeasureText(text, GraphUtils.ToFont(font), new Size(width, font.Height), flags);
 }
Beispiel #12
0
 public void DrawString(string s, Font2 font, Brush2 brush, Rectangle2 rectangleF)
 {
     DrawString(s, font, brush, rectangleF, null);
 }
Beispiel #13
0
 public void DrawString(string s, Font2 font, Brush2 brush, Point2 point, StringFormat2 format)
 {
     DrawString(s, font, brush, new Rectangle2(point, Size2.Empty), format);
 }
Beispiel #14
0
 /// <summary>
 /// Draws the specified text string at the specified location with the specified Brush and Font objects.
 /// </summary>
 /// <param name="s">String to draw.</param>
 /// <param name="font">Font that defines the text format of the string.</param>
 /// <param name="brush">Brush that determines the color and texture of the drawn text.</param>
 /// <param name="location">The location of the upper-left corner of the drawn text.</param>
 public void DrawString(string s, Font2 font, Brush2 brush, Point2 location)
 {
     DrawString(s, font, brush, new Rectangle2(location, Size2.Empty), null);
 }
Beispiel #15
0
 private void SetFont(Font2 font)
 {
     iTextSharp.text.Font f = GetFont(font);
     template.SetFontAndSize(f.BaseFont, font.Size);
 }
Beispiel #16
0
 public static string GetStringValue(IGraphics g, string s, int width, Font2 font)
 {
     if (width < 20){
         return "";
     }
     if (g.MeasureString(s, font).Width < width - 7){
         return s;
     }
     StringBuilder sb = new StringBuilder();
     foreach (char t in s){
         if (g.MeasureString(sb.ToString(), font).Width < width - 21){
             sb.Append(t);
         } else{
             break;
         }
     }
     return sb + "...";
 }
Beispiel #17
0
 public void DrawString(string s, Font2 font, Brush2 brush, Point2 point, StringFormat2 format)
 {
     DrawString(s, font, brush, new Rectangle2(point, MeasureString(s, font)), format);
 }
Beispiel #18
0
 public static Font ToFont(Font2 f)
 {
     return new Font(f.Name, f.Size, ToFontStyle(f.Style));
 }
Beispiel #19
0
 public void DrawString(string s, Font2 font, Brush2 brush, Rectangle2 rectangleF, StringFormat2 format)
 {
     template.BeginText();
     SetFont(font);
     SetBrush(brush);
     float x = rectangleF.X;
     float y = rectangleF.Y - 1;
     Size2 size = MeasureString(s, font);
     if (format != null){
         switch (format.Alignment){
             case StringAlignment2.Center:
                 x = x + (rectangleF.Width - size.Width)/2f;
                 break;
             case StringAlignment2.Near:
                 x = x + 2;
                 break;
             case StringAlignment2.Far:
                 x = x + (rectangleF.Width - size.Width) - 2;
                 break;
         }
         switch (format.LineAlignment){
             case StringAlignment2.Center:
                 y = y + font.Height/2f;
                 break;
             case StringAlignment2.Near:
                 y = y + 2;
                 break;
             case StringAlignment2.Far:
                 y = y + font.Height;
                 break;
         }
     }
     template.SetTextMatrix(x, currentHeight - y - (font.Height*0.5f*1.5f));
     template.ShowText(s.TrimStart().TrimEnd());
     template.EndText();
 }
 private static void DrawString(IGraphics g, string s, Font2 font, Brush2 brush, float x, float y)
 {
     try{
         g.DrawString(s, font, brush, x, y);
     } catch (Exception){}
 }
Beispiel #21
0
 public void DrawString(string s, Font2 font, Brush2 brush, Point2 location)
 {
     DrawString(s, font, brush, new Rectangle2(location, new Size2(0, 0)), new StringFormat2());
 }
Beispiel #22
0
 public void DrawString(string s, Font2 font, Brush2 brush, Rectangle2 rectangleF)
 {
     DrawString(s, font, brush, rectangleF, new StringFormat2());
 }
Beispiel #23
0
 /// <summary>
 /// Draws the specified text string at the specified location with the specified Brush and Font objects.
 /// </summary>
 /// <param name="s">String to draw.</param>
 /// <param name="font">Font that defines the text format of the string.</param>
 /// <param name="brush">Brush that determines the color and texture of the drawn text.</param>
 /// <param name="x">The x-coordinate of the upper-left corner of the drawn text.</param>
 /// <param name="y">The y-coordinate of the upper-left corner of the drawn text.</param>
 public void DrawString(string s, Font2 font, Brush2 brush, float x, float y)
 {
     DrawString(s, font, brush, new Rectangle2(x, y, 0, 0), null);
 }