public List<PageItem> Process(int Flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;
            try
            {
                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);

                Byte[] PrivateData = _br.ReadBytes(RecordData.Length);
                //Ok we should have our private data which I am storing my tooltip value in...
                //now lets interpret it...            
                string PData = new System.Text.ASCIIEncoding().GetString(PrivateData);
                //If string starts with "ToolTip" then lets do something with it.. otherwise I don't care about it.
                if (PData.StartsWith("ToolTip"))
                {
                    PageRectangle pr = new PageRectangle();
                    StyleInfo si = new StyleInfo();
                    pr.SI = si;
                    //si.BackgroundColor = Color.Blue;// Just a test to see where the tooltip is being drawn
                    string[] ttd = PData.Split('|');
                    pr.Tooltip = ttd[0].Split(':')[1];
                    pr.X = X + Single.Parse(ttd[1].Split(':')[1]) * SCALEFACTOR;
                    pr.Y = Y + Single.Parse(ttd[2].Split(':')[1]) * SCALEFACTOR;
                    pr.W = Single.Parse(ttd[3].Split(':')[1]) * SCALEFACTOR;
                    pr.H = Single.Parse(ttd[4].Split(':')[1]) * SCALEFACTOR;
                    items.Add(pr);
                }
                else if (PData.StartsWith("PolyToolTip"))
                {
                    PagePolygon pp = new PagePolygon();
                    StyleInfo si = new StyleInfo();
                    pp.SI = si;
                    //si.BackgroundColor = Color.Blue;// Just a test to see where the tooltip is being drawn
                    string[] ttd = PData.Split('|');
                    PointF[] pts = new PointF[(ttd.Length - 1) / 2];
                    pp.Points = pts;
                    pp.Tooltip = ttd[0].Split(':')[1];
                    for (int i = 0; i < pts.Length; i++)
                    {
                        pts[i].X = X + Single.Parse(ttd[i*2 +1]) * SCALEFACTOR;
                        pts[i].Y = Y + Single.Parse(ttd[i*2 +2]) * SCALEFACTOR;
                    }
                    items.Add(pp);
                }
                return items;
            }

            finally
            {
                if (_br != null)
                    _br.Close();
                if (_ms != null)
                    _ms.Dispose();

            }
        }
示例#2
0
 //
 internal void AddCurve(PointF[] pts, StyleInfo si)
 {
     if (pts.Length > 2)
     {   // do a spline curve
         PointF[] tangents = GetCurveTangents(pts);
         DoCurve(pts, tangents, si);
     }
     else
     {   // we only have two points; just do a line segment
         AddLine(pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, si);
     }
 }
示例#3
0
		internal string GetPdfFont(StyleInfo si)
		{
			string face = FontNameNormalize(si.FontFamily);
			if (face == "Times-Roman" &&
				(si.IsFontBold() || si.FontStyle == FontStyleEnum.Italic))
				face = "Times";

			if (si.IsFontBold() && 
				si.FontStyle == FontStyleEnum.Italic)	// bold and italic?
				face = face + "-BoldOblique";
			else if (si.IsFontBold())			// just bold?
				face = face + "-Bold";
			else if (si.FontStyle == FontStyleEnum.Italic)
				face = face + "-Oblique";

			return GetPdfFont(face);
		}
示例#4
0
 /// <summary>
 /// Draw a pie
 /// </summary>
 /// <returns></returns>
 internal abstract protected void AddPie(float x, float y, float height, float width, StyleInfo si, string url, string tooltip);
示例#5
0
 /// <summary>
 /// Draw a curve
 /// </summary>
 /// <returns></returns>
 protected internal abstract void AddCurve(PointF[] pts, StyleInfo si);
示例#6
0
        //25072008 GJL Draw a bezier curve
        private void iAddCurve(float X1, float Y1, float X2, float Y2, float X3, float Y3, float X4, float Y4, StyleInfo si, string url)
        {

            if (si.BStyleTop != BorderStyleEnum.None)
            {
                switch (si.BStyleTop)
                {
                    case BorderStyleEnum.Dashed:
                        cb.SetLineDash(new float[] { '3', '2' }, 0);
                        break;
                    case BorderStyleEnum.Dotted:
                        cb.SetLineDash(new float[] { '2' }, 0);
                        break;
                    case BorderStyleEnum.Solid:
                    default:
                        cb.SetLineDash(new float[] { }, 0);
                        break;
                }
                cb.SetRGBColorStroke(si.BColorTop.R, si.BColorTop.G, si.BColorTop.B);
            }

            if (!si.BackgroundColor.IsEmpty)
            {
                cb.SetRGBColorStrokeF(si.BackgroundColor.R, si.BackgroundColor.G, si.BackgroundColor.B);
            }
            cb.CurveTo(X1, _pSize.yHeight - Y1, X2, _pSize.yHeight - Y1, X3, _pSize.yHeight - Y3);
            if (si.BackgroundColor.IsEmpty)
                cb.ClosePathStroke();
            else
                cb.ClosePathFillStroke();
        }
示例#7
0
 internal void Dispose()
 {
     si     = null;
     parent = null;
 }
示例#8
0
        private void HandleStyleFontWeight(StyleInfo si, string w)
        {
            try
            {
                switch (w)
                {
                case "bold":
                    si.FontWeight = FontWeightEnum.Bold;
                    break;

                case "bolder":
                    if (si.FontWeight > FontWeightEnum.Bolder)
                    {
                        if (si.FontWeight < FontWeightEnum.W900)
                        {
                            si.FontWeight++;
                        }
                    }
                    else if (si.FontWeight == FontWeightEnum.Normal)
                    {
                        si.FontWeight = FontWeightEnum.W700;
                    }
                    else if (si.FontWeight == FontWeightEnum.Bold)
                    {
                        si.FontWeight = FontWeightEnum.W900;
                    }
                    else if (si.FontWeight != FontWeightEnum.Bolder)
                    {
                        si.FontWeight = FontWeightEnum.Normal;
                    }
                    break;

                case "lighter":
                    if (si.FontWeight > FontWeightEnum.Bolder)
                    {
                        if (si.FontWeight > FontWeightEnum.W100)
                        {
                            si.FontWeight--;
                        }
                    }
                    else if (si.FontWeight == FontWeightEnum.Normal)
                    {
                        si.FontWeight = FontWeightEnum.W300;
                    }
                    else if (si.FontWeight == FontWeightEnum.Bold)
                    {
                        si.FontWeight = FontWeightEnum.W400;
                    }
                    else if (si.FontWeight != FontWeightEnum.Lighter)
                    {
                        si.FontWeight = FontWeightEnum.Normal;
                    }
                    break;

                case "normal":
                    si.FontWeight = FontWeightEnum.Normal;
                    break;

                case "100":
                    si.FontWeight = FontWeightEnum.W100;
                    break;

                case "200":
                    si.FontWeight = FontWeightEnum.W200;
                    break;

                case "300":
                    si.FontWeight = FontWeightEnum.W300;
                    break;

                case "400":
                    si.FontWeight = FontWeightEnum.W400;
                    break;

                case "500":
                    si.FontWeight = FontWeightEnum.W500;
                    break;

                case "600":
                    si.FontWeight = FontWeightEnum.W600;
                    break;

                case "700":
                    si.FontWeight = FontWeightEnum.W700;
                    break;

                case "800":
                    si.FontWeight = FontWeightEnum.W800;
                    break;

                case "900":
                    si.FontWeight = FontWeightEnum.W900;
                    break;
                }
            }
            catch {}                            // lots of user errors will cause an exception; ignore
            return;
        }
示例#9
0
 /// <summary>
 /// Page Text element at the X Y position; multiple lines handled
 /// </summary>
 /// <returns></returns>
 internal abstract protected void AddText(float x, float y, float height, float width, string[] sa,
                                          StyleInfo si, float[] tw, bool bWrap, string url, bool bNoClip, string tooltip);
示例#10
0
        public void TableRowStart(TableRow tr, Row row)
        {
            Table  t    = null;
            Header head = null;

            for (ReportLink rl = tr.Parent.Parent; rl != null; rl = rl.Parent)
            {
                if (rl is Table)
                {
                    t = rl as Table;
                    break;
                }
                else if (rl is Header)
                {
                    head = rl as Header;
                }
            }
            if (t == null)
            {
                return;
            }

            tw.Write(@"\trowd \trql\trgaph108\trrh0\trleft236");
            if (head != null && head.RepeatOnNewPage)       // repeat table header on multiple pages
            {
                tw.Write(@"\trhdr");
            }

            int pos = 0;

            int cellIndex  = 0;
            int colLength  = t.TableColumns.Items.Count;
            int cellLength = tr.TableCells.Items.Count;

            for (int colIndex = 0; colIndex < colLength; colIndex++)
            {
                TableColumn tc = t.TableColumns[colIndex];

                pos += tc.Width.Twips;

                TableCell cell = tr.TableCells.Items[cellIndex];

                if (cell.ColSpan > 1)
                {
                    for (int k = 1; k < cell.ColSpan; k++)
                    {
                        pos += t.TableColumns[colIndex + k].Width.Twips;
                    }
                }

                string border = @"\clbrdrt\brdrth\clbrdrl\brdrs\clbrdrb\brdrs\clbrdrr\brdrs";
                if (cellIndex < cellLength)
                {
                    ReportItem ri = tr.TableCells.Items[cellIndex].ReportItems[0];

                    if (ri.Style != null)
                    {
                        StyleInfo si = ri.Style.GetStyleInfo(r, row);
                        border = string.Format(@"\clbrdrt\{0}\clbrdrl\{1}\clbrdrb\{2}\clbrdrr\{3}",
                                               GetBorderStyle(si.BStyleTop),
                                               GetBorderStyle(si.BStyleLeft),
                                               GetBorderStyle(si.BStyleBottom),
                                               GetBorderStyle(si.BStyleRight));

                        if (si.VerticalAlign == VerticalAlignEnum.Middle)
                        {
                            border += @"\clvertalc";
                        }
                        else if (si.VerticalAlign == VerticalAlignEnum.Bottom)
                        {
                            border += @"\clvertalb";
                        }
                        else
                        {
                            border += @"\clvertalt";
                        }
                    }
                }

                tw.Write(@"{1}\cellx{0}", pos, border);

                if (cell.ColSpan > 1)
                {
                    for (int k = 1; k < cell.ColSpan; k++)
                    {
                        colIndex++;
                    }
                }

                cellIndex++;
            }
            tw.Write(@"\pard \intbl");
        }
示例#11
0
 /// <summary>
 /// Page Text element at the X Y position; multiple lines handled
 /// </summary>
 /// <returns></returns>
 protected internal abstract void AddText(float x, float y, float height, float width, string[] sa,
     StyleInfo si,  float[] tw, bool bWrap, string url, bool bNoClip, string tooltip);
示例#12
0
        private void DrawBackground(Graphics g, System.Drawing.RectangleF rect, StyleInfo si)
        {
            LinearGradientBrush linGrBrush = null;
            SolidBrush          sb         = null;

            try
            {
                if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None &&
                    !si.BackgroundGradientEndColor.IsEmpty &&
                    !si.BackgroundColor.IsEmpty)
                {
                    Color c  = si.BackgroundColor;
                    Color ec = si.BackgroundGradientEndColor;

                    switch (si.BackgroundGradientType)
                    {
                    case BackgroundGradientTypeEnum.LeftRight:
                        linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                        break;

                    case BackgroundGradientTypeEnum.TopBottom:
                        linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                        break;

                    case BackgroundGradientTypeEnum.Center:
                        linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                        break;

                    case BackgroundGradientTypeEnum.DiagonalLeft:
                        linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal);
                        break;

                    case BackgroundGradientTypeEnum.DiagonalRight:
                        linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal);
                        break;

                    case BackgroundGradientTypeEnum.HorizontalCenter:
                        linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                        break;

                    case BackgroundGradientTypeEnum.VerticalCenter:
                        linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                        break;

                    default:
                        break;
                    }
                }

                if (linGrBrush != null)
                {
                    g.FillRectangle(linGrBrush, rect);
                    linGrBrush.Dispose();
                }
                else if (!si.BackgroundColor.IsEmpty)
                {
                    sb = new SolidBrush(si.BackgroundColor);
                    g.FillRectangle(sb, rect);
                    sb.Dispose();
                }
            }
            finally
            {
                if (linGrBrush != null)
                {
                    linGrBrush.Dispose();
                }
                if (sb != null)
                {
                    sb.Dispose();
                }
            }
            return;
        }
示例#13
0
        private void DoStyle(Style style, Row row)
        {
            if (style == null)
            {
                return;
            }

            StyleInfo si = style.GetStyleInfo(r, row);

            tw.Write(@"\pard\plain");        // reset current attributes

            //Îı¾¶ÔÆë
            if (si.TextAlign == TextAlignEnum.Center)
            {
                tw.Write(@"\qc");
            }
            else if (si.TextAlign == TextAlignEnum.Right)
            {
                tw.Write(@"\qr");
            }
            else if (si.TextAlign == TextAlignEnum.Left)
            {
                tw.Write(@"\ql");
            }

            // Handle the font
            if (!_Fonts.Contains(si.FontFamily))
            {
                _Fonts.Add(si.FontFamily);
            }
            int fc = _Fonts.IndexOf(si.FontFamily);

            tw.Write(@"\f{0} ", fc);

            if (si.IsFontBold())
            {
                tw.Write(@"\b");
            }
            if (si.FontStyle == FontStyleEnum.Italic)
            {
                tw.Write(@"\i");
            }
            switch (si.TextDecoration)
            {
            case TextDecorationEnum.Underline:
                tw.Write(@"\ul");
                break;

            case TextDecorationEnum.LineThrough:
                tw.Write(@"\strike");
                break;

            default:
                break;
            }

            tw.Write(@"\fs{0}", (int)Math.Round(si.FontSize * 2, 0));        // font size

            // Handle the color
            int ic;

            if (!_Colors.Contains(si.Color))
            {
                _Colors.Add(si.Color);
            }
            ic = _Colors.IndexOf(si.Color) + 1;

            tw.Write(@"\cf{0} ", ic);
        }
示例#14
0
        private void DrawImageSized(PageImage pi, System.Drawing.Image im, System.Drawing.Graphics g, System.Drawing.RectangleF r)
        {
            float     height, width;  // some work variables
            StyleInfo si = pi.SI;

            // adjust drawing rectangle based on padding
            System.Drawing.RectangleF r2 = new System.Drawing.RectangleF(r.Left + PixelsX(si.PaddingLeft),
                                                                         r.Top + PixelsY(si.PaddingTop),
                                                                         r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                                         r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            System.Drawing.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
            case ImageSizingEnum.AutoSize:
                // Note: GDI+ will stretch an image when you only provide
                //  the left/top coordinates.  This seems pretty stupid since
                //  it results in the image being out of focus even though
                //  you don't want the image resized.
                if (g.DpiX == im.HorizontalResolution &&
                    g.DpiY == im.VerticalResolution)
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      im.Width, im.Height);
                }
                else
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                }
                g.DrawImage(im, ir);

                break;

            case ImageSizingEnum.Clip:
                Region saveRegion = g.Clip;
                Region clipRegion = new Region(g.Clip.GetRegionData());
                clipRegion.Intersect(r2);
                g.Clip = clipRegion;
                if (g.DpiX == im.HorizontalResolution &&
                    g.DpiY == im.VerticalResolution)
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      im.Width, im.Height);
                }
                else
                {
                    ir = new System.Drawing.Rectangle(Convert.ToInt32(r2.Left), Convert.ToInt32(r2.Top),
                                                      Convert.ToInt32(r2.Width), Convert.ToInt32(r2.Height));
                }
                g.DrawImage(im, ir);
                g.Clip = saveRegion;
                break;

            case ImageSizingEnum.FitProportional:
                float ratioIm = (float)im.Height / (float)im.Width;
                float ratioR  = r2.Height / r2.Width;
                height = r2.Height;
                width  = r2.Width;
                if (ratioIm > ratioR)
                {       // this means the rectangle width must be corrected
                    width = height * (1 / ratioIm);
                }
                else if (ratioIm < ratioR)
                {       // this means the ractangle height must be corrected
                    height = width * ratioIm;
                }
                r2 = new RectangleF(r2.X, r2.Y, width, height);
                g.DrawImage(im, r2);
                break;

            case ImageSizingEnum.Fit:
            default:
                g.DrawImage(im, r2);
                break;
            }
            return;
        }
示例#15
0
        private void DrawString(PageText pt, Graphics g, RectangleF r)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            Font         drawFont   = null;
            StringFormat drawFormat = null;
            Brush        drawBrush  = null;

            try
            {
                // STYLE
                System.Drawing.FontStyle fs = 0;
                if (si.FontStyle == FontStyleEnum.Italic)
                {
                    fs |= System.Drawing.FontStyle.Italic;
                }

                switch (si.TextDecoration)
                {
                case TextDecorationEnum.Underline:
                    fs |= System.Drawing.FontStyle.Underline;
                    break;

                case TextDecorationEnum.LineThrough:
                    fs |= System.Drawing.FontStyle.Strikeout;
                    break;

                case TextDecorationEnum.Overline:
                case TextDecorationEnum.None:
                    break;
                }

                // WEIGHT
                switch (si.FontWeight)
                {
                case FontWeightEnum.Bold:
                case FontWeightEnum.Bolder:
                case FontWeightEnum.W500:
                case FontWeightEnum.W600:
                case FontWeightEnum.W700:
                case FontWeightEnum.W800:
                case FontWeightEnum.W900:
                    fs |= System.Drawing.FontStyle.Bold;
                    break;

                default:
                    break;
                }
                try
                {
                    drawFont = new Font(si.GetFontFamily(), si.FontSize, fs);   // si.FontSize already in points
                }
                catch (ArgumentException)
                {
                    drawFont = new Font("Arial", si.FontSize, fs);   // if this fails we'll let the error pass thru
                }
                // ALIGNMENT
                drawFormat = new StringFormat();
                switch (si.TextAlign)
                {
                case TextAlignEnum.Right:
                    drawFormat.Alignment = StringAlignment.Far;
                    break;

                case TextAlignEnum.Center:
                    drawFormat.Alignment = StringAlignment.Center;
                    break;

                case TextAlignEnum.Left:
                default:
                    drawFormat.Alignment = StringAlignment.Near;
                    break;
                }
                if (pt.SI.WritingMode == WritingModeEnum.tb_rl)
                {
                    drawFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    drawFormat.FormatFlags |= StringFormatFlags.DirectionVertical;
                }
                switch (si.VerticalAlign)
                {
                case VerticalAlignEnum.Bottom:
                    drawFormat.LineAlignment = StringAlignment.Far;
                    break;

                case VerticalAlignEnum.Middle:
                    drawFormat.LineAlignment = StringAlignment.Center;
                    break;

                case VerticalAlignEnum.Top:
                default:
                    drawFormat.LineAlignment = StringAlignment.Near;
                    break;
                }
                // draw the background
                DrawBackground(g, r, si);

                // adjust drawing rectangle based on padding
                RectangleF r2 = new RectangleF(r.Left + si.PaddingLeft,
                                               r.Top + si.PaddingTop,
                                               r.Width - si.PaddingLeft - si.PaddingRight,
                                               r.Height - si.PaddingTop - si.PaddingBottom);

                drawBrush = new SolidBrush(si.Color);
                if (pt.NoClip)   // request not to clip text
                {
                    g.DrawString(pt.Text, drawFont, drawBrush, new PointF(r.Left, r.Top), drawFormat);
                    //HighlightString(g, pt, new RectangleF(r.Left, r.Top, float.MaxValue, float.MaxValue),drawFont, drawFormat);
                }
                else
                {
                    g.DrawString(pt.Text, drawFont, drawBrush, r2, drawFormat);
                    //HighlightString(g, pt, r2, drawFont, drawFormat);
                }
            }
            finally
            {
                if (drawFont != null)
                {
                    drawFont.Dispose();
                }
                if (drawFormat != null)
                {
                    drawFont.Dispose();
                }
                if (drawBrush != null)
                {
                    drawBrush.Dispose();
                }
            }
        }
示例#16
0
 /// <summary>
 /// Add image to the page.
 /// </summary>
 /// <returns>string Image name</returns>
 internal abstract protected void AddImage(string name, StyleInfo si,
                                           ImageFormat imf, float x, float y, float width, float height, RectangleF clipRect,
                                           byte[] im, int samplesW, int samplesH, string url, string tooltip);
示例#17
0
 /// <summary>
 /// Add image to the page.
 /// </summary>
 /// <returns>string Image name</returns>
 protected internal abstract void AddImage(string name,  StyleInfo si,
     ImageFormat imf, float x, float y, float width, float height, RectangleF clipRect,
     byte[] im, int samplesW, int samplesH, string url, string tooltip);
示例#18
0
 /// <summary>
 /// Draw a curve
 /// </summary>
 /// <returns></returns>
 internal abstract protected void AddCurve(PointF[] pts, StyleInfo si);
示例#19
0
 /// <summary>
 /// Page Polygon
 /// </summary>
 /// <param name="pts"></param>
 /// <param name="si"></param>
 /// <param name="url"></param>
 /// <param name="patterns"></param>
 protected internal abstract void AddPolygon(PointF[] pts, StyleInfo si, string url);
示例#20
0
        //25072008 GJL Draw a bezier curve
        internal void AddCurve(float X1, float Y1, float X2, float Y2, float X3, float Y3, float X4, float Y4, StyleInfo si, string url)
        {
            string linestyle;

            switch (si.BStyleTop)
            {
            case BorderStyleEnum.Dashed:
                linestyle = "[3 2] 0 d";
                break;

            case BorderStyleEnum.Dotted:
                linestyle = "[2] 0 d";
                break;

            case BorderStyleEnum.Solid:
            default:
                linestyle = "[] 0 d";
                break;
            }

            elements.AppendFormat("\r\nq\t");
            if (si.BStyleTop != BorderStyleEnum.None)
            {
                elements.AppendFormat("{0} w\t {1} \t", si.BWidthTop, linestyle);
                elements.AppendFormat("{0} {1} {2} RG\t", Math.Round(si.BColorTop.R / 255.0, 3), Math.Round(si.BColorTop.G / 255.0, 3), Math.Round(si.BColorTop.B / 255.0, 3));                 //Set Stroking colours
            }
            if (!si.BackgroundColor.IsEmpty)
            {
                elements.AppendFormat("{0} {1} {2} rg\t", Math.Round(si.BackgroundColor.R / 255.0, 3), Math.Round(si.BackgroundColor.G / 255.0, 3), Math.Round(si.BackgroundColor.B / 255.0, 3)); //Set Non Stroking colours
            }
            elements.AppendFormat("{0} {1} m\t", X1, pSize.yHeight - Y1);                                                                                                                         //FirstPoint..
            elements.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, pSize.yHeight - Y2, X3, pSize.yHeight - Y3, X4, pSize.yHeight - Y4);
            if (!si.BackgroundColor.IsEmpty && si.BStyleTop != BorderStyleEnum.None)
            {
                //Line and fill
                elements.AppendFormat("B\t");
            }
            else if (si.BStyleTop != BorderStyleEnum.None)
            {
                //Line
                elements.AppendFormat("S\t");
            }
            else if (!si.BackgroundColor.IsEmpty)
            {
                //fill
                elements.AppendFormat("f\t");
            }
            elements.AppendFormat("Q\t");
        }
示例#21
0
        private PageImage BuildImage(Graphics g, string token, StyleInfo oldsi, PageText model)
        {
            PageTextHtmlCmdLexer hc = new PageTextHtmlCmdLexer(token.Substring(4));
            Hashtable            ht = hc.Lex();

            string src = (string)ht["src"];

            if (src == null || src.Length < 1)
            {
                return(null);
            }

            string alt = (string)ht["alt"];

            string height = (string)ht["height"];
            string width  = (string)ht["width"];
            string align  = (string)ht["align"];

            Stream strm = null;

            System.Drawing.Image im = null;
            PageImage            pi = null;

            try
            {
                // Obtain the image stream
                if (src.StartsWith("http:") ||
                    src.StartsWith("file:") ||
                    src.StartsWith("https:"))
                {
                    WebRequest  wreq = WebRequest.Create(src);
                    WebResponse wres = wreq.GetResponse();
                    strm = wres.GetResponseStream();
                }
                else
                {
                    strm = new FileStream(src, System.IO.FileMode.Open, FileAccess.Read);
                }

                im = System.Drawing.Image.FromStream(strm);
                int          h     = im.Height;
                int          w     = im.Width;
                MemoryStream ostrm = new MemoryStream();
                ImageFormat  imf;
                imf = ImageFormat.Jpeg;
                im.Save(ostrm, imf);
                byte[] ba = ostrm.ToArray();
                ostrm.Close();
                pi             = new PageImage(imf, ba, w, h);
                pi.AllowSelect = false;
                pi.Page        = this.Page;
                pi.HyperLink   = model.HyperLink;
                pi.Tooltip     = alt == null ? model.Tooltip : alt;
                pi.X           = 0;
                pi.Y           = 0;

                pi.W  = RSize.PointsFromPixels(g, width != null? Convert.ToInt32(width): w);
                pi.H  = RSize.PointsFromPixels(g, height != null? Convert.ToInt32(height): h);
                pi.SI = new StyleInfo();
            }
            catch
            {
                pi = null;
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
                if (im != null)
                {
                    im.Dispose();
                }
            }

            return(pi);
        }
示例#22
0
        //25072008 GJL Draw 4 bezier curves to approximate a circle
        internal void AddEllipse(float x, float y, float height, float width, StyleInfo si, string url)
        {
            //Ok we need to draw 4 bezier curves - Unfortunately we cant call drawcurve 4 times because of the fill - we would end up drawing 4 filled arcs with an empty diamond in the middle
            //but we will still include a drawcurve function - it may be usefull one day
            float k       = 0.5522847498f;
            float RadiusX = (width / 2.0f);
            float RadiusY = (height / 2.0f);
            float kRy     = k * RadiusY;
            float kRx     = k * RadiusX;

            float Y4 = y;
            float X1 = x;
            float Y1 = Y4 + RadiusY;
            float X4 = X1 + RadiusX;
            //Control Point 1 will be on the same X as point 1 and be -kRy Y
            float X2 = X1;
            float Y2 = Y1 - kRy;
            float X3 = X4 - kRx;
            float Y3 = Y4;

            elements.AppendFormat("\r\nq\t");
            elements.AppendFormat("{0} {1} m\t", X1, pSize.yHeight - Y1);  //FirstPoint..

            if (si.BStyleTop != BorderStyleEnum.None)
            {
                string linestyle;
                switch (si.BStyleTop)
                {
                case BorderStyleEnum.Dashed:
                    linestyle = "[3 2] 0 d";
                    break;

                case BorderStyleEnum.Dotted:
                    linestyle = "[2] 0 d";
                    break;

                case BorderStyleEnum.Solid:
                default:
                    linestyle = "[] 0 d";
                    break;
                }
                elements.AppendFormat("{0} w\t {1} \t", si.BWidthTop, linestyle);
                elements.AppendFormat("{0} {1} {2} RG\t", Math.Round(si.BColorTop.R / 255.0, 3), Math.Round(si.BColorTop.G / 255.0, 3), Math.Round(si.BColorTop.B / 255.0, 3));                         //Set Stroking colours
            }
            if (!si.BackgroundColor.IsEmpty)
            {
                elements.AppendFormat("{0} {1} {2} rg\t", Math.Round(si.BackgroundColor.R / 255.0, 3), Math.Round(si.BackgroundColor.G / 255.0, 3), Math.Round(si.BackgroundColor.B / 255.0, 3));                         //Set Non Stroking colours
            }
            elements.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, pSize.yHeight - Y2, X3, pSize.yHeight - Y3, X4, pSize.yHeight - Y4);


            X1 += 2 * RadiusX;
            X2  = X1;
            X3 += 2 * kRx;

            elements.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, pSize.yHeight - Y3, X2, pSize.yHeight - Y2, X1, pSize.yHeight - Y1);


            Y2 += 2 * kRy;
            Y3 += 2 * RadiusY;
            Y4  = Y3;

            elements.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, pSize.yHeight - Y2, X3, pSize.yHeight - Y3, X4, pSize.yHeight - Y4);


            X1 -= 2 * RadiusX;
            X2  = X1;
            X3 -= 2 * kRx;

            elements.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, pSize.yHeight - Y3, X2, pSize.yHeight - Y2, X1, pSize.yHeight - Y1);


            if (!si.BackgroundColor.IsEmpty && si.BStyleTop != BorderStyleEnum.None)
            {
                //Line and fill
                elements.AppendFormat("B\t");
            }
            else if (si.BStyleTop != BorderStyleEnum.None)
            {
                //Line
                elements.AppendFormat("S\t");
            }
            else if (!si.BackgroundColor.IsEmpty)
            {
                //fill
                elements.AppendFormat("f\t");
            }

            elements.AppendFormat("Q\t");
        }
示例#23
0
        private SizeF MeasureString(string s, StyleInfo si, Graphics g, out float descent)
        {
            Font         drawFont   = null;
            StringFormat drawFormat = null;
            SizeF        ms         = SizeF.Empty;

            descent = 0;
            if (s == null || s.Length == 0)
            {
                return(ms);
            }
            try
            {
                // STYLE
                System.Drawing.FontStyle fs = 0;
                if (si.FontStyle == FontStyleEnum.Italic)
                {
                    fs |= System.Drawing.FontStyle.Italic;
                }

                // WEIGHT
                switch (si.FontWeight)
                {
                case FontWeightEnum.Bold:
                case FontWeightEnum.Bolder:
                case FontWeightEnum.W500:
                case FontWeightEnum.W600:
                case FontWeightEnum.W700:
                case FontWeightEnum.W800:
                case FontWeightEnum.W900:
                    fs |= System.Drawing.FontStyle.Bold;
                    break;

                default:
                    break;
                }
                try
                {
                    FontFamily ff = si.GetFontFamily();
                    drawFont = new Font(ff, si.FontSize, fs);
                    // following algorithm comes from the C# Font Metrics documentation
                    float descentPixel = si.FontSize * ff.GetCellDescent(fs) / ff.GetEmHeight(fs);
                    descent = RSize.PointsFromPixels(g, descentPixel);
                }
                catch
                {
                    drawFont = new Font("Arial", si.FontSize, fs);                      // usually because font not found
                    descent  = 0;
                }
                drawFormat           = new StringFormat();
                drawFormat.Alignment = StringAlignment.Near;

                CharacterRange[] cr = { new CharacterRange(0, s.Length) };
                drawFormat.SetMeasurableCharacterRanges(cr);
                Region[] rs = new Region[1];
                rs = g.MeasureCharacterRanges(s, drawFont, new RectangleF(0, 0, float.MaxValue, float.MaxValue),
                                              drawFormat);
                RectangleF mr = rs[0].GetBounds(g);

                ms.Height = RSize.PointsFromPixels(g, mr.Height);                       // convert to points from pixels
                ms.Width  = RSize.PointsFromPixels(g, mr.Width);                        // convert to points from pixels
                return(ms);
            }
            finally
            {
                if (drawFont != null)
                {
                    drawFont.Dispose();
                }
                if (drawFormat != null)
                {
                    drawFont.Dispose();
                }
            }
        }
示例#24
0
        /// <summary>
        /// Page Text element at the X Y position; multiple lines handled
        /// </summary>
        /// <returns></returns>
        internal void AddText(float x, float y, float height, float width, string[] sa,
                              StyleInfo si, PdfFonts fonts, float[] tw, bool bWrap, string url, bool bNoClip)
        {
            // Calculate the RGB colors e.g. RGB(255, 0, 0) = red = 1 0 0 rg
            double r = si.Color.R;
            double g = si.Color.G;
            double b = si.Color.B;

            r = Math.Round((r / 255), 3);
            g = Math.Round((g / 255), 3);
            b = Math.Round((b / 255), 3);

            string pdfFont = fonts.GetPdfFont(si);              // get the pdf font resource name

            // Loop thru the lines of text
            for (int i = 0; i < sa.Length; i++)
            {
                string text      = sa[i];
                float  textwidth = tw[i];
                // Calculate the x position
                float startX = x + si.PaddingLeft;                                      // TODO: handle tb_rl
                float startY = y + si.PaddingTop + (i * si.FontSize);                   // TODO: handle tb_rl

                if (si.WritingMode == WritingModeEnum.lr_tb)
                {                       // TODO: not sure what alignment means with tb_lr so I'll leave it out for now
                    switch (si.TextAlign)
                    {
                    case TextAlignEnum.Center:
                        if (width > 0)
                        {
                            startX = x + si.PaddingLeft + (width - si.PaddingLeft - si.PaddingRight) / 2 - textwidth / 2;
                        }
                        break;

                    case TextAlignEnum.Right:
                        if (width > 0)
                        {
                            startX = x + width - textwidth - si.PaddingRight;
                        }
                        break;

                    case TextAlignEnum.Left:
                    default:
                        break;
                    }

                    // Calculate the y position
                    switch (si.VerticalAlign)
                    {
                    case VerticalAlignEnum.Middle:
                        if (height <= 0)
                        {
                            break;
                        }

                        // calculate the middle of the region
                        startY = y + si.PaddingTop + (height - si.PaddingTop - si.PaddingBottom) / 2 - si.FontSize / 2;
                        // now go up or down depending on which line
                        if (sa.Length == 1)
                        {
                            break;
                        }
                        if (sa.Length % 2 == 0)                                 // even number
                        {
                            startY = startY - ((sa.Length / 2 - i) * si.FontSize) + si.FontSize / 2;
                        }
                        else
                        {
                            startY = startY - ((sa.Length / 2 - i) * si.FontSize);
                        }
                        break;

                    case VerticalAlignEnum.Bottom:
                        if (height <= 0)
                        {
                            break;
                        }

                        startY = y + height - si.PaddingBottom - (si.FontSize * (sa.Length - i));
                        break;

                    case VerticalAlignEnum.Top:
                    default:
                        break;
                    }
                }

                // Draw background rectangle if needed (only put out on the first line, since we do whole rectangle)
                if (!si.BackgroundColor.IsEmpty && height > 0 && width > 0 && i == 0)
                {                       // background color, height and width are specified
                    AddFillRect(x, y, width, height, si.BackgroundColor);
                }

                // Set the clipping path
                if (height > 0 && width > 0)
                {
                    if (bNoClip)                        // no clipping but we still want URL checking
                    {
                        elements.Append("\r\nq\t");
                    }
                    else
                    {
                        elements.AppendFormat(NumberFormatInfo.InvariantInfo,
                                              "\r\nq\t{0} {1} {2} {3} re W n",
                                              x, pSize.yHeight - y - height, width, height);
                    }
                    if (url != null)
                    {
                        p.AddHyperlink(x, pSize.yHeight - y, height, width, url);
                    }
                }
                else
                {
                    elements.Append("\r\nq\t");
                }

                // Escape the text

                string newtext = PdfUtility.UTF16StringQuoter(text);

                //string newtext = text.Replace("\\", "\\\\");
                //newtext = newtext.Replace("(", "\\(");
                //newtext = newtext.Replace(")", "\\)");

                if (si.WritingMode == WritingModeEnum.lr_tb)
                {
                    elements.AppendFormat(NumberFormatInfo.InvariantInfo,
                                          "\r\nBT/{0} {1} Tf\t{5} {6} {7} rg\t{2} {3} Td \t({4}) Tj\tET\tQ\t",
                                          pdfFont, si.FontSize, startX, (pSize.yHeight - startY - si.FontSize), newtext, r, g, b);
                }
                else
                {                       // Rotate text -90 degrees=-.5 radians (this works for english don't know about true tb-rl language)
                                        //   had to play with reader to find best approximation for this rotation; didn't do what I expected
                                        //    see pdf spec section 4.2.2 pg 141  "Common Transformations"

                    elements.AppendFormat(NumberFormatInfo.InvariantInfo,
                                          "\r\nBT/{0} {1} Tf\t{5} {6} {7} rg\t{8} {9} {10} {11} {2} {3} Tm \t({4}) Tj\tET\tQ\t",
                                          pdfFont, si.FontSize, startX, (pSize.yHeight - startY), newtext, r, g, b,
                                          radsCos, radsSin, -radsSin, radsCos);
                }

                // Handle underlining etc.
                float maxX;
                switch (si.TextDecoration)
                {
                case TextDecorationEnum.Underline:
                    maxX = width > 0? Math.Min(x + width, startX + textwidth): startX + textwidth;
                    AddLine(startX, startY + si.FontSize + 1, maxX, startY + si.FontSize + 1, 1, si.Color, BorderStyleEnum.Solid);
                    break;

                case TextDecorationEnum.LineThrough:
                    maxX = width > 0? Math.Min(x + width, startX + textwidth): startX + textwidth;
                    AddLine(startX, startY + (si.FontSize / 2) + 1, maxX, startY + (si.FontSize / 2) + 1, 1, si.Color, BorderStyleEnum.Solid);
                    break;

                case TextDecorationEnum.Overline:
                    maxX = width > 0? Math.Min(x + width, startX + textwidth): startX + textwidth;
                    AddLine(startX, startY + 1, maxX, startY + 1, 1, si.Color, BorderStyleEnum.Solid);
                    break;

                case TextDecorationEnum.None:
                default:
                    break;
                }
            }

            AddBorder(si, x, y, height, width);                                 // add any required border

            return;
        }
示例#25
0
        /// <summary>
        /// Draw a pie
        /// </summary>
        /// <returns></returns>
        private void iAddPie(float x, float y, float height, float width, StyleInfo si, string url, PdfPattern patterns, string tooltip)
        {
            // Draw background rectangle if needed
            if (!si.BackgroundColor.IsEmpty && height > 0 && width > 0)
            {	// background color, height and width are specified
                iAddFillRect(x, y, width, height, si, patterns);
            }
            iAddBorder(si, x, y, height, width);			// add any required border

            //add url
            if (url != null)
                pdfdocument.Add(new Annotation(x, _pSize.yHeight - y, width + x, height, url));
            //add tooltip
            if (!string.IsNullOrEmpty(tooltip))
                pdfdocument.Add(new Annotation(x, _pSize.yHeight - y, width + x, height, tooltip));
            return;
        }
示例#26
0
 /// <summary>
 /// Page line element at the X Y to X2 Y2 position
 /// </summary>
 /// <returns></returns>
 internal void AddLine(float x, float y, float x2, float y2, StyleInfo si)
 {
     AddLine(x, y, x2, y2, si.BWidthTop, si.BColorTop, si.BStyleTop);
 }
示例#27
0
        /// <summary>
        /// Page Text element at the X Y position; multiple lines handled
        /// </summary>
        /// <returns></returns>
		private void iAddText (float x, float y, float height, float width, string[] sa,
			StyleInfo si, PdfFonts fonts, float[] tw, bool bWrap, string url, bool bNoClip, string tooltip)
		{
			int platform = (int)Environment.OSVersion.Platform;
			int version = (int)Environment.OSVersion.Version.Major;

			BaseFont bf;
			string face = iFontNameNormalize (si.FontFamily);
			string fontname = "";
			bool fonttype1 = true;
			var folder = FontFolder; //Call to determine folder and set value of dejavuFonts;
			if (face == "Times-Roman") {
				if (si.IsFontBold () && si.FontStyle == FontStyleEnum.Italic) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "TimesNewRomanPS-BoldItalicMT";
						fontname = "Times New Roman Bold Italic.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Serif Condensed Bold Italic" : "Times-BoldItalic";
						fontname = (dejavuFonts ? "DejaVuSerifCondensed-BoldItalic.ttf" : "timesbi.ttf");
					}
				} else if (si.IsFontBold ()) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "TimesNewRomanPS-BoldMT";
						fontname = "Times New Roman Bold.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Serif Condensed Bold" : "Times-Bold";
						fontname = (dejavuFonts ? "DejaVuSerifCondensed-Bold.ttf" : "timesbd.ttf");
					}
				} else if (si.FontStyle == FontStyleEnum.Italic) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "TimesNewRomanPS-ItalicMT";
						fontname = "Times New Roman Italic.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Serif Condensed Italic" : "Times-Italic";
						fontname = (dejavuFonts ? "DejaVuSerifCondensed-Italic.ttf" : "timesi.ttf");
					}
				} else {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "TimesNewRomanPSMT";
						fontname = "Times New Roman.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Serif Condensed" : face;
						fontname = (dejavuFonts ? "DejaVuSerifCondensed.ttf" : "times.ttf");
					}
				}
				fonttype1 = false;
			} else if (face == "Arial") {
				if (si.IsFontBold () && si.FontStyle == FontStyleEnum.Italic) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "Arial BoldItalicMT";
						fontname = "Arial Bold Italic.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Condensed Bold Oblique" : "Arial-BoldItalic";
						fontname = (dejavuFonts ? "DejaVuSansCondensed-BoldOblique.ttf" : "arialbi.ttf");
					}
				} else if (si.IsFontBold ()) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "Arial-BoldMT";
						fontname = "Arial Bold.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Condensed Bold" : "Arial-Bold";
						fontname = (dejavuFonts ? "DejaVuSansCondensed-Bold.ttf" : "arialbd.ttf");
					}
				} else if (si.FontStyle == FontStyleEnum.Italic) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "Arial-ItalicMT";
						fontname = "Arial Italic.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Condensed Oblique" : "Arial-Italic";
						fontname = (dejavuFonts ? "DejaVuSansCondensed-Oblique.ttf" : "ariali.ttf");
					}
				} else {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "ArialMT";
						fontname = "Arial.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Condensed" : face;
						fontname = (dejavuFonts ? "DejaVuSansCondensed.ttf" : "arial.ttf");
					}
				}
				fonttype1 = false;
			} else if (face == "Courier New") {
				if (si.IsFontBold () && si.FontStyle == FontStyleEnum.Italic) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "CourierNewPS-BoldItalicMT";
						fontname = "Courier New Bold Italic.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Mono Bold Oblique" : "Courier New-BoldItalic";
						fontname = (dejavuFonts ? "DejaVuSansMono-BoldOblique.ttf" : "courbi.ttf");
					}
				} else if (si.IsFontBold ()) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "CourierNewPS-BoldMT";
						fontname = "Courier New Bold.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Mono Bold" : "Courier New-Bold";
						fontname = (dejavuFonts ? "DejaVuSansMono-Oblique.ttf" : "courbd.ttf");
					}
				} else if (si.FontStyle == FontStyleEnum.Italic) {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "CourierNewPS-ItalicMT";
						fontname = "Courier New Italic.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Mono Oblique" : "Courier New-Italic";
						fontname = (dejavuFonts ? "DejaVuSansMono-Oblique.ttf" : "couri.ttf");
					}
				} else {
					//OSX
					if ((platform == 4 || platform == 6 || platform == 128) && version > 8) {
						face = "CourierNewPSMT";
						fontname = "Courier New.ttf";
					} else {
						face = dejavuFonts ? "DejaVu Sans Mono" : face;
						fontname = (dejavuFonts ? "DejaVuSansMono.ttf" : "cour.ttf");
					}
				}
				fonttype1 = false;
			} else {
                        if (si.IsFontBold() &&
                    si.FontStyle == FontStyleEnum.Italic)   // bold and italic?
                            face = face + "-BoldOblique";
                        else if (si.IsFontBold())           // just bold?
                            face = face + "-Bold";
                        else if (si.FontStyle == FontStyleEnum.Italic)
                            face = face + "-Oblique";
                        fonttype1 = true;
                    }
            //Get index of fontname in List font name
            int indexbf = BaseFontsname.FindIndex(delegate(string _fontname) { return _fontname == face; });
            //If not found then add new BaseFont
            if (indexbf == -1)
            {
                BaseFontsname.Add(face);
                if (fonttype1)
                {
                    bf = BaseFont.CreateFont(face, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                }
                else
                {
                    string path = System.IO.Path.Combine(folder, fontname);
                    bf = BaseFont.CreateFont(path, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                }
                BaseFonts.Add(bf);
            }
            else
            //Get from List
            {
                bf = BaseFonts[indexbf];
            }

            // Loop thru the lines of text
            for (int i = 0; i < sa.Length; i++)
            {
                string text = sa[i];
                float textwidth = tw[i];
                // Calculate the x positino
                float startX = x + si.PaddingLeft;						// TODO: handle tb_rl
                float startY = y + si.PaddingTop + (i * si.FontSize);	// TODO: handle tb_rl
                int align = 0;
                if (si.WritingMode == WritingModeEnum.lr_tb)
                {	// TODO: not sure what alignment means with tb_lr so I'll leave it out for now
                    switch (si.TextAlign)
                    {
                        case TextAlignEnum.Center:
                            if (width > 0)
                            {
                                startX = x + si.PaddingLeft + (width - si.PaddingLeft - si.PaddingRight) / 2 - textwidth / 2;
                                align = Element.ALIGN_CENTER;
                            }
                            break;
                        case TextAlignEnum.Right:
                            if (width > 0)
                            {
                                startX = x + width - textwidth - si.PaddingRight;
                                align = Element.ALIGN_RIGHT;
                            }
                            break;
                        case TextAlignEnum.Left:
                        default:
                            align = Element.ALIGN_LEFT;
                            break;
                    }

                    // Calculate the y position
                    switch (si.VerticalAlign)
                    {
                        case VerticalAlignEnum.Middle:
                            if (height <= 0)
                                break;

                            // calculate the middle of the region
                            startY = y + si.PaddingTop + (height - si.PaddingTop - si.PaddingBottom) / 2 - si.FontSize / 2;
                            // now go up or down depending on which line
                            if (sa.Length == 1)
                                break;
                            if (sa.Length % 2 == 0)	// even number
                            {
                                startY = startY - ((sa.Length / 2 - i) * si.FontSize) + si.FontSize / 2;
                            }
                            else
                            {
                                startY = startY - ((sa.Length / 2 - i) * si.FontSize);
                            }
                            break;
                        case VerticalAlignEnum.Bottom:
                            if (height <= 0)
                                break;

                            startY = y + height - si.PaddingBottom - (si.FontSize * (sa.Length - i));
                            break;
                        case VerticalAlignEnum.Top:
                        default:
                            break;
                    }
                }
                else
                {
                    //25072008 GJL - Move x in a little - it draws to close to the edge of the rectangle (25% of the font size seems to work!) and Center or right align vertical text
                    startX += si.FontSize / 4;

                    switch (si.TextAlign)
                    {
                        case TextAlignEnum.Center:
                            if (height > 0)
                                startY = y + si.PaddingLeft + (height - si.PaddingLeft - si.PaddingRight) / 2 - textwidth / 2;
                            break;
                        case TextAlignEnum.Right:
                            if (width > 0)
                                startY = y + height - textwidth - si.PaddingRight;
                            break;
                        case TextAlignEnum.Left:
                        default:
                            break;
                    }

                }

                // Draw background rectangle if needed (only put out on the first line, since we do whole rectangle)
                if (!si.BackgroundColor.IsEmpty && height > 0 && width > 0 && i == 0)
                {	// background color, height and width are specified
                    iAddFillRect(x, y, width, height, si.BackgroundColor);
                }

                // Set the clipping path, (Itext have no clip)
                if (height > 0 && width > 0)
                {
                    cb.SetRGBColorFill(si.Color.R, si.Color.G, si.Color.B);

                    if (si.WritingMode == WritingModeEnum.lr_tb)
                    {
                        //If textline after measure with word break can fit just simple show Text
                        if (width >= textwidth)
                        {
                            cb.BeginText();
                            cb.SetFontAndSize(bf, si.FontSize);
                            cb.SetTextMatrix(startX, (_pSize.yHeight - startY - si.FontSize));
                            cb.ShowText(text);
                            cb.EndText();
                        }
                        else
                        {
                            //else use Column text to wrap or clip (wrap: for example a text like an URL so word break is not working here, itextsharp ColumnText do the work for us)
                            ColumnText ct = new ColumnText(cb);
                            Phrase myPhrase = new Phrase(text, new iTextSharp.text.Font(bf, si.FontSize));
                            ct.SetSimpleColumn(myPhrase, x + si.PaddingLeft, _pSize.yHeight - startY, x + width - si.PaddingRight, _pSize.yHeight - y - si.PaddingBottom - height, 10f, align);
                            ct.Go();
                        }
                    }
                    else
                    {
                        //Not checked
                        double rads = -283.0 / 180.0;
                        double radsCos = Math.Cos(rads);
                        double radsSin = Math.Sin(rads);
                        cb.BeginText();
                        cb.SetFontAndSize(bf, si.FontSize);
                        cb.SetTextMatrix((float)radsCos, (float)radsSin, (float)-radsSin, (float)radsCos, startX, _pSize.yHeight - startY);
                        cb.ShowText(text);
                        cb.EndText();
                    }

                    //add URL
                    if (url != null)
						pdfdocument.Add(new Annotation(x, _pSize.yHeight - (y + height), width + x, _pSize.yHeight - y, url));
                    //add tooltip
                    if (tooltip != null)
						pdfdocument.Add(new Annotation(x, _pSize.yHeight - (y + height), width + x, _pSize.yHeight - y, tooltip));

                }

                // Handle underlining etc.
                float maxX;
                switch (si.TextDecoration)
                {
                    case TextDecorationEnum.Underline:
                        maxX = width > 0 ? Math.Min(x + width, startX + textwidth) : startX + textwidth;
                        iAddLine(startX, startY + si.FontSize + 1, maxX, startY + si.FontSize + 1, 1, si.Color, BorderStyleEnum.Solid);
                        break;
                    case TextDecorationEnum.LineThrough:
                        maxX = width > 0 ? Math.Min(x + width, startX + textwidth) : startX + textwidth;
                        iAddLine(startX, startY + (si.FontSize / 2) + 1, maxX, startY + (si.FontSize / 2) + 1, 1, si.Color, BorderStyleEnum.Solid);
                        break;
                    case TextDecorationEnum.Overline:
                        maxX = width > 0 ? Math.Min(x + width, startX + textwidth) : startX + textwidth;
                        iAddLine(startX, startY + 1, maxX, startY + 1, 1, si.Color, BorderStyleEnum.Solid);
                        break;
                    case TextDecorationEnum.None:
                    default:
                        break;
                }
            }

            iAddBorder(si, x, y, height, width);			// add any required border

            return;
        }
示例#28
0
        public List <PageItem> Process(int Flags, byte[] RecordData)
        {
            MemoryStream _ms = null;
            BinaryReader _br = null;

            try
            {
                _ms = new MemoryStream(RecordData);
                _br = new BinaryReader(_ms);

                Byte[] PrivateData = _br.ReadBytes(RecordData.Length);
                //Ok we should have our private data which I am storing my tooltip value in...
                //now lets interpret it...
                string PData = new System.Text.ASCIIEncoding().GetString(PrivateData);
                //If string starts with "ToolTip" then lets do something with it.. otherwise I don't care about it.
                if (PData.StartsWith("ToolTip"))
                {
                    PageRectangle pr = new PageRectangle();
                    StyleInfo     si = new StyleInfo();
                    pr.SI = si;
                    //si.BackgroundColor = Color.Blue;// Just a test to see where the tooltip is being drawn
                    string[] ttd = PData.Split('|');
                    pr.Tooltip = ttd[0].Split(':')[1];
                    pr.X       = X + Single.Parse(ttd[1].Split(':')[1]) * SCALEFACTOR;
                    pr.Y       = Y + Single.Parse(ttd[2].Split(':')[1]) * SCALEFACTOR;
                    pr.W       = Single.Parse(ttd[3].Split(':')[1]) * SCALEFACTOR;
                    pr.H       = Single.Parse(ttd[4].Split(':')[1]) * SCALEFACTOR;
                    items.Add(pr);
                }
                else if (PData.StartsWith("PolyToolTip"))
                {
                    PagePolygon pp = new PagePolygon();
                    StyleInfo   si = new StyleInfo();
                    pp.SI = si;
                    //si.BackgroundColor = Color.Blue;// Just a test to see where the tooltip is being drawn
                    string[] ttd = PData.Split('|');
                    PointF[] pts = new PointF[(ttd.Length - 1) / 2];
                    pp.Points  = pts;
                    pp.Tooltip = ttd[0].Split(':')[1];
                    for (int i = 0; i < pts.Length; i++)
                    {
                        pts[i].X = X + Single.Parse(ttd[i * 2 + 1]) * SCALEFACTOR;
                        pts[i].Y = Y + Single.Parse(ttd[i * 2 + 2]) * SCALEFACTOR;
                    }
                    items.Add(pp);
                }
                return(items);
            }

            finally
            {
                if (_br != null)
                {
                    _br.Close();
                }
                if (_ms != null)
                {
                    _ms.Dispose();
                }
            }
        }
示例#29
0
        private void DrawBackground(Graphics g, System.Drawing.RectangleF rect, StyleInfo si)
        {
            LinearGradientBrush linGrBrush = null;
            SolidBrush sb = null;
            HatchBrush hb = null;
            try
            {
                if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None &&
                    !si.BackgroundGradientEndColor.IsEmpty &&
                    !si.BackgroundColor.IsEmpty)
                {
                    Color c = si.BackgroundColor;
                    Color ec = si.BackgroundGradientEndColor;

                    switch (si.BackgroundGradientType)
                    {
                        case BackgroundGradientTypeEnum.LeftRight:
                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                            break;
                        case BackgroundGradientTypeEnum.TopBottom:
                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                            break;
                        case BackgroundGradientTypeEnum.Center:
                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                            break;
                        case BackgroundGradientTypeEnum.DiagonalLeft:
                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal);
                            break;
                        case BackgroundGradientTypeEnum.DiagonalRight:
                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal);
                            break;
                        case BackgroundGradientTypeEnum.HorizontalCenter:
                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                            break;
                        case BackgroundGradientTypeEnum.VerticalCenter:
                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                            break;
                        default:
                            break;
                    }
                }
                if (si.PatternType != patternTypeEnum.None)
                {
                    switch (si.PatternType)
                    {
                        case patternTypeEnum.BackwardDiagonal:
                            hb = new HatchBrush(HatchStyle.BackwardDiagonal, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.CheckerBoard:
                            hb = new HatchBrush(HatchStyle.LargeCheckerBoard, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.Cross:
                            hb = new HatchBrush(HatchStyle.Cross, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.DarkDownwardDiagonal:
                            hb = new HatchBrush(HatchStyle.DarkDownwardDiagonal, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.DarkHorizontal:
                            hb = new HatchBrush(HatchStyle.DarkHorizontal, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.DiagonalBrick:
                            hb = new HatchBrush(HatchStyle.DiagonalBrick, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.HorizontalBrick:
                            hb = new HatchBrush(HatchStyle.HorizontalBrick, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.LargeConfetti:
                            hb = new HatchBrush(HatchStyle.LargeConfetti, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.OutlinedDiamond:
                            hb = new HatchBrush(HatchStyle.OutlinedDiamond, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.SmallConfetti:
                            hb = new HatchBrush(HatchStyle.SmallConfetti, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.SolidDiamond:
                            hb = new HatchBrush(HatchStyle.SolidDiamond, si.Color, si.BackgroundColor);
                            break;
                        case patternTypeEnum.Vertical:
                            hb = new HatchBrush(HatchStyle.Vertical, si.Color, si.BackgroundColor);
                            break;
                    }
                }

                if (linGrBrush != null)
                {
                    g.FillRectangle(linGrBrush, rect);
                    linGrBrush.Dispose();
                }
                else if (hb != null)
                {
                    g.FillRectangle(hb, rect);
                    hb.Dispose();
                }
                else if (!si.BackgroundColor.IsEmpty)
                {
                    sb = new SolidBrush(si.BackgroundColor);
                    g.FillRectangle(sb, rect);
                    sb.Dispose();
                }
            }
            finally
            {
                if (linGrBrush != null)
                    linGrBrush.Dispose();
                if (sb != null)
                    sb.Dispose();
            }
            return;
        }
示例#30
0
        private string[] MeasureString(PageText pt, System.Drawing.Graphics g)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            System.Drawing.Font         drawFont   = null;
            System.Drawing.StringFormat drawFormat = null;
            System.Drawing.SizeF        ms;

            string[] sa = null;

            try
            {
                // STYLE
                System.Drawing.FontStyle fs = 0;
                if (si.FontStyle == FontStyleEnum.Italic)
                {
                    fs |= System.Drawing.FontStyle.Italic;
                }

                if (si.IsFontBold())
                {
                    fs |= System.Drawing.FontStyle.Bold;
                }

                if (si.TextDecoration == TextDecorationEnum.Underline)
                {
                    fs |= System.Drawing.FontStyle.Underline;
                }

                drawFont = new System.Drawing.Font(StyleInfo.GetFontFamily(si.FontFamilyFull), si.FontSize, fs);

                drawFormat = new System.Drawing.StringFormat();

                if (si.TextAlign == TextAlignEnum.Center)
                {
                    drawFormat.Alignment = System.Drawing.StringAlignment.Center;
                }
                if (si.TextAlign == TextAlignEnum.Right)
                {
                    drawFormat.Alignment = System.Drawing.StringAlignment.Far;
                }
                else
                {
                    drawFormat.Alignment = System.Drawing.StringAlignment.Near;
                }

                ms = MeasureString(pt.Text, g, drawFont, drawFormat);

                float width = pt.W - si.PaddingLeft - si.PaddingRight;

                if (ms.Width <= (width + si.FontSize * 1.5))
                {
                    sa    = new string[1];
                    sa[0] = pt.Text;
                }
                else
                {
                    int x = (int)(ms.Width / width) + 1;

                    List <string> texts = new List <string>();

                    int len   = pt.Text.Length;
                    int start = 0;
                    int setup = len / x;

                    while (true)
                    {
                        ms = MeasureString(pt.Text.Substring(start, setup), g, drawFont, drawFormat);

                        float subW = width - ms.Width;

                        if ((subW >= 0) & (subW <= si.FontSize))
                        {
                            texts.Add(pt.Text.Substring(start, setup));

                            if ((start + setup) == len)
                            {
                                break;
                            }
                            else
                            {
                                start += setup;

                                if ((start + setup) >= len)
                                {
                                    setup = len - start;
                                }
                            }
                        }
                        else if ((subW >= 0) & (subW > si.FontSize))
                        {
                            if ((start + setup) == len)
                            {
                                texts.Add(pt.Text.Substring(start, setup));
                                break;
                            }
                            setup++;
                        }
                        else if (subW < 0)
                        {
                            setup--;
                        }
                    }

                    sa = new string[texts.Count];
                    texts.CopyTo(sa);
                }
            }
            finally
            {
                if (drawFont != null)
                {
                    drawFont.Dispose();
                }
                if (drawFormat != null)
                {
                    drawFont.Dispose();
                }
            }

            return(sa);
        }
示例#31
0
        private void DoEllipse(Pen p, Single Xp, Single Yp, Single Wid, Single Hgt)
        {
            BorderStyleEnum ls = getLineStyle(p);

            Color col = Color.Black;

            if (p.Brush.GetType().Name.Equals("SolidBrush"))
            {
                System.DrawingCore.SolidBrush theBrush = (System.DrawingCore.SolidBrush)p.Brush;
                col = theBrush.Color;
            }

            PageEllipse pl = new PageEllipse();

            pl.X = X + Xp * SCALEFACTOR;
            pl.Y = Y + Yp * SCALEFACTOR;
            pl.W = Wid * SCALEFACTOR;
            pl.H = Hgt * SCALEFACTOR;

            StyleInfo SI = new StyleInfo();

            SI.Color     = col;
            SI.BColorTop = col;
            SI.BStyleTop = ls;
            SI.BWidthTop = p.Width * SCALEFACTOR;
            pl.SI        = SI;
            items.Add(pl);

            //Lines.AppendFormat("\r\n"); //CrLf
            //Lines.AppendFormat("q\t"); //Push graphics state onto stack
            //Lines.AppendFormat("{0} w\t", p.Width * ScaleX); //set width of path
            //Lines.AppendFormat("{0} \t", linestyle); //line style from pen...
            //Lines.AppendFormat("{0} {1} {2} RG\t", Math.Round(R / 255.0, 3), Math.Round(G / 255.0, 3), Math.Round(B / 255.0, 3)); //Set RGB colours
            //Lines.AppendFormat("{0} {1} {2} rg\t", Math.Round(R / 255.0, 3), Math.Round(G / 255.0, 3), Math.Round(B / 255.0, 3)); //Set RGB colours
            ////Need some bezier curves to  draw an ellipse.. we can't draw a circle, but we can get close.
            //Double k = 0.5522847498;
            //Double RadiusX = (Wid / 2.0) * ScaleX;
            //Double RadiusY = (Hgt / 2.0) * ScaleY;
            //Double Y4 = Y + Height - Yp * ScaleY;
            //Double X1 = Xp * ScaleX + X;
            //Double Y1 = Y4 - RadiusY;
            //Double X4 = X1 + RadiusX;

            //Lines.AppendFormat("{0} {1} m\t", X1, Y1);//FirstPoint..

            //Double kRy = k * RadiusY;
            //Double kRx = k * RadiusX;

            ////Control Point 1 will be on the same X as point 1 and be -kRy Y
            //Double X2 = X1;
            //Double Y2 = Y1 + kRy;

            //Double X3 = X4 - kRx;
            //Double Y3 = Y4;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Upper Left Quadrant

            //X1 += 2 * RadiusX;
            //X2 = X1;
            //X3 += 2 * kRx;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Upper Right Quadrant

            //Y2 -= 2 * kRy;
            //Y3 -= 2 * RadiusY;
            //Y4 = Y3;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X2, Y2, X3, Y3, X4, Y4); //Lower Right Quadrant

            //X1 -= 2 * RadiusX;
            //X2 = X1;
            //X3 -= 2 * kRx;

            //Lines.AppendFormat("{0} {1} {2} {3} {4} {5}  c\t", X3, Y3, X2, Y2, X1, Y1); //Lower Right Quadrant

            //Lines.AppendFormat("S\t");//Stroke path
            //Lines.AppendFormat("Q\t");//Pop graphics state from stack
        }
示例#32
0
        public void Textbox(Textbox tb, string t, Row r)
        {
            TableCell tableCell = tb.Parent.Parent as TableCell;

            if (tableCell != null)
            {
                string text = tb.RunText(this._Report, r);

                StyleInfo si = tb.Style.GetStyleInfo(_Report, r);

                iTextSharp.text.Font ft = TextUtility.GetFont(si, text);

                iTextSharp.text.Cell cell = new iTextSharp.text.Cell(new iTextSharp.text.Phrase(text, ft));
                cell.Colspan = tableCell.ColSpan;

                //水不对齐
                if (si.TextAlign == TextAlignEnum.Center)
                {
                    cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                }
                else if (si.TextAlign == TextAlignEnum.Left)
                {
                    cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                }
                else if (si.TextAlign == TextAlignEnum.Right)
                {
                    cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                }

                ////垂直对齐
                if (si.VerticalAlign == VerticalAlignEnum.Middle)
                {
                    cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                }
                else if (si.VerticalAlign == VerticalAlignEnum.Top)
                {
                    cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
                }
                else if (si.VerticalAlign == VerticalAlignEnum.Bottom)
                {
                    cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_BOTTOM;
                }

                //cell.BackgroundColor = new Color(si.BackgroundColor);

                cell.BorderColorLeft   = new Color(si.BColorLeft);
                cell.BorderColorRight  = new Color(si.BColorRight);
                cell.BorderColorTop    = new Color(si.BColorTop);
                cell.BorderColorBottom = new Color(si.BColorBottom);

                int border = iTextSharp.text.Rectangle.NO_BORDER;

                if (si.BStyleLeft != BorderStyleEnum.None)
                {
                    cell.BorderWidthLeft = si.BWidthLeft / 4;
                    border += iTextSharp.text.Rectangle.LEFT_BORDER;
                }
                else
                {
                    cell.BorderWidthLeft = 0;
                }

                if (si.BStyleRight != BorderStyleEnum.None)
                {
                    cell.BorderWidthRight = si.BWidthRight / 4;
                    border += iTextSharp.text.Rectangle.RIGHT_BORDER;
                }
                else
                {
                    cell.BorderWidthRight = 0;
                }

                if (si.BStyleTop != BorderStyleEnum.None)
                {
                    cell.BorderWidthTop = si.BWidthTop / 4;
                    border += iTextSharp.text.Rectangle.TOP_BORDER;
                }
                else
                {
                    cell.BorderWidthTop = 0;
                }

                if (si.BStyleBottom != BorderStyleEnum.None)
                {
                    cell.BorderWidthBottom = si.BWidthBottom / 4;
                    border += iTextSharp.text.Rectangle.BOTTOM_BORDER;
                }
                else
                {
                    cell.BorderWidthBottom = 0;
                }

                cell.Border = border;
                this.textTable.AddCell(cell);
            }
        }
示例#33
0
 //25072008 GJL Draw 4 bezier curves to approximate a circle
 protected internal abstract void AddEllipse(float x, float y, float height, float width, StyleInfo si, string url);
示例#34
0
        private void HandleStyle(string token, StyleInfo model)
        {
            StyleInfo si= model.Clone() as StyleInfo;	// always push a StyleInfo
            _StyleStack.Push(si);						//   since they will always be popped

            Hashtable ht = ParseHtmlCmd(token);
            string style = (string) ht["style"];

            HandleStyleString(style, si);

            return;
        }
示例#35
0
 protected internal void AddLine(float x, float y, float x2, float y2, StyleInfo si)
 {
     AddLine(x, y, x2, y2, si.BWidthTop, si.BColorTop, si.BStyleTop);
 }
示例#36
0
        private void HandleStyleFontSize(StyleInfo si, string size)
        {
            try
            {
                int i = size.IndexOf("pt");

                if (i > 0)
                {
                    size = size.Remove(i, 2);
                    float n = (float) Convert.ToDouble(size);
                    if (size[0] == '+')
                        si.FontSize += n;
                    else
                        si.FontSize = n;
                    return;
                }
                i = size.IndexOf("%");
                if (i > 0)
                {
                    size = size.Remove(i, 1);
                    float n = (float) Convert.ToDouble(size);
                    si.FontSize = n*si.FontSize;
                    return;
                }
                switch (size)
                {
                    case "xx-small":
                        si.FontSize = 6;
                        break;
                    case "x-small":
                        si.FontSize = 8;
                        break;
                    case "small":
                        si.FontSize = 10;
                        break;
                    case "medium":
                        si.FontSize = 12;
                        break;
                    case "large":
                        si.FontSize = 14;
                        break;
                    case "x-large":
                        si.FontSize = 16;
                        break;
                    case "xx-large":
                        si.FontSize = 18;
                        break;
                    case "1":
                        si.FontSize = 8;
                        break;
                    case "2":
                        si.FontSize = 10;
                        break;
                    case "3":
                        si.FontSize = 12;
                        break;
                    case "4":
                        si.FontSize = 14;
                        break;
                    case "5":
                        si.FontSize = 18;
                        break;
                    case "6":
                        si.FontSize = 24;
                        break;
                    case "7":
                        si.FontSize = 36;
                        break;
                }
            }
            catch {}		// lots of user errors will cause an exception; ignore
            return;
        }
示例#37
0
 /// <summary>
 /// Page Rectangle element at the X Y position
 /// </summary>
 /// <returns></returns>
 protected internal abstract void AddRectangle(float x, float y, float height, float width, StyleInfo si, string url,  string tooltip);
示例#38
0
 private void HandleStyleFontWeight(StyleInfo si, string w)
 {
     try
     {
         switch (w)
         {
             case "bold":
                 si.FontWeight = FontWeightEnum.Bold;
                 break;
             case "bolder":
                 if (si.FontWeight > FontWeightEnum.Bolder)
                 {
                     if (si.FontWeight < FontWeightEnum.W900)
                         si.FontWeight++;
                 }
                 else if (si.FontWeight == FontWeightEnum.Normal)
                     si.FontWeight = FontWeightEnum.W700;
                 else if (si.FontWeight == FontWeightEnum.Bold)
                     si.FontWeight = FontWeightEnum.W900;
                 else if (si.FontWeight != FontWeightEnum.Bolder)
                     si.FontWeight = FontWeightEnum.Normal;
                 break;
             case "lighter":
                 if (si.FontWeight > FontWeightEnum.Bolder)
                 {
                     if (si.FontWeight > FontWeightEnum.W100)
                         si.FontWeight--;
                 }
                 else if (si.FontWeight == FontWeightEnum.Normal)
                     si.FontWeight = FontWeightEnum.W300;
                 else if (si.FontWeight == FontWeightEnum.Bold)
                     si.FontWeight = FontWeightEnum.W400;
                 else if (si.FontWeight != FontWeightEnum.Lighter)
                     si.FontWeight = FontWeightEnum.Normal;
                 break;
             case "normal":
                 si.FontWeight = FontWeightEnum.Normal;
                 break;
             case "100":
                 si.FontWeight = FontWeightEnum.W100;
                 break;
             case "200":
                 si.FontWeight = FontWeightEnum.W200;
                 break;
             case "300":
                 si.FontWeight = FontWeightEnum.W300;
                 break;
             case "400":
                 si.FontWeight = FontWeightEnum.W400;
                 break;
             case "500":
                 si.FontWeight = FontWeightEnum.W500;
                 break;
             case "600":
                 si.FontWeight = FontWeightEnum.W600;
                 break;
             case "700":
                 si.FontWeight = FontWeightEnum.W700;
                 break;
             case "800":
                 si.FontWeight = FontWeightEnum.W800;
                 break;
             case "900":
                 si.FontWeight = FontWeightEnum.W900;
                 break;
         }
     }
     catch {}		// lots of user errors will cause an exception; ignore
     return;
 }
示例#39
0
        private void DoInstructions(Font f, StringFormat sf, Brush br, Single recX, Single recY, Single recWidth, Single recHeight, String Text)
        {
            Color Col = Color.Black;

            if (br.GetType().Name.Equals("SolidBrush"))
            {
                SolidBrush sb = (SolidBrush)br;
                Col = sb.Color;
            }

            PageText pt = new PageText(Text);

            pt.X = X + recX * SCALEFACTOR;
            pt.Y = Y + recY * SCALEFACTOR;
            pt.W = recWidth * SCALEFACTOR;
            pt.H = recHeight * SCALEFACTOR;
            StyleInfo SI = new StyleInfo();

            SI.Color      = Col;
            SI.Direction  = DirectionEnum.LTR;
            SI.FontFamily = f.Name;
            SI.FontSize   = f.Size * SCALEFACTOR;
            if (f.Italic)
            {
                SI.FontStyle = FontStyleEnum.Italic;
            }
            if (f.Bold)
            {
                SI.FontWeight = FontWeightEnum.Bold;
            }
            if (f.Underline)
            {
                SI.TextDecoration = TextDecorationEnum.Underline;
            }
            if (sf.LineAlignment == StringAlignment.Center)
            {
                SI.TextAlign = TextAlignEnum.Center;
            }
            else if (sf.LineAlignment == StringAlignment.Far)
            {
                SI.TextAlign = TextAlignEnum.Right;
            }

            if (sf.Alignment == StringAlignment.Center)
            {
                SI.VerticalAlign = VerticalAlignEnum.Middle;
            }
            else if (sf.Alignment == StringAlignment.Far)
            {
                SI.VerticalAlign = VerticalAlignEnum.Bottom;
            }
            if ((sf.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                SI.WritingMode = WritingModeEnum.tb_rl;
            }
            else
            {
                SI.WritingMode = WritingModeEnum.lr_tb;
            }
            pt.SI = SI;
            items.Add(pt);


            //r = Math.Round((r / 255), 3);
            //g = Math.Round((g / 255), 3);
            //b = Math.Round((b / 255), 3);

            //string pdfFont = fonts.GetPdfFont(f.Name);
            ////need a graphics object...
            //Bitmap bm = new Bitmap(1, 1);
            //Graphics gr = Graphics.FromImage(bm);
            //Font scaleFont = new Font(f.Name, (f.Size * ScaleY) * 1.5f, f.Style, f.Unit);
            //SizeF TextSize = gr.MeasureString(Text.Substring(0, Text.Length), scaleFont, (int)(recWidth * ScaleX), sf);
            //float textwidth = TextSize.Width;
            //float textHeight = TextSize.Height;
            //float startX = X + recX * ScaleX;
            //float startY = Y + Height - recY * ScaleY - (scaleFont.Size);
            //if ((sf.FormatFlags & StringFormatFlags.DirectionVertical) != StringFormatFlags.DirectionVertical)
            //{
            //    if (sf.LineAlignment == StringAlignment.Center)
            //    {
            //        startX = (startX + (recWidth * ScaleX) / 2) - (textwidth / 4);
            //    }
            //    else if (sf.LineAlignment == StringAlignment.Far)
            //    {
            //        startX = (startX + recWidth * ScaleX) - (textwidth / 1.8f);
            //    }
            //}
            //else
            //{
            //    startX += textwidth / 4;
            //    if (sf.LineAlignment == StringAlignment.Center)
            //    {
            //        startY = (startY - (recHeight * ScaleY) / 2) + (textHeight / 4);
            //    }
            //    else if (sf.LineAlignment == StringAlignment.Far)
            //    {
            //        startY = (startY - recHeight * ScaleY) + (textHeight / 1.8f);
            //    }
            //}

            //Lines.Append("\r\nq\t");

            //string newtext = PdfUtility.UTF16StringQuoter(Text);
            //if ((sf.FormatFlags & StringFormatFlags.DirectionVertical) != StringFormatFlags.DirectionVertical)
            //{
            //    Lines.AppendFormat(System.Globalization.NumberFormatInfo.InvariantInfo,
            //           "\r\nBT/{0} {1} Tf\t{5} {6} {7} rg\t{2} {3} Td \t({4}) Tj\tET\tQ\t",
            //           pdfFont, scaleFont.SizeInPoints, startX, startY, newtext, r, g, b);
            //}
            //else
            //{
            //    double rads = -283.0 / 180.0;
            //    double radsCos = Math.Cos(rads);
            //    double radsSin = Math.Sin(rads);

            //    Lines.AppendFormat(System.Globalization.NumberFormatInfo.InvariantInfo,
            //                "\r\nBT/{0} {1} Tf\t{5} {6} {7} rg\t{8} {9} {10} {11} {2} {3} Tm \t({4}) Tj\tET\tQ\t",
            //                pdfFont, scaleFont.SizeInPoints, startX, startY, newtext, r, g, b,
            //                radsCos, radsSin, -radsSin, radsCos);
            //}
        }
示例#40
0
        private void HandleStyleString(string style, StyleInfo si)
        {
            if (style == null || style.Length < 1)
                return;

            string[] styleList = style.Split(new char[] {';'});

            foreach (string item in styleList)
            {
                string[] val = item.Split(new char[] {':'});
                if (val.Length != 2)
                    continue;			// must be illegal syntax
                string tval = val[1].Trim();
                switch (val[0].ToLower().Trim())
                {
                    case "background":
                    case "background-color":
                        si.BackgroundColor = XmlUtil.ColorFromHtml(tval, si.Color);
                        break;
                    case "color":
                        si.Color = XmlUtil.ColorFromHtml(tval, si.Color);
                        break;
                    case "font-family":
                        si.FontFamily = tval;
                        break;
                    case "font-size":
                        HandleStyleFontSize(si, tval);
                        break;
                    case "font-style":
                        if (tval == "italic")
                            si.FontStyle = FontStyleEnum.Italic;
                        break;
                    case "font-weight":
                        HandleStyleFontWeight(si, tval);
                        break;
                }
            }

            return;
        }
示例#41
0
        private void HandleStyleFontSize(StyleInfo si, string size)
        {
            try
            {
                int i = size.IndexOf("pt");

                if (i > 0)
                {
                    size = size.Remove(i, 2);
                    float n = (float)Convert.ToDouble(size);
                    if (size[0] == '+')
                    {
                        si.FontSize += n;
                    }
                    else
                    {
                        si.FontSize = n;
                    }
                    return;
                }
                i = size.IndexOf("%");
                if (i > 0)
                {
                    size = size.Remove(i, 1);
                    float n = (float)Convert.ToDouble(size);
                    si.FontSize = n * si.FontSize;
                    return;
                }
                switch (size)
                {
                case "xx-small":
                    si.FontSize = 6;
                    break;

                case "x-small":
                    si.FontSize = 8;
                    break;

                case "small":
                    si.FontSize = 10;
                    break;

                case "medium":
                    si.FontSize = 12;
                    break;

                case "large":
                    si.FontSize = 14;
                    break;

                case "x-large":
                    si.FontSize = 16;
                    break;

                case "xx-large":
                    si.FontSize = 18;
                    break;

                case "1":
                    si.FontSize = 8;
                    break;

                case "2":
                    si.FontSize = 10;
                    break;

                case "3":
                    si.FontSize = 12;
                    break;

                case "4":
                    si.FontSize = 14;
                    break;

                case "5":
                    si.FontSize = 18;
                    break;

                case "6":
                    si.FontSize = 24;
                    break;

                case "7":
                    si.FontSize = 36;
                    break;
                }
            }
            catch {}                            // lots of user errors will cause an exception; ignore
            return;
        }
示例#42
0
        private void iAddFillRect(float x, float y, float width, float height, StyleInfo si, PdfPattern patterns)
        {
            System.Drawing.Color c;
            //Not sure about iTextSharp Pattern => Need check
            if (si.PatternType != patternTypeEnum.None)
            {
                string p = patterns.GetPdfPattern(si.PatternType.ToString());
                c = si.Color;
                double red = Math.Round((c.R / 255.0), 3);
                double green = Math.Round((c.G / 255.0), 3);
                double blue = Math.Round((c.B / 255.0), 3);
                StringBuilder elements = new StringBuilder();
                elements.AppendFormat("\r\nq");
                elements.AppendFormat("\r\n /CS1 cs");
                elements.AppendFormat("\r\n {0} {1} {2} /{3} scn", red, green, blue, p);
                elements.AppendFormat("\r\n {0} {1} {2} RG", red, green, blue);
                elements.AppendFormat("\r\n {0} {1} {2} {3} re\tf", x, _pSize.yHeight - y - height, width, height);
                elements.AppendFormat("\tQ");
                PdfPatternPainter pdfp = cb.CreatePattern(60f, 60f, 60f, 60f);
                pdfp.SetLiteral(elements.ToString());
                cb.SetPatternFill(pdfp);
            }
            // Get the fill color - could be a gradient or pattern etc...
            c = si.BackgroundColor;
            cb.SetRGBColorFill(c.R, c.G, c.B);
            cb.Rectangle(x, _pSize.yHeight - y - height, width, height);
            //cb.ClosePathFillStroke();
            cb.Fill();

        }
示例#43
0
        private void BuildPrivate(Graphics g)
        {
            PageText model = new PageText("");

            model.AllowSelect = false;
            model.Page        = this.Page;
            model.HyperLink   = null;
            model.Tooltip     = null;
            int fontSizeModel = 3;

            if (_items != null)                         // this has already been built
            {
                return;
            }
            _items      = new List <PageItem>();
            _StyleStack = new Stack();

            // The first item is always a text box with the border and background attributes
            PageText pt = new PageText("");

            pt.AllowSelect      = true;           // This item represents HTML item for selection in RdlViewer
            pt.Page             = this.Page;
            pt.HtmlParent       = this;
            pt.X                = this.X;
            pt.Y                = this.Y;
            pt.H                = this.H;
            pt.W                = this.W;
            pt.CanGrow          = false;
            pt.SI               = this.SI.Clone() as StyleInfo;
            pt.SI.PaddingBottom = pt.SI.PaddingLeft = pt.SI.PaddingRight = pt.SI.PaddingTop = 0;
            pt.SI.TextAlign     = TextAlignEnum.Left;
            _items.Add(pt);

            // Now we create multiple items that represent what is in the box
            PageTextHtmlLexer hl     = new PageTextHtmlLexer(this.Text);
            List <string>     tokens = hl.Lex();

            float textWidth = this.W - pt.SI.PaddingLeft - pt.SI.PaddingRight;
            // Now set the default style for the rest of the members
            StyleInfo si = this.SI.Clone() as StyleInfo;

            si.BStyleBottom           = si.BStyleLeft = si.BStyleRight = si.BStyleTop = BorderStyleEnum.None;
            pt.SI.TextAlign           = TextAlignEnum.Left;
            pt.SI.VerticalAlign       = VerticalAlignEnum.Top;
            si.BackgroundColor        = Color.Empty;
            si.BackgroundGradientType = BackgroundGradientTypeEnum.None;
            si.BackgroundImage        = null;

            bool            bFirstInLine  = true;
            StringBuilder   sb            = new StringBuilder(); // this will hold the accumulating line
            float           lineXPos      = 0;
            float           xPos          = 0;
            float           yPos          = 0;
            float           maxLineHeight = 0;
            float           maxDescent    = 0;
            float           descent;                            // working value for descent
            SizeF           ms;
            bool            bWhiteSpace = false;
            List <PageItem> lineItems   = new List <PageItem>();

            foreach (string token in tokens)
            {
                if (token[0] == PageTextHtmlLexer.HTMLCMD)                              // indicates an HTML command
                {
                    // we need to create a PageText since the styleinfo is changing
                    if (sb.Length != 0)
                    {
                        pt             = new PageText(sb.ToString());
                        pt.AllowSelect = false;
                        pt.Page        = this.Page;
                        pt.HtmlParent  = this;
                        pt.HyperLink   = model.HyperLink;
                        pt.Tooltip     = model.Tooltip;
                        pt.NoClip      = true;
                        sb             = new StringBuilder();
                        pt.X           = this.X + lineXPos;
                        pt.Y           = this.Y + yPos;
                        pt.CanGrow     = false;
                        pt.SI          = CurrentStyle(si).Clone() as StyleInfo;
                        _items.Add(pt);
                        lineItems.Add(pt);
                        ms            = this.MeasureString(pt.Text, pt.SI, g, out descent);
                        maxDescent    = Math.Max(maxDescent, descent);
                        pt.W          = ms.Width;
                        pt.H          = ms.Height;
                        pt.Descent    = descent;
                        maxLineHeight = Math.Max(maxLineHeight, ms.Height);
                        lineXPos      = xPos;
                    }
                    // Now reset the styleinfo
                    StyleInfo cs     = CurrentStyle(si);
                    string    ltoken = token.Substring(1, Math.Min(token.Length - 1, 10)).ToLower();
                    if (ltoken == "<b>" || ltoken == "<strong>")
                    {
                        cs.FontWeight = FontWeightEnum.Bold;
                    }
                    else if (ltoken == "</b>" || ltoken == "</strong>")
                    {
                        cs.FontWeight = FontWeightEnum.Normal;
                    }
                    else if (ltoken == "<i>" || ltoken == "<cite>" || ltoken == "<var>" || ltoken == "<em>")
                    {
                        cs.FontStyle = FontStyleEnum.Italic;
                    }
                    else if (ltoken == "</i>" || ltoken == "</cite>" || ltoken == "</var>" || ltoken == "</em>")
                    {
                        cs.FontStyle = FontStyleEnum.Normal;
                    }
                    else if (ltoken == "<code>" || ltoken == "<samp>")
                    {
                        cs.FontFamily = "Courier New";
                    }
                    else if (ltoken == "</code>" || ltoken == "</samp>")
                    {
                        cs.FontFamily = this.SI.FontFamily;
                    }
                    else if (ltoken == "<kbd>")
                    {
                        cs.FontFamily = "Courier New";
                        cs.FontWeight = FontWeightEnum.Bold;
                    }
                    else if (ltoken == "</kdd>")
                    {
                        cs.FontFamily = this.SI.FontFamily;
                        cs.FontWeight = FontWeightEnum.Normal;
                    }
                    else if (ltoken == "<big>")
                    {                           // big makes it bigger by 20% for each time over the baseline of 3
                        fontSizeModel++;
                        float inc = 1;
                        for (int i = 3; i < fontSizeModel; i++)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize * inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken == "</big>")
                    {                           // undoes the effect of big
                        fontSizeModel--;
                        float inc = 1;
                        for (int i = 3; i < fontSizeModel; i++)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize / inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken == "<small>")
                    {                           // small makes it smaller by 20% for each time under the baseline of 3
                        fontSizeModel--;
                        float inc = 1;
                        for (int i = 3; i > fontSizeModel; i--)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize / inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken == "</small>")
                    {                           // undoes the effect of small
                        fontSizeModel++;
                        float inc = 1;
                        for (int i = 3; i > fontSizeModel; i--)
                        {
                            inc += .2f;
                        }
                        float h = this.SI.FontSize * inc;
                        cs.FontSize = h;
                    }
                    else if (ltoken.StartsWith("<br"))
                    {
                        yPos += maxLineHeight;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        maxLineHeight = xPos = lineXPos = maxDescent = 0;
                        bFirstInLine  = true;
                        bWhiteSpace   = false;
                    }
                    else if (ltoken.StartsWith("<hr"))
                    {   // Add a line
                        // Process existing line if any
                        yPos += maxLineHeight;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        maxLineHeight = xPos = lineXPos = maxDescent = 0;
                        bFirstInLine  = true;
                        bWhiteSpace   = false;

                        PageLine pl = new PageLine();
                        pl.AllowSelect = false;
                        pl.Page        = this.Page;
                        const int horzLineHeight = 10;
                        pl.SI            = cs.Clone() as StyleInfo;
                        pl.SI.BStyleLeft = BorderStyleEnum.Ridge;
                        pl.Y             = pl.Y2 = this.Y + yPos + horzLineHeight / 2;
                        pl.X             = this.X;
                        pl.X2            = pl.X + this.W;
                        _items.Add(pl);
                        yPos += horzLineHeight;  // skip past horizontal line
                    }
                    else if (ltoken.StartsWith("<p"))
                    {
                        yPos += maxLineHeight * 2;
                        NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                        maxLineHeight = xPos = lineXPos = maxDescent = 0;
                        bFirstInLine  = true;
                        bWhiteSpace   = false;
                    }
                    else if (ltoken.StartsWith("<a"))
                    {
                        BuildAnchor(token.Substring(1), cs, model);
                    }
                    else if (ltoken.StartsWith("<img"))
                    {
                        PageImage pimg = BuildImage(g, token.Substring(1), cs, model);
                        if (pimg != null)   // We got an image; add to process list
                        {
                            pimg.Y = this.Y + yPos;
                            pimg.X = this.X;
                            _items.Add(pimg);
                            yPos         += pimg.H;     // Increment y position
                            maxLineHeight = xPos = lineXPos = maxDescent = 0;
                            bFirstInLine  = true;
                            bWhiteSpace   = false;
                        }
                    }
                    else if (ltoken == "</a>")
                    {
                        model.HyperLink = model.Tooltip = null;
                        PopStyle();
                    }
                    else if (ltoken.StartsWith("<span"))
                    {
                        HandleStyle(token.Substring(1), si);
                    }
                    else if (ltoken == "</span>")
                    {   // we really should match span and font but it shouldn't matter very often?
                        PopStyle();
                    }
                    else if (ltoken.StartsWith("<font"))
                    {
                        HandleFont(token.Substring(1), si);
                    }
                    else if (ltoken == "</font>")
                    {   // we really should match span and font but it shouldn't matter very often?
                        PopStyle();
                    }
                    continue;
                }
                if (token == PageTextHtmlLexer.WHITESPACE)
                {
                    if (!bFirstInLine)
                    {
                        bWhiteSpace = true;
                    }
                    continue;
                }

                if (token != PageTextHtmlLexer.EOF)
                {
                    string ntoken;
                    if (token == PageTextHtmlLexer.NBSP.ToString())
                    {
                        ntoken = bWhiteSpace ? "  " : " ";
                    }
                    else
                    {
                        ntoken = bWhiteSpace ? " " + token : token;
                    }
                    ntoken = ntoken.Replace(PageTextHtmlLexer.NBSP, ' ');

                    bWhiteSpace = false;                                        // can only use whitespace once
                    ms          = this.MeasureString(ntoken, CurrentStyle(si), g, out descent);
                    if (xPos + ms.Width < textWidth)
                    {
                        bFirstInLine = false;
                        sb.Append(ntoken);

                        maxDescent    = Math.Max(maxDescent, descent);
                        maxLineHeight = Math.Max(maxLineHeight, ms.Height);
                        xPos         += ms.Width;
                        continue;
                    }
                }
                else if (sb.Length == 0)                        // EOF and no previous string means we're done
                {
                    continue;
                }

                pt             = new PageText(sb.ToString());
                pt.AllowSelect = false;
                pt.Page        = this.Page;
                pt.HtmlParent  = this;
                pt.NoClip      = true;
                pt.HyperLink   = model.HyperLink;
                pt.Tooltip     = model.Tooltip;
                sb             = new StringBuilder();
                sb.Append(token.Replace(PageTextHtmlLexer.NBSP, ' '));
                pt.SI      = CurrentStyle(si).Clone() as StyleInfo;
                ms         = this.MeasureString(pt.Text, pt.SI, g, out descent);
                pt.X       = this.X + lineXPos;
                pt.Y       = this.Y + yPos;
                pt.H       = ms.Height;
                pt.W       = ms.Width;
                pt.Descent = descent;
                pt.CanGrow = false;
                _items.Add(pt);
                lineItems.Add(pt);
                maxDescent    = Math.Max(maxDescent, descent);
                maxLineHeight = Math.Max(maxLineHeight, ms.Height);
                yPos         += maxLineHeight;             // Increment y position
                NormalizeLineHeight(lineItems, maxLineHeight, maxDescent);
                lineXPos = maxLineHeight = maxDescent = 0; // start line height over

                // Now set the xPos just after the current token
                ms   = this.MeasureString(token, CurrentStyle(si), g, out descent);
                xPos = ms.Width;
            }

            _TotalHeight = yPos;                        // set the calculated height of the result
            _StyleStack  = null;
            return;
        }
示例#44
0
        /// <summary>
        /// Add image to the page.
        /// </summary>
        /// <returns>string Image name</returns>
        private void iAddImage(PdfImages images, string name, int contentRef, StyleInfo si,
            ImageFormat imf, float x, float y, float width, float height, RectangleF clipRect,
            byte[] im, int samplesW, int samplesH, string url, string tooltip)
        {

            iTextSharp.text.Image pdfImg = iTextSharp.text.Image.GetInstance(im);
            pdfImg.ScaleAbsolute(width, height); //zoom		  
            pdfImg.SetAbsolutePosition(x, _pSize.yHeight - y - height);//Set position
            pdfdocument.Add(pdfImg);
            //add url
            if (url != null)
                pdfdocument.Add(new Annotation(x, _pSize.yHeight - y - _pSize.topMargin, width + x, height, url));
            //add tooltip
            if (!string.IsNullOrEmpty(tooltip))
                pdfdocument.Add(new Annotation(x, _pSize.yHeight - y - _pSize.topMargin, width + x, height, tooltip));
            iAddBorder(si, x - si.PaddingLeft, y - si.PaddingTop,
                height + si.PaddingTop + si.PaddingBottom,
                width + si.PaddingLeft + si.PaddingRight);			// add any required border
        }
示例#45
0
        private SizeF MeasureString(string s, StyleInfo si, Graphics g, out float descent)
        {
            Font drawFont=null;
            StringFormat drawFormat=null;
            SizeF ms = SizeF.Empty;
            descent = 0;
            if (s == null || s.Length == 0)
                return ms;
            try
            {
                // STYLE
                System.Drawing.FontStyle fs = 0;
                if (si.FontStyle == FontStyleEnum.Italic)
                    fs |= System.Drawing.FontStyle.Italic;

                // WEIGHT
                switch (si.FontWeight)
                {
                    case FontWeightEnum.Bold:
                    case FontWeightEnum.Bolder:
                    case FontWeightEnum.W500:
                    case FontWeightEnum.W600:
                    case FontWeightEnum.W700:
                    case FontWeightEnum.W800:
                    case FontWeightEnum.W900:
                        fs |= System.Drawing.FontStyle.Bold;
                        break;
                    default:
                        break;
                }
                try
                {
                    FontFamily ff = si.GetFontFamily();
                    drawFont = new Font(ff, si.FontSize, fs);
                    // following algorithm comes from the C# Font Metrics documentation
                    float descentPixel = si.FontSize * ff.GetCellDescent(fs) / ff.GetEmHeight(fs);
                    descent = RSize.PointsFromPixels(g, descentPixel);
                }
                catch
                {
                    drawFont = new Font("Arial", si.FontSize, fs);	// usually because font not found
                    descent = 0;
                }
                drawFormat = new StringFormat();
                drawFormat.Alignment = StringAlignment.Near;

                CharacterRange[] cr = {new CharacterRange(0, s.Length)};
                drawFormat.SetMeasurableCharacterRanges(cr);
                Region[] rs = new Region[1];
                rs = g.MeasureCharacterRanges(s, drawFont, new RectangleF(0,0,float.MaxValue,float.MaxValue),
                    drawFormat);
                RectangleF mr = rs[0].GetBounds(g);

                ms.Height = RSize.PointsFromPixels(g, mr.Height);	// convert to points from pixels
                ms.Width = RSize.PointsFromPixels(g, mr.Width);		// convert to points from pixels
                return ms;
            }
            finally
            {
                if (drawFont != null)
                    drawFont.Dispose();
                if (drawFormat != null)
                    drawFont.Dispose();
            }
        }
示例#46
0
 //25072008 GJL Draw 4 bezier curves to approximate a circle
 internal abstract protected void AddEllipse(float x, float y, float height, float width, StyleInfo si, string url);
示例#47
0
        /// <summary>
        /// Add border
        /// </summary>
        private void iAddBorder(StyleInfo si, float x, float y, float height, float width)
        {
            // Handle any border required   TODO: optimize border by drawing a rect when possible
            if (height <= 0 || width <= 0)		// no bounding box to use
                return;

            float ybottom = (y + height);
            float xright = x + width;
            if (si.BStyleTop != BorderStyleEnum.None && si.BWidthTop > 0)
                iAddLine(x, y, xright, y, si.BWidthTop, si.BColorTop, si.BStyleTop);

            if (si.BStyleRight != BorderStyleEnum.None && si.BWidthRight > 0)
                iAddLine(xright, y, xright, ybottom, si.BWidthRight, si.BColorRight, si.BStyleRight);

            if (si.BStyleLeft != BorderStyleEnum.None && si.BWidthLeft > 0)
                iAddLine(x, y, x, ybottom, si.BWidthLeft, si.BColorLeft, si.BStyleLeft);

            if (si.BStyleBottom != BorderStyleEnum.None && si.BWidthBottom > 0)
                iAddLine(x, ybottom, xright, ybottom, si.BWidthBottom, si.BColorBottom, si.BStyleBottom);

            return;
        }
示例#48
0
        private void DoInstructions(PointF[] points, Pen p, UInt32 Offset, UInt32 NumberOfPoints, float Tension)
        {
            BorderStyleEnum ls = getLineStyle(p);
            //Well we only draw lines at the moment.... 

            switch (p.Brush.GetType().Name)
            {
                case "SolidBrush":
                    System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)p.Brush;
                    PageCurve pc = new PageCurve();
                    for (int i = 0; i < points.Length; i++)
                    {
                        points[i].X = X + points[i].X * SCALEFACTOR;
                        points[i].Y = Y + points[i].Y * SCALEFACTOR;
                    }
                    pc.Points = points;
                    pc.Offset = (int) Offset;
                    pc.Tension = Tension;
                    

                    StyleInfo SI = new StyleInfo();
                    SI.Color = theBrush.Color;
                    SI.BColorTop = theBrush.Color;
                    SI.BStyleTop = ls;
                    SI.BWidthTop = p.Width * SCALEFACTOR;
                    SI.BColorBottom = theBrush.Color;
                    SI.BStyleBottom = ls;
                    SI.BWidthBottom = p.Width * SCALEFACTOR;
                    SI.BColorLeft = theBrush.Color;
                    SI.BStyleLeft = ls;
                    SI.BWidthLeft = p.Width * SCALEFACTOR;
                    SI.BColorRight = theBrush.Color;
                    SI.BStyleRight = ls;
                    SI.BWidthRight = p.Width * SCALEFACTOR;
                    pc.SI = SI;
                    items.Add(pc);
                    break;
                default:
                    break;
            }
        }
示例#49
0
        /// <summary>
        /// Page Polygon
        /// </summary>
        /// <param name="pts"></param>
        /// <param name="si"></param>
        /// <param name="url"></param>
        /// <param name="patterns"></param>
        internal void iAddPolygon(PointF[] pts, StyleInfo si, string url, PdfPattern patterns)
        {
            if (si.BackgroundColor.IsEmpty)
                return;		 // nothing to do

            // Get the fill color - could be a gradient or pattern etc...
            System.Drawing.Color c = si.BackgroundColor;
            iAddPoints(pts);
            cb.SetRGBColorFill(c.R, c.G, c.B);
            cb.ClosePathFillStroke();

            //Not sure about iTextSharp Pattern => Need check
            if (si.PatternType != patternTypeEnum.None)
            {
                string p = patterns.GetPdfPattern(si.PatternType.ToString());
                StringBuilder elements = new StringBuilder();
                c = si.Color;
                double red = Math.Round((c.R / 255.0), 3);
                double green = Math.Round((c.G / 255.0), 3);
                double blue = Math.Round((c.B / 255.0), 3);
                elements.AppendFormat("\r\nq");
                elements.AppendFormat("\r\n /CS1 cs");
                elements.AppendFormat("\r\n {0} {1} {2} /{3} scn", red, green, blue, p);
                elements.AppendFormat("\r\n {0} {1} {2} RG", red, green, blue);
                elements.AppendFormat("\tQ");
                PdfPatternPainter pdfp = cb.CreatePattern(60f, 60f, 60f, 60f);
                pdfp.SetLiteral(elements.ToString());
                cb.SetPatternFill(pdfp);
                iAddPoints(pts);
                cb.ClosePathFillStroke();
            }
        }
        private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Pen p,Single StartAngle,Single SweepAngle)
        {
         
            BorderStyleEnum ls = getLineStyle(p);
            switch (p.Brush.GetType().Name)
            {
                case "SolidBrush":
                    System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)p.Brush;
                    PagePie pl = new PagePie();
                    pl.StartAngle = StartAngle;
                    pl.SweepAngle = SweepAngle;
                    pl.X = X + recX * SCALEFACTOR;
                    pl.Y = Y + recY * SCALEFACTOR;
                    pl.W = recWidth * SCALEFACTOR;
                    pl.H = recHeight * SCALEFACTOR;

                    StyleInfo SI = new StyleInfo();
                    SI.Color = theBrush.Color;
                    SI.BColorTop = SI.BColorBottom = SI.BColorLeft = SI.BColorRight = theBrush.Color;
                    SI.BStyleTop = SI.BStyleBottom = SI.BStyleLeft = SI.BStyleRight = ls;
                    SI.BWidthTop = SI.BWidthBottom = SI.BWidthLeft = SI.BWidthRight = p.Width * SCALEFACTOR;
                    pl.SI = SI;
                    items.Add(pl);
                    break;
                default:
                    break;
            }
        }
示例#51
0
        private void iDoCurve(PointF[] points, PointF[] tangents, StyleInfo si)
        {
            int i;

            for (i = 0; i < points.Length - 1; i++)
            {
                int j = i + 1;

                float x0 = points[i].X;
                float y0 = points[i].Y;

                float x1 = points[i].X + tangents[i].X;
                float y1 = points[i].Y + tangents[i].Y;

                float x2 = points[j].X - tangents[j].X;
                float y2 = points[j].Y - tangents[j].Y;

                float x3 = points[j].X;
                float y3 = points[j].Y;
                iAddCurve(x0, y0, x1, y1, x2, y2, x3, y3, si, null);
            }
        }
示例#52
0
        private string[] MeasureString(PageText pt, Graphics g, out float[] width)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            Font         drawFont   = null;
            StringFormat drawFormat = null;
            SizeF        ms;

            string[] sa = null;
            width = null;
            try
            {
                // STYLE
                System.Drawing.FontStyle fs = 0;
                if (si.FontStyle == FontStyleEnum.Italic)
                {
                    fs |= System.Drawing.FontStyle.Italic;
                }

                // WEIGHT
                switch (si.FontWeight)
                {
                case FontWeightEnum.Bold:
                case FontWeightEnum.Bolder:
                case FontWeightEnum.W500:
                case FontWeightEnum.W600:
                case FontWeightEnum.W700:
                case FontWeightEnum.W800:
                case FontWeightEnum.W900:
                    fs |= System.Drawing.FontStyle.Bold;
                    break;

                default:
                    break;
                }

                drawFont             = new Font(StyleInfo.GetFontFamily(si.FontFamilyFull), si.FontSize, fs);
                drawFormat           = new StringFormat();
                drawFormat.Alignment = StringAlignment.Near;

                // Measure string
                //  pt.NoClip indicates that this was generated by PageTextHtml Build.  It has already word wrapped.
                if (pt.NoClip || pt.SI.WritingMode == WritingModeEnum.tb_rl)                    // TODO: support multiple lines for vertical text
                {
                    ms       = MeasureString(s, g, drawFont, drawFormat);
                    width    = new float[1];
                    width[0] = RSize.PointsFromPixels(g, ms.Width);                     // convert to points from pixels
                    sa       = new string[1];
                    sa[0]    = s;
                    return(sa);
                }

                // handle multiple lines;
                //  1) split the string into the forced line breaks (ie "\n and \r")
                //  2) foreach of the forced line breaks; break these into words and recombine
                s = s.Replace("\r\n", "\n");                    // don't want this to result in double lines
                string[]      flines     = s.Split(lineBreak);
                List <string> lines      = new List <string>();
                List <float>  lineWidths = new List <float>();
                // remove the size reserved for left and right padding
                float ptWidth = pt.W - pt.SI.PaddingLeft - pt.SI.PaddingRight;
                if (ptWidth <= 0)
                {
                    ptWidth = 1;
                }
                foreach (string tfl in flines)
                {
                    string fl;
                    if (tfl.Length > 0 && tfl[tfl.Length - 1] == ' ')
                    {
                        fl = tfl.TrimEnd(' ');
                    }
                    else
                    {
                        fl = tfl;
                    }

                    // Check if entire string fits into a line
                    ms = MeasureString(fl, g, drawFont, drawFormat);
                    float tw = RSize.PointsFromPixels(g, ms.Width);
                    if (tw <= ptWidth)
                    {                       // line fits don't need to break it down further
                        lines.Add(fl);
                        lineWidths.Add(tw);
                        continue;
                    }

                    // Line too long; need to break into multiple lines
                    // 1) break line into parts; then build up again keeping track of word positions
                    string[]         parts = fl.Split(wordBreak);               // this is the maximum split of lines
                    StringBuilder    sb    = new StringBuilder(fl.Length);
                    CharacterRange[] cra   = new CharacterRange[parts.Length];
                    for (int i = 0; i < parts.Length; i++)
                    {
                        int sc = sb.Length;        // starting character
                        sb.Append(parts[i]);       // endding character
                        if (i != parts.Length - 1) // last item doesn't need blank
                        {
                            sb.Append(" ");
                        }
                        int            ec = sb.Length;
                        CharacterRange cr = new CharacterRange(sc, ec - sc);
                        cra[i] = cr;            // add to character array
                    }

                    // 2) Measure the word locations within the line
                    string            wfl           = sb.ToString();
                    WordStartFinish[] wordLocations = MeasureString(wfl, g, drawFont, drawFormat, cra);
                    if (wordLocations == null)
                    {
                        continue;
                    }

                    // 3) Loop thru creating new lines as needed
                    int            startLoc = 0;
                    CharacterRange crs      = cra[startLoc];
                    CharacterRange cre      = cra[startLoc];
                    float          cwidth   = wordLocations[0].end;   // length of the first
                    float          bwidth   = wordLocations[0].start; // characters need a little extra on start
                    string         ts;
                    bool           bLine = true;
                    for (int i = 1; i < cra.Length; i++)
                    {
                        cwidth = wordLocations[i].end - wordLocations[startLoc].start + bwidth;
                        if (cwidth > ptWidth)
                        {                               // time for a new line
                            cre = cra[i - 1];
                            ts  = wfl.Substring(crs.First, cre.First + cre.Length - crs.First);
                            lines.Add(ts);
                            lineWidths.Add(wordLocations[i - 1].end - wordLocations[startLoc].start + bwidth);

                            // Find the first non-blank character of the next line
                            while (i < cra.Length &&
                                   cra[i].Length == 1 &&
                                   fl[cra[i].First] == ' ')
                            {
                                i++;
                            }
                            if (i < cra.Length) // any lines left?
                            {                   // yes, continue on
                                startLoc = i;
                                crs      = cre = cra[startLoc];
                                cwidth   = wordLocations[i].end - wordLocations[startLoc].start + bwidth;
                            }
                            else  // no, we can stop
                            {
                                bLine = false;
                            }
                            //  bwidth = wordLocations[startLoc].start - wordLocations[startLoc - 1].end;
                        }
                        else
                        {
                            cre = cra[i];
                        }
                    }
                    if (bLine)
                    {
                        ts = fl.Substring(crs.First, cre.First + cre.Length - crs.First);
                        lines.Add(ts);
                        lineWidths.Add(cwidth);
                    }
                }
                // create the final array from the Lists
                string[] la = lines.ToArray();
                width = lineWidths.ToArray();
                return(la);
            }
            finally
            {
                if (drawFont != null)
                {
                    drawFont.Dispose();
                }
                if (drawFormat != null)
                {
                    drawFont.Dispose();
                }
            }
        }
示例#53
0
 //25072008 GJL Draw 4 bezier curves to approximate a circle
 private void iAddEllipse(float x, float y, float height, float width, StyleInfo si, string url)
 {
     if (si.BStyleTop != BorderStyleEnum.None)
     {
         switch (si.BStyleTop)
         {
             case BorderStyleEnum.Dashed:
                 cb.SetLineDash(new float[] { '3', '2' }, 0);
                 break;
             case BorderStyleEnum.Dotted:
                 cb.SetLineDash(new float[] { '2' }, 0);
                 break;
             case BorderStyleEnum.Solid:
             default:
                 cb.SetLineDash(new float[] { }, 0);
                 break;
         }
         cb.SetRGBColorStroke(si.BColorTop.R, si.BColorTop.G, si.BColorTop.B);
     }
     float RadiusX = (width / 2.0f);
     float RadiusY = (height / 2.0f);
     cb.Ellipse(x, _pSize.yHeight - y, x + RadiusX, y + RadiusY);
     if (!si.BackgroundColor.IsEmpty)
     {
         cb.SetRGBColorStrokeF(si.BackgroundColor.R, si.BackgroundColor.G, si.BackgroundColor.B);
     }
     if (si.BackgroundColor.IsEmpty)
         cb.ClosePathStroke();
     else
         cb.ClosePathFillStroke();
 }
        protected internal override void AddPie(float x, float y, float height, float width, StyleInfo si, string url, string tooltip)
        {
            // Draw background rectangle if needed
            if (!si.BackgroundColor.IsEmpty && height > 0 && width > 0)
            {   // background color, height and width are specified
                iAddFillRect(x, y, width, height, si);
            }
            iAddBorder(si, x, y, height, width);                        // add any required border

            //add url
            if (url != null)
            {
                _pdfDocument.Add(new Annotation(x, PageSize.yHeight - y, width + x, height, url));
            }
            //add tooltip
            if (!string.IsNullOrEmpty(tooltip))
            {
                _pdfDocument.Add(new Annotation(x, PageSize.yHeight - y, width + x, height, tooltip));
            }
            return;
        }
示例#55
0
 /// <summary>
 /// Page line element at the X Y to X2 Y2 position
 /// </summary>
 /// <returns></returns>
 private void iAddLine(float x, float y, float x2, float y2, StyleInfo si)
 {
     iAddLine(x, y, x2, y2, si.BWidthTop, si.BColorTop, si.BStyleTop);
 }
        protected internal override void AddEllipse(float x, float y, float height, float width, StyleInfo si, string url)
        {
            if (si.BStyleTop != BorderStyleEnum.None)
            {
                switch (si.BStyleTop)
                {
                case BorderStyleEnum.Dashed:
                    _contentByte.SetLineDash(new float[] { '3', '2' }, 0);
                    break;

                case BorderStyleEnum.Dotted:
                    _contentByte.SetLineDash(new float[] { '2' }, 0);
                    break;

                case BorderStyleEnum.Solid:
                default:
                    _contentByte.SetLineDash(new float[] { }, 0);
                    break;
                }
                _contentByte.SetRgbColorStroke(si.BColorTop.R, si.BColorTop.G, si.BColorTop.B);
            }
            float RadiusX = (width / 2.0f);
            float RadiusY = (height / 2.0f);

            _contentByte.Ellipse(x, PageSize.yHeight - y, x + RadiusX, y + RadiusY);
            if (!si.BackgroundColor.IsEmpty)
            {
                _contentByte.SetRgbColorStrokeF(si.BackgroundColor.R, si.BackgroundColor.G, si.BackgroundColor.B);
            }
            if (si.BackgroundColor.IsEmpty)
            {
                _contentByte.ClosePathStroke();
            }
            else
            {
                _contentByte.ClosePathFillStroke();
            }
        }
示例#57
0
        private void DrawBackground(Xwt.Drawing.Context g, Xwt.Rectangle rect, StyleInfo si)
        {
            //            LinearGradientBrush linGrBrush = null;
            //            SolidBrush sb = null;
            if (si.BackgroundColor.IsEmpty)
                return;

            g.Save();

            Xwt.Drawing.Color c = XwtColor.SystemColorToXwtColor(si.BackgroundColor);

            Xwt.Drawing.Gradient gradient = null;

            if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None &&
                !si.BackgroundGradientEndColor.IsEmpty)
            {
                Xwt.Drawing.Color ec = XwtColor.SystemColorToXwtColor(si.BackgroundGradientEndColor);

                switch (si.BackgroundGradientType)
                {
                    case BackgroundGradientTypeEnum.LeftRight:
                        //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                        gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y);
                        break;
                    case BackgroundGradientTypeEnum.TopBottom:
                        //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                        gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X, rect.Y + rect.Height);
                        break;
                    case BackgroundGradientTypeEnum.Center:
                        //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                        throw new NotSupportedException();
                    //                            break;
                    case BackgroundGradientTypeEnum.DiagonalLeft:
                        //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal);
                        gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
                        break;
                    case BackgroundGradientTypeEnum.DiagonalRight:
                        //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal);
                        gradient = new Xwt.Drawing.LinearGradient(rect.X + rect.Width, rect.Y + rect.Height, rect.X, rect.Y);
                        break;
                    case BackgroundGradientTypeEnum.HorizontalCenter:
                        //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                        throw new NotSupportedException();
                    //							break;
                    case BackgroundGradientTypeEnum.VerticalCenter:
                        //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                        throw new NotSupportedException();
                    //							break;
                    default:
                        break;
                }

                gradient.AddColorStop(0, c);
                gradient.AddColorStop(1, ec);
            }

            if (gradient != null)
            {
                // TODO: Fix
                //g.FillRectangle(rect, gradient);
            }
            else if (!si.BackgroundColor.IsEmpty)
            {
                // TODO: Fix
                //g.FillRectangle(rect, c);

            }
            g.Restore();
        }
        protected internal override void AddText(float x, float y, float height, float width, string[] sa, StyleInfo si, float[] tw, bool bWrap, string url, bool bNoClip, string tooltip)
        {
            BaseFont bf;
            string   face      = iFontNameNormalize(si.FontFamily);
            string   fontname  = "";
            bool     fonttype1 = true;
            var      folder    = FontFolder; //Call to determine folder and set value of _dejavuFonts;

            if (face == "Times-Roman")
            {
                if (si.IsFontBold() && si.FontStyle == FontStyleEnum.Italic)
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "TimesNewRomanPS-BoldItalicMT";
                        fontname = "Times New Roman Bold Italic.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Serif Condensed Bold Italic" : "Times-BoldItalic";
                        fontname = (_dejavuFonts ? "DejaVuSerifCondensed-BoldItalic.ttf" : "timesbi.ttf");
                    }
                }
                else if (si.IsFontBold())
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "TimesNewRomanPS-BoldMT";
                        fontname = "Times New Roman Bold.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Serif Condensed Bold" : "Times-Bold";
                        fontname = (_dejavuFonts ? "DejaVuSerifCondensed-Bold.ttf" : "timesbd.ttf");
                    }
                }
                else if (si.FontStyle == FontStyleEnum.Italic)
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "TimesNewRomanPS-ItalicMT";
                        fontname = "Times New Roman Italic.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Serif Condensed Italic" : "Times-Italic";
                        fontname = (_dejavuFonts ? "DejaVuSerifCondensed-Italic.ttf" : "timesi.ttf");
                    }
                }
                else
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "TimesNewRomanPSMT";
                        fontname = "Times New Roman.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Serif Condensed" : face;
                        fontname = (_dejavuFonts ? "DejaVuSerifCondensed.ttf" : "times.ttf");
                    }
                }
                fonttype1 = false;
            }
            else if (face == "Arial")
            {
                if (IsAsian(sa))
                {
                    face     = "Arial Unicode MS";
                    fontname = "arialuni.ttf";
                }
                else if (si.IsFontBold() && si.FontStyle == FontStyleEnum.Italic)
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "Arial BoldItalicMT";
                        fontname = "Arial Bold Italic.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Condensed Bold Oblique" : "Arial-BoldItalic";
                        fontname = (_dejavuFonts ? "DejaVuSansCondensed-BoldOblique.ttf" : "arialbi.ttf");
                    }
                }
                else if (si.IsFontBold())
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "Arial-BoldMT";
                        fontname = "Arial Bold.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Condensed Bold" : "Arial-Bold";
                        fontname = (_dejavuFonts ? "DejaVuSansCondensed-Bold.ttf" : "arialbd.ttf");
                    }
                }
                else if (si.FontStyle == FontStyleEnum.Italic)
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "Arial-ItalicMT";
                        fontname = "Arial Italic.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Condensed Oblique" : "Arial-Italic";
                        fontname = (_dejavuFonts ? "DejaVuSansCondensed-Oblique.ttf" : "ariali.ttf");
                    }
                }
                else
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "ArialMT";
                        fontname = "Arial.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Condensed" : face;
                        fontname = (_dejavuFonts ? "DejaVuSansCondensed.ttf" : "arial.ttf");
                    }
                }
                fonttype1 = false;
            }
            else if (face == "Courier New")
            {
                if (si.IsFontBold() && si.FontStyle == FontStyleEnum.Italic)
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "CourierNewPS-BoldItalicMT";
                        fontname = "Courier New Bold Italic.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Mono Bold Oblique" : "Courier New-BoldItalic";
                        fontname = (_dejavuFonts ? "DejaVuSansMono-BoldOblique.ttf" : "courbi.ttf");
                    }
                }
                else if (si.IsFontBold())
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "CourierNewPS-BoldMT";
                        fontname = "Courier New Bold.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Mono Bold" : "Courier New-Bold";
                        fontname = (_dejavuFonts ? "DejaVuSansMono-Oblique.ttf" : "courbd.ttf");
                    }
                }
                else if (si.FontStyle == FontStyleEnum.Italic)
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "CourierNewPS-ItalicMT";
                        fontname = "Courier New Italic.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Mono Oblique" : "Courier New-Italic";
                        fontname = (_dejavuFonts ? "DejaVuSansMono-Oblique.ttf" : "couri.ttf");
                    }
                }
                else
                {
                    //OSX
                    if (IsOSX)
                    {
                        face     = "CourierNewPSMT";
                        fontname = "Courier New.ttf";
                    }
                    else
                    {
                        face     = _dejavuFonts ? "DejaVu Sans Mono" : face;
                        fontname = (_dejavuFonts ? "DejaVuSansMono.ttf" : "cour.ttf");
                    }
                }
                fonttype1 = false;
            }
            else
            {
                if (si.IsFontBold() &&
                    si.FontStyle == FontStyleEnum.Italic) // bold and italic?
                {
                    face = face + "-BoldOblique";
                }
                else if (si.IsFontBold())           // just bold?
                {
                    face = face + "-Bold";
                }
                else if (si.FontStyle == FontStyleEnum.Italic)
                {
                    face = face + "-Oblique";
                }
                fonttype1 = true;
            }
            //Get index of fontname in List font name
            int indexbf = _baseFontsName.FindIndex(delegate(string _fontname) { return(_fontname == face); });

            //If not found then add new BaseFont
            if (indexbf == -1)
            {
                _baseFontsName.Add(face);
                if (fonttype1)
                {
                    bf = BaseFont.CreateFont(face, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                }
                else
                {
                    string path = System.IO.Path.Combine(folder, fontname);
                    bf = BaseFont.CreateFont(path, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                }
                _baseFonts.Add(bf);
            }
            else
            //Get from List
            {
                bf = _baseFonts[indexbf];
            }

            // Loop thru the lines of text
            for (int i = 0; i < sa.Length; i++)
            {
                string text      = sa[i];
                float  textwidth = tw[i];
                // Calculate the x positino
                float startX = x + si.PaddingLeft;                      // TODO: handle tb_rl
                float startY = y + si.PaddingTop + (i * si.FontSize);   // TODO: handle tb_rl
                int   align  = 0;
                if (si.WritingMode == WritingModeEnum.lr_tb)
                {       // TODO: not sure what alignment means with tb_lr so I'll leave it out for now
                    switch (si.TextAlign)
                    {
                    case TextAlignEnum.Center:
                        if (width > 0)
                        {
                            startX = x + si.PaddingLeft + (width - si.PaddingLeft - si.PaddingRight) / 2 - textwidth / 2;
                            align  = Element.ALIGN_CENTER;
                        }
                        break;

                    case TextAlignEnum.Right:
                        if (width > 0)
                        {
                            startX = x + width - textwidth - si.PaddingRight;
                            align  = Element.ALIGN_RIGHT;
                        }
                        break;

                    case TextAlignEnum.Left:
                    default:
                        align = Element.ALIGN_LEFT;
                        break;
                    }

                    // Calculate the y position
                    switch (si.VerticalAlign)
                    {
                    case VerticalAlignEnum.Middle:
                        if (height <= 0)
                        {
                            break;
                        }

                        // calculate the middle of the region
                        startY = y + si.PaddingTop + (height - si.PaddingTop - si.PaddingBottom) / 2 - si.FontSize / 2;
                        // now go up or down depending on which line
                        if (sa.Length == 1)
                        {
                            break;
                        }
                        if (sa.Length % 2 == 0)         // even number
                        {
                            startY = startY - ((sa.Length / 2 - i) * si.FontSize) + si.FontSize / 2;
                        }
                        else
                        {
                            startY = startY - ((sa.Length / 2 - i) * si.FontSize);
                        }
                        break;

                    case VerticalAlignEnum.Bottom:
                        if (height <= 0)
                        {
                            break;
                        }

                        startY = y + height - si.PaddingBottom - (si.FontSize * (sa.Length - i));
                        break;

                    case VerticalAlignEnum.Top:
                    default:
                        break;
                    }
                }
                else
                {
                    //25072008 GJL - Move x in a little - it draws to close to the edge of the rectangle (25% of the font size seems to work!) and Center or right align vertical text
                    startX += si.FontSize / 4;

                    switch (si.TextAlign)
                    {
                    case TextAlignEnum.Center:
                        if (height > 0)
                        {
                            startY = y + si.PaddingLeft + (height - si.PaddingLeft - si.PaddingRight) / 2 - textwidth / 2;
                        }
                        break;

                    case TextAlignEnum.Right:
                        if (width > 0)
                        {
                            startY = y + height - textwidth - si.PaddingRight;
                        }
                        break;

                    case TextAlignEnum.Left:
                    default:
                        break;
                    }
                }

                // Draw background rectangle if needed (only put out on the first line, since we do whole rectangle)
                if (!si.BackgroundColor.IsEmpty && height > 0 && width > 0 && i == 0)
                {       // background color, height and width are specified
                    iAddFillRect(x, y, width, height, si.BackgroundColor);
                }

                // Set the clipping path, (Itext have no clip)
                if (height > 0 && width > 0)
                {
                    _contentByte.SetRgbColorFill(si.Color.R, si.Color.G, si.Color.B);

                    if (si.WritingMode == WritingModeEnum.lr_tb)
                    {
                        //If textline after measure with word break can fit just simple show Text
                        if (width >= textwidth)
                        {
                            _contentByte.BeginText();
                            _contentByte.SetFontAndSize(bf, si.FontSize);
                            _contentByte.SetTextMatrix(startX, (PageSize.yHeight - startY - si.FontSize));
                            _contentByte.ShowText(text);
                            _contentByte.EndText();
                        }
                        else
                        {
                            //else use Column text to wrap or clip (wrap: for example a text like an URL so word break is not working here, itextsharp ColumnText do the work for us)
                            ColumnText ct       = new ColumnText(_contentByte);
                            Phrase     myPhrase = new Phrase(text, new iTextSharp.text.Font(bf, si.FontSize));
                            ct.SetSimpleColumn(myPhrase, x + si.PaddingLeft, PageSize.yHeight - startY, x + width - si.PaddingRight, PageSize.yHeight - y - si.PaddingBottom - height, 10f, align);
                            ct.Go();
                        }
                    }
                    else
                    {
                        //Not checked
                        double rads    = -283.0 / 180.0;
                        double radsCos = Math.Cos(rads);
                        double radsSin = Math.Sin(rads);
                        _contentByte.BeginText();
                        _contentByte.SetFontAndSize(bf, si.FontSize);
                        _contentByte.SetTextMatrix((float)radsCos, (float)radsSin, (float)-radsSin, (float)radsCos, startX, PageSize.yHeight - startY);
                        _contentByte.ShowText(text);
                        _contentByte.EndText();
                    }

                    //add URL
                    if (url != null)
                    {
                        _pdfDocument.Add(new Annotation(x, PageSize.yHeight - (y + height), width + x, PageSize.yHeight - y, url));
                    }
                    //add tooltip
                    if (tooltip != null)
                    {
                        _pdfDocument.Add(new Annotation(x, PageSize.yHeight - (y + height), width + x, PageSize.yHeight - y, tooltip));
                    }
                }

                // Handle underlining etc.
                float maxX;
                switch (si.TextDecoration)
                {
                case TextDecorationEnum.Underline:
                    maxX = width > 0 ? Math.Min(x + width, startX + textwidth) : startX + textwidth;
                    AddLine(startX, startY + si.FontSize + 1, maxX, startY + si.FontSize + 1, 1, si.Color, BorderStyleEnum.Solid);
                    break;

                case TextDecorationEnum.LineThrough:
                    maxX = width > 0 ? Math.Min(x + width, startX + textwidth) : startX + textwidth;
                    AddLine(startX, startY + (si.FontSize / 2) + 1, maxX, startY + (si.FontSize / 2) + 1, 1, si.Color, BorderStyleEnum.Solid);
                    break;

                case TextDecorationEnum.Overline:
                    maxX = width > 0 ? Math.Min(x + width, startX + textwidth) : startX + textwidth;
                    AddLine(startX, startY + 1, maxX, startY + 1, 1, si.Color, BorderStyleEnum.Solid);
                    break;

                case TextDecorationEnum.None:
                default:
                    break;
                }
            }

            iAddBorder(si, x, y, height, width);                        // add any required border

            return;
        }
示例#59
0
        private void DrawImageBackground(PageImage pi, StyleInfo si, Graphics g, RectangleF r)
        {
            Stream strm = null;
            System.Drawing.Image im = null;
            try
            {
                strm = new MemoryStream(pi.ImageData);
                im = System.Drawing.Image.FromStream(strm);

                // http://www.fyireporting.com/forum/viewtopic.php?t=892
                //A.S.> convert pt to px if needed(when printing we need px, when draw preview - pt)

                RectangleF r2;
                if (g.PageUnit == GraphicsUnit.Pixel)
                {
                    r2 = new RectangleF(r.Left + (si.PaddingLeft * g.DpiX) / 72,
                    r.Top + (si.PaddingTop * g.DpiX) / 72,
                    r.Width - ((si.PaddingLeft + si.PaddingRight) * g.DpiX) / 72,
                    r.Height - ((si.PaddingTop + si.PaddingBottom) * g.DpiX) / 72);
                }
                else
                {
                    // adjust drawing rectangle based on padding
                    r2 = new RectangleF(r.Left + si.PaddingLeft,
                    r.Top + si.PaddingTop,
                    r.Width - si.PaddingLeft - si.PaddingRight,
                    r.Height - si.PaddingTop - si.PaddingBottom);
                }

                int repeatX = 0;
                int repeatY = 0;
                switch (pi.Repeat)
                {
                    case ImageRepeat.Repeat:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        break;
                    case ImageRepeat.RepeatX:
                        repeatX = (int)Math.Floor(r2.Width / pi.SamplesW);
                        repeatY = 1;
                        break;
                    case ImageRepeat.RepeatY:
                        repeatY = (int)Math.Floor(r2.Height / pi.SamplesH);
                        repeatX = 1;
                        break;
                    case ImageRepeat.NoRepeat:
                    default:
                        repeatX = repeatY = 1;
                        break;
                }

                //make sure the image is drawn at least 1 times
                repeatX = Math.Max(repeatX, 1);
                repeatY = Math.Max(repeatY, 1);

                float startX = r2.Left;
                float startY = r2.Top;

                Region saveRegion = g.Clip;
                Region clipRegion = new Region(g.Clip.GetRegionData());
                clipRegion.Intersect(r2);
                g.Clip = clipRegion;

                for (int i = 0; i < repeatX; i++)
                {
                    for (int j = 0; j < repeatY; j++)
                    {
                        float currX = startX + i * pi.SamplesW;
                        float currY = startY + j * pi.SamplesH;
                        g.DrawImage(im, new RectangleF(currX, currY, pi.SamplesW, pi.SamplesH));
                    }
                }
                g.Clip = saveRegion;
            }
            finally
            {
                if (strm != null)
                    strm.Close();
                if (im != null)
                    im.Dispose();
            }
        }
        //25072008 GJL Draw a bezier curve
        private void iAddCurve(float X1, float Y1, float X2, float Y2, float X3, float Y3, float X4, float Y4, StyleInfo si, string url)
        {
            if (si.BStyleTop != BorderStyleEnum.None)
            {
                switch (si.BStyleTop)
                {
                case BorderStyleEnum.Dashed:
                    _contentByte.SetLineDash(new float[] { '3', '2' }, 0);
                    break;

                case BorderStyleEnum.Dotted:
                    _contentByte.SetLineDash(new float[] { '2' }, 0);
                    break;

                case BorderStyleEnum.Solid:
                default:
                    _contentByte.SetLineDash(new float[] { }, 0);
                    break;
                }
                _contentByte.SetRgbColorStroke(si.BColorTop.R, si.BColorTop.G, si.BColorTop.B);
            }

            if (!si.BackgroundColor.IsEmpty)
            {
                _contentByte.SetRgbColorStrokeF(si.BackgroundColor.R, si.BackgroundColor.G, si.BackgroundColor.B);
            }
            _contentByte.CurveTo(X1, PageSize.yHeight - Y1, X2, PageSize.yHeight - Y1, X3, PageSize.yHeight - Y3);
            if (si.BackgroundColor.IsEmpty)
            {
                _contentByte.ClosePathStroke();
            }
            else
            {
                _contentByte.ClosePathFillStroke();
            }
        }