示例#1
0
        private static void DrawComment(Gtk.PrintContext context, double x, double y, double h, string comment, bool rotated)
        {
            if (string.IsNullOrEmpty(comment))
                return;

            Context cr = context.CairoContext;
            cr.Save ();
            Pango.Layout layout = context.CreatePangoLayout ();
            Pango.FontDescription desc = Pango.FontDescription.FromString ("sans 14");
            layout.FontDescription = desc;
            layout.SetText (comment);
            int lay_w, lay_h;
            layout.GetPixelSize (out lay_w, out lay_h);
            double scale = h/lay_h;
            if (rotated) {
                cr.Translate (x - h, y + lay_w * scale);
                cr.Rotate (- Math.PI / 2);
            }
            else
                cr.Translate (x - lay_w * scale, y - h);
            cr.Scale (scale, scale);
            Pango.CairoHelper.ShowLayout (context.CairoContext, layout);
            cr.Restore ();
        }
示例#2
0
 Pango.Layout GetLayout(Gtk.Widget widget)
 {
     return widget.CreatePangoLayout (string.Empty);
 }
示例#3
0
        public void Draw(Gtk.PrintContext context)
        {
            Cairo.Context con = context.CairoContext;
            Pango.Layout layout = context.CreatePangoLayout();

            layout.SetText(this.textValue);
            layout.FontDescription = Pango.FontDescription.FromString(this.FontDescription);

            int pixelSizeWidth, pixelSizeHeight;
            layout.GetPixelSize(out pixelSizeWidth, out pixelSizeHeight);

            Console.WriteLine("   Text value: " + this.textValue);
            Console.WriteLine("   Pixel size width: " + pixelSizeWidth);
            Console.WriteLine("   Pixel size height: " + pixelSizeHeight);
            Console.WriteLine("   Text X position: " + this.x);
            Console.WriteLine("   Text Y position: " + this.y);

            double x_offset = pixelSizeWidth*0; // Disabled
            double y_offset = pixelSizeHeight * 0.83;

            Console.WriteLine("width: " + x_offset);
            Console.WriteLine("height: " + y_offset);

            /// Alignment
            /// If text.Alignment == "center", then x coordinate is indicating
            /// the center, not the left side. That's way we add pixelSizeWidth/2
            /// to x_offset
            if (this.alignment.Equals("center")) {
                layout.Alignment = Pango.Alignment.Center;
                x_offset += pixelSizeWidth/2;
            }

            con.MoveTo(this.x - x_offset, this.y - y_offset);
            Pango.CairoHelper.ShowLayout(con, layout);

            //			con.MoveTo(text.X, text.Y - y_offset);
            //			con.LineTo(text.X + 100, text.Y - y_offset);
            //			con.Stroke();
            //
            //			con.MoveTo(text.X, 38.4376957919563);
            //			con.LineTo(text.X + 100, 38.4376957919563);
            //			con.Stroke();
        }
                private Pango.Layout CreateTimestampLayout (Gtk.PrintContext context)
                {
                        Pango.Layout layout = context.CreatePangoLayout ();
                        layout.FontDescription = Window.Editor.Style.FontDesc;
                        layout.Width = Pango.Units.FromPixels ((int) context.Width);
                        layout.FontDescription.Style = Pango.Style.Normal;
                        layout.FontDescription.Weight = Pango.Weight.Light;

                        string footer_right = DateTime.Now.ToString (
                        /* Translators: Explanation of the date and time format specifications can be found here:
                         * http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx */
                                Catalog.GetString ("dddd MM/dd/yyyy, hh:mm:ss tt"));
                        layout.Alignment = Pango.Alignment.Right;
                        layout.SetText (footer_right);

                        return layout;
                }
		private Pango.Layout CreatePagenumbersLayout (Gtk.PrintContext context,
		                                              int page_number, int total_pages)
                {
                        Pango.Layout layout = context.CreatePangoLayout ();
                        layout.FontDescription = Window.Editor.Style.FontDesc;
                        layout.Width = Pango.Units.FromPixels ((int) context.Width);
                        layout.FontDescription.Style = Pango.Style.Normal;
                        layout.FontDescription.Weight = Pango.Weight.Light;

                        string footer_left = string.Format (Catalog.GetString ("Page {0} of {1}"),
                                                            page_number, total_pages);
                        layout.Alignment = Pango.Alignment.Left;
                        layout.SetText (footer_left);

                        return layout;
                }
		private Pango.Layout CreateParagraphLayout (Gtk.PrintContext context,
							       Gtk.TextIter p_start,
							       Gtk.TextIter p_end,
							       out int indentation)
		{
			Pango.Layout layout = context.CreatePangoLayout ();
			layout.FontDescription = Window.Editor.Style.FontDesc;
			int start_index = p_start.LineIndex;
			indentation = 0;

			double dpiX = context.DpiX;
			using (Pango.AttrList attr_list = new Pango.AttrList ()) {
				Gtk.TextIter segm_start = p_start;
				Gtk.TextIter segm_end;
				
				while (segm_start.Compare (p_end) < 0) {
					segm_end = segm_start;
					IEnumerable<Pango.Attribute> attrs =
						GetParagraphAttributes (
							layout, dpiX, out indentation,
							ref segm_end, p_end);

					uint si = (uint) (segm_start.LineIndex - start_index);
					uint ei = (uint) (segm_end.LineIndex - start_index);

					foreach (Pango.Attribute a in attrs) {
						a.StartIndex = si;
						a.EndIndex = ei;
						attr_list.Insert (a);
					}
					segm_start = segm_end;
				}

				layout.Attributes = attr_list;
			}

			DepthNoteTag depth = Buffer.FindDepthTag (p_start);
			if (depth != null)
				indentation += ((int) (dpiX / 3)) * depth.Depth;

			layout.Width = Pango.Units.FromPixels ((int)context.Width -
				margin_left - margin_right - indentation);
			layout.Wrap = Pango.WrapMode.WordChar;
			layout.SetText (Buffer.GetSlice (p_start, p_end, false));
			return layout;
		}
示例#7
0
        public void Draw(Gtk.PrintContext context,
		                  Dictionary<string, string> data,
		                  Dictionary<string, DataTable> dataTables,
		                  double maxYToDraw,
		                  bool reallyDraw)
        {
            foreach (IShape aShape in this.shapesInSection) {
                if (aShape is Text) {
                    Text aText = (Text)aShape;
                    Console.WriteLine(aText.TextValue);

                    if (data.ContainsKey(aText.Id))
                        aText.TextValue = data[aText.Id];
                }

                else if (aShape is Table) {
                    Table aTable = (Table)aShape;

                    /* If the table has no data, don't draw it */
                    if (!dataTables.ContainsKey(aTable.Id))
                        continue;

                    // DataTable corresponding to the Table object
                    DataTable dataTable = dataTables[aTable.Id];

                    if (this.datarowsToDraw == null) {
                        this.datarowsToDraw = new List<DataRow>();

                        // Add all DataRows
                        foreach (DataRow dr in dataTable.Rows)
                            this.datarowsToDraw.Add(dr);

                        this.originalNumberOfDataRows = this.datarowsToDraw.Count;
                    }

                    Console.WriteLine("Procesando un DataTable...");

                    Text textTemp = null;
                    List<Text> textRow = new List<Text>(aTable.NumberOfColumns);
                    List<DataRow> datarowsDrawn = new List<DataRow>();

                    foreach (DataRow dataRow in this.datarowsToDraw) {
                        foreach (Text aText in aTable.LastRowAdded) {
                            Console.WriteLine("   Text: " + aText.TextValue);

                            textTemp = (Text)aText.Clone();
                            textTemp.TextValue =
                                dataRow[textTemp.Id].ToString();
                            textTemp.Y = textTemp.Y +
                                Utils.GetPixelHeightSize(textTemp,
                                                         context.CreatePangoLayout());

                            textRow.Add(textTemp);
                        }

                        /* We stop drawing rows if we have reached the end
                         * of the section (the start of the next one) */
                        double heightOfLastText =
                            textTemp.Y + Utils.GetPixelHeightSize(textTemp,
                                                                  context.CreatePangoLayout());
                        if (heightOfLastText > maxYToDraw)
                            break;

                        aTable.AddRow(textRow);
                        textRow.Clear();

                        /* I add the DataRow to remove it later.
                         * This is for multipage reports, where there is a lot
                         * of data. Next call to this function we will draw
                         * remaning shapes */
                        datarowsDrawn.Add(dataRow);
                    }

                    // Remove already drawn datarows
                    foreach (DataRow dr in datarowsDrawn)
                        this.datarowsToDraw.Remove(dr);
                }

                // Draw the Shape
                if (reallyDraw)
                    aShape.Draw(context);

                // Let's reset all tables for next iteration
                if (aShape is Table) (aShape as Table).Reset();
            }
        }