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(); } }
public string GetPdfFont(StyleInfo si) { string face = FontNameNormalize(si.FontFamily); if (face == "Times-Roman") { if (si.IsFontBold() && si.FontStyle == FontStyleEnum.Italic) face = "Times-BoldItalic"; else if (si.IsFontBold()) face = "Times-Bold"; else if (si.FontStyle == FontStyleEnum.Italic) face = "Times-Italic"; } 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"; return GetPdfFont(face); }
private void InsertContentControl(int number, string content, float X, float Y, float W, float H, StyleInfo styleInfo, PageText pt) { int sCountTo, sCountFrom; sCountFrom = (int)(X / spaceWidth); sCountTo = (int)((X + W) / spaceWidth); int rCount = (int)((Y + H) / rowHeight); //if (styleInfo.FontWeight == FontWeightEnum.Bold) //{ // content = content.Insert(0, BoldOn); // content = content.Insert(content.Length, BoldOff); //} //if (styleInfo.FontSize > 11f) //{ // content = content.Insert(0, Expanded); // content = content.Insert(content.Length, ExpandedNormal); //} DMPControl control = new DMPControl(); control.Number = number; control.LineNumber = rCount; control.FromIndex = sCountFrom; control.ToIndex = sCountTo; control.ContentLength = content.Length; control.VerticalAlign = styleInfo.VerticalAlign; control.TextAlign = styleInfo.TextAlign; control.String = content; control.CanGrow = pt.CanGrow; control.SI = styleInfo; control.TopBorder = styleInfo.BStyleTop == BorderStyleEnum.Solid || styleInfo.BStyleTop == BorderStyleEnum.Dotted; control.BottomBorder = styleInfo.BStyleBottom == BorderStyleEnum.Solid || styleInfo.BStyleBottom == BorderStyleEnum.Dotted; ContentControls.Add(control); }
public void InsertContent(string content, float X, float Y, float W, float H, bool canGrow) { int sCountTo, sCountFrom; sCountFrom = (int)(X / spaceWidth); sCountTo = (int)((X + W) / spaceWidth); int rCount = (int)((Y + H) / rowHeight); if (Content.Count >= rCount) { StyleInfo styleInfo = new StyleInfo() { TextAlign = TextAlignEnum.Left }; bool isFullTextPrinted = Content[rCount].InsertText(content, sCountFrom, sCountTo, styleInfo); if (canGrow) CheckGrowedText(isFullTextPrinted, content, rCount, sCountFrom, sCountTo, styleInfo); } }
//25072008 GJL Draw 4 bezier curves to approximate a circle public 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"); }
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; }
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; }
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; }
public bool InsertGrowedText(string text, int index, int lastIndex, StyleInfo styleInfo) { int space = lastIndex - (index + 1); if (space > text.Length && styleInfo.TextAlign == TextAlignEnum.Center) index += (space - text.Length) / 2; else if (space > text.Length && styleInfo.TextAlign == TextAlignEnum.Right) index += (space - text.Length); foreach (char _char in text) { if (index >= lastIndex - 1) return false; if (Line.Count > index) { Line[index].Char = Line[index].IsBlank() || Line[index].Char == _LineHChar ? _char : Line[index].Char; index++; } else { AddChar(_char); index++; } } return true; }
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.Drawing.SolidBrush theBrush = (System.Drawing.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 }
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); }
private void CheckGrowedText(bool isFullTextPrinted, string content, int rCount, int sCountFrom, int sCountTo, StyleInfo styleInfo) { int lineNumber = rCount + 1; int index = sCountTo - (sCountFrom + 1); string text = content; while (!isFullTextPrinted) { text = text.Remove(0, index); if (Content.Count > lineNumber) { isFullTextPrinted = Content[lineNumber].InsertGrowedText(text, sCountFrom, sCountTo, styleInfo); } else { break; } lineNumber = lineNumber + 1; } }
public void InsertContent(string content, float X, float Y, float W, float H, StyleInfo styleInfo, bool canGrow) { int sCountTo, sCountFrom; sCountFrom = (int)(X / spaceWidth); sCountTo = (int)((X + W) / spaceWidth); int rCount = (int)((Y + H) / rowHeight); if (Content.Count >= rCount) { if (styleInfo.FontWeight == FontWeightEnum.Bold) { content = content.Insert(0, BoldOn); content = content.Insert(content.Length, BoldOff); } if (styleInfo.FontSize > 11f) { content = content.Insert(0, Expanded); content = content.Insert(content.Length, ExpandedNormal); } InsertBordar(X, Y, W, H, styleInfo); bool isFullTextPrinted = Content[rCount].InsertText(content, sCountFrom, sCountTo, styleInfo); if (canGrow) { CheckGrowedText(isFullTextPrinted, content, rCount, sCountFrom, sCountTo, styleInfo); } } }
public void InsertLineContent(int number, float X, float Y, float W, float H, StyleInfo styleInfo) { int sCountTo, sCountFrom; sCountFrom = (int)(X / spaceWidth); sCountTo = (int)((X + W) / spaceWidth); int rCount = (int)((Y + H) / rowHeight); int i = rCount; DMPControl control = new DMPControl(); control.Number = number; control.LineNumber = rCount; control.FromIndex = sCountFrom; control.ToIndex = sCountTo; control.VerticalAlign = styleInfo.VerticalAlign; control.TextAlign = styleInfo.TextAlign; control.InsertLine(sCountFrom, sCountTo); control.CanGrow = false; control.SI = styleInfo; control.TopBorder = styleInfo.BStyleTop == BorderStyleEnum.Solid || styleInfo.BStyleTop == BorderStyleEnum.Dotted; control.BottomBorder = styleInfo.BStyleBottom == BorderStyleEnum.Solid || styleInfo.BStyleBottom == BorderStyleEnum.Dotted; ContentControls.Add(control); }
private void CheckGrowedText(bool isFullTextPrinted, string content, int rCount, int sCountFrom, int sCountTo, StyleInfo styleInfo) { int lineNumber = rCount + 1; int index = sCountTo - (sCountFrom + 1); string text = content; while (!isFullTextPrinted) { text = text.Remove(0, index); if (Content.Count > lineNumber) isFullTextPrinted = Content[lineNumber].InsertGrowedText(text, sCountFrom, sCountTo, styleInfo); else break; lineNumber = lineNumber + 1; } }
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; }
public void InsertLine(float X, float Y, float W, float H, StyleInfo styleInfo) { int sCountTo, sCountFrom; sCountFrom = (int)(X / spaceWidth); sCountTo = (int)((X + W) / spaceWidth); int rCount = (int)((Y + H) / rowHeight); int i = rCount; if (Content.Count >= i) { Content[i].InsertLine(sCountFrom, sCountTo); } }
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; }
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; }
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(); } } }
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; }
/// <summary> /// Page line element at the X Y to X2 Y2 position /// </summary> /// <returns></returns> public void AddLine(float x, float y, float x2, float y2, StyleInfo si) { AddLine(x, y, x2, y2, si.BWidthTop, si.BColorTop, si.BStyleTop); }
private void DoInstructions(PointF[] Ps, Brush b) { PagePolygon pl = new PagePolygon(); //pl.X = X * SCALEFACTOR; //pl.Y = Y * SCALEFACTOR; pl.Points = Ps; StyleInfo SI = new StyleInfo(); switch (b.GetType().Name) { case "SolidBrush": System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b; SI.Color = theBrush.Color; SI.BackgroundColor = theBrush.Color; break; case "LinearGradientBrush": System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b; SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight; SI.BackgroundColor = linBrush.LinearColors[0]; SI.BackgroundGradientEndColor = linBrush.LinearColors[1]; break; case "HatchBrush": System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b; SI.BackgroundColor = hatBrush.BackgroundColor; SI.Color = hatBrush.ForegroundColor; SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle); break; default: break; } pl.SI = SI; items.Add(pl); }
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; } }
/// <summary> /// Page Text element at the X Y position; multiple lines handled /// </summary> /// <returns></returns> public void AddText(float x, float y, float height, float width, string[] sa, StyleInfo si, PdfFonts fonts, float[] tw, bool bWrap, string url, bool bNoClip, string tooltip) { // 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; } } 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 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); } if (tooltip != null) { p.AddToolTip(x, pSize.yHeight - y, height, width, tooltip); } } 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; }
private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Pen p) { BorderStyleEnum ls = getLineStyle(p); switch (p.Brush.GetType().Name) { case "SolidBrush": System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)p.Brush; PageRectangle pl = new PageRectangle(); 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; } }
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); //} }
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(); } } }
private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Brush b, Single StartAngle, Single SweepAngle) { PagePie pl = new PagePie(); pl.StartAngle = StartAngle; pl.SweepAngle = SweepAngle; StyleInfo SI = new StyleInfo(); pl.X = X + recX * SCALEFACTOR; pl.Y = Y + recY * SCALEFACTOR; pl.W = recWidth * SCALEFACTOR; pl.H = recHeight * SCALEFACTOR; switch (b.GetType().Name) { case "SolidBrush": System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b; SI.Color = theBrush.Color; SI.BackgroundColor = theBrush.Color; break; case "LinearGradientBrush": System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b; SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight; SI.BackgroundColor = linBrush.LinearColors[0]; SI.BackgroundGradientEndColor = linBrush.LinearColors[1]; break; case "HatchBrush": System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b; SI.BackgroundColor = hatBrush.BackgroundColor; SI.Color = hatBrush.ForegroundColor; SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle); break; default: break; } pl.SI = SI; items.Add(pl); }
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; }
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; }
public void InsertContent(string content, float X, float Y, float W, float H, StyleInfo styleInfo, bool canGrow) { int sCountTo, sCountFrom; sCountFrom = (int)(X / spaceWidth); sCountTo = (int)((X + W) / spaceWidth); int rCount = (int)((Y + H) / rowHeight); if (Content.Count >= rCount) { if (styleInfo.FontWeight == FontWeightEnum.Bold) { content = content.Insert(0, BoldOn); content = content.Insert(content.Length, BoldOff); } if (styleInfo.FontSize > 11f) { content = content.Insert(0, Expanded); content = content.Insert(content.Length, ExpandedNormal); } InsertBordar(X, Y, W, H, styleInfo); bool isFullTextPrinted = Content[rCount].InsertText(content, sCountFrom, sCountTo, styleInfo); if (canGrow) CheckGrowedText(isFullTextPrinted, content, rCount, sCountFrom, sCountTo, styleInfo); } }
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); //} }
public void InsertBordar(float X, float Y, float W, float H, StyleInfo styleInfo) { int sCountTo, sCountFrom; sCountFrom = (int)(X / spaceWidth); sCountTo = (int)((X + W)/ spaceWidth); int rCount = (int)((Y + H) / rowHeight); string content = string.Empty; if (styleInfo.BStyleTop == BorderStyleEnum.Solid || styleInfo.BStyleTop == BorderStyleEnum.Dotted) { int i = rCount - 1; if (Content.Count >= i) { if (!Content[i].InsertHorizontalBorder(sCountFrom, sCountTo)) { // this.InsertForcedLine(i, TotalSpaces); // Content[i].InsertHorizontalBorder(sCountFrom, sCountTo); } } } if (styleInfo.BStyleBottom == BorderStyleEnum.Solid || styleInfo.BStyleBottom == BorderStyleEnum.Dotted) { int i = rCount + 1; if (Content.Count >= i) { if (!Content[i].InsertHorizontalBorder(sCountFrom, sCountTo)) { // this.InsertForcedLine(i, TotalSpaces); //Content[i].InsertHorizontalBorder(sCountFrom, sCountTo); } } } if (styleInfo.BStyleRight == BorderStyleEnum.Solid || styleInfo.BStyleRight == BorderStyleEnum.Dotted) { int i = sCountTo; if (Content.Count >= rCount) { Content[rCount].InsertVerticalBorder(i); } } if (styleInfo.BStyleLeft == BorderStyleEnum.Solid || styleInfo.BStyleLeft == BorderStyleEnum.Dotted) { int i = sCountFrom; if (Content.Count >= rCount) { Content[rCount].InsertVerticalBorder(i); } } }
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(); } } }
public DMPControl() { _LineHChar = '-'; _LineVChar = '|'; Content = new List<DMPChar>(); SI = new StyleInfo(); }
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; }
private void BuildAnchor(string token, StyleInfo oldsi, PageText model) { StyleInfo si= oldsi.Clone() as StyleInfo; // always push a StyleInfo _StyleStack.Push(si); // since they will always be popped Hashtable ht = ParseHtmlCmd(token); string href = (string) ht["href"]; if (href == null || href.Length < 1) return; model.HyperLink = model.Tooltip = href; si.TextDecoration = TextDecorationEnum.Underline; si.Color = Color.Blue; }
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); RectangleF r2 = new 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)); 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(); } }
private StyleInfo CurrentStyle(StyleInfo def) { if (_StyleStack == null || _StyleStack.Count == 0) return def; else return (StyleInfo) _StyleStack.Peek(); }
// Generate an evaluated version of all the style parameters; used for page processing public StyleInfo GetStyleInfo(Report rpt, Row r) { WorkClass wc = GetWC(rpt); if (wc != null && wc.StyleInfo != null) // When StyleInfo is available; style is a constant { return (StyleInfo) wc.StyleInfo.Clone(); // clone it because others can modify it after this } StyleInfo si = new StyleInfo(); if (this.BorderColor != null) { StyleBorderColor bc = this.BorderColor; si.BColorLeft = bc.EvalLeft(rpt, r); si.BColorRight = bc.EvalRight(rpt, r); si.BColorTop = bc.EvalTop(rpt, r); si.BColorBottom = bc.EvalBottom(rpt, r); } if (this.BorderStyle != null) { StyleBorderStyle bs = this.BorderStyle; si.BStyleLeft = bs.EvalLeft(rpt, r); si.BStyleRight = bs.EvalRight(rpt, r); si.BStyleTop = bs.EvalTop(rpt, r); si.BStyleBottom = bs.EvalBottom(rpt, r); } if (this.BorderWidth != null) { StyleBorderWidth bw = this.BorderWidth; si.BWidthLeft = bw.EvalLeft(rpt, r); si.BWidthRight = bw.EvalRight(rpt, r); si.BWidthTop = bw.EvalTop(rpt, r); si.BWidthBottom = bw.EvalBottom(rpt, r); } si.BackgroundColor = this.EvalBackgroundColor(rpt, r); // When background color not specified; and reportitem part of table // use the tables background color if (si.BackgroundColor == System.Drawing.Color.Empty) { ReportItem ri = this.Parent as ReportItem; if (ri != null) { if (ri.TC != null) { Table t = ri.TC.OwnerTable; if (t.Style != null) si.BackgroundColor = t.Style.EvalBackgroundColor(rpt, r); } } } si.BackgroundGradientType = this.EvalBackgroundGradientType(rpt, r); si.BackgroundGradientEndColor = this.EvalBackgroundGradientEndColor(rpt, r); if (this._BackgroundImage != null) { si.BackgroundImage = _BackgroundImage.GetPageImage(rpt, r); } else si.BackgroundImage = null; si.FontStyle = this.EvalFontStyle(rpt, r); si.FontFamily = this.EvalFontFamily(rpt, r); si.FontSize = this.EvalFontSize(rpt, r); si.FontWeight = this.EvalFontWeight(rpt, r); si._Format = this.EvalFormat(rpt, r); //(string) .NET Framework formatting string1 si.TextDecoration = this.EvalTextDecoration(rpt, r); si.TextAlign = this.EvalTextAlign(rpt, r); si.VerticalAlign = this.EvalVerticalAlign(rpt, r); si.Color = this.EvalColor(rpt, r); si.PaddingLeft = this.EvalPaddingLeft(rpt, r); si.PaddingRight = this.EvalPaddingRight(rpt, r); si.PaddingTop = this.EvalPaddingTop(rpt, r); si.PaddingBottom = this.EvalPaddingBottom(rpt, r); si.LineHeight = this.EvalLineHeight(rpt, r); si.Direction = this.EvalDirection(rpt, r); si.WritingMode = this.EvalWritingMode(rpt, r); si.Language = this.EvalLanguage(rpt, r); si.UnicodeBiDirectional = this.EvalUnicodeBiDirectional(rpt, r); si.Calendar = this.EvalCalendar(rpt, r); si.NumeralLanguage = this.EvalNumeralLanguage(rpt, r); si.NumeralVariant = this.EvalNumeralVariant(rpt, r); if (this._ConstantStyle) // We'll only do this work once { wc.StyleInfo = si; // when all are constant si = (StyleInfo) wc.StyleInfo.Clone(); } return si; }
private void HandleFont(string token, StyleInfo model) { StyleInfo si = model.Clone() as StyleInfo; // always push a StyleInfo _StyleStack.Push(si); // since they will always be popped PageTextHtmlCmdLexer hc = new PageTextHtmlCmdLexer(token.Substring(5)); Hashtable ht = hc.Lex(); string style = (string)ht["style"]; HandleStyleString(style, si); string color = (string)ht["color"]; if (color != null && color.Length > 0) si.Color = XmlUtil.ColorFromHtml(color, si.Color); string size = (string)ht["size"]; if (size != null && size.Length > 0) HandleStyleFontSize(si, size); string face = (string)ht["face"]; if (face != null && face.Length > 0) si.FontFamily = face; return; }
public StyleInfo StyleInfo; // When ConstantStyle is true; this will hold cache of StyleInfo public WorkClass() { CssStyle = null; StyleInfo = null; }
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; }
//25072008 GJL Draw a bezier curve public 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"); }
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(); } }
void AddBorder(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) AddLine(x, y, xright, y, si.BWidthTop, si.BColorTop, si.BStyleTop); if (si.BStyleRight != BorderStyleEnum.None && si.BWidthRight > 0) AddLine(xright, y, xright, ybottom, si.BWidthRight, si.BColorRight, si.BStyleRight); if (si.BStyleLeft != BorderStyleEnum.None && si.BWidthLeft > 0) AddLine(x, y, x, ybottom, si.BWidthLeft, si.BColorLeft, si.BStyleLeft); if (si.BStyleBottom != BorderStyleEnum.None && si.BWidthBottom > 0) AddLine(x, ybottom, xright, ybottom, si.BWidthBottom, si.BColorBottom, si.BStyleBottom); return; }