コード例 #1
0
        void PrintHeader(Cairo.Context cr, PrintContext context, int page, ref double xPos, ref double yPos)
        {
            if (headerLines == 0)
            {
                return;
            }

            ResetAttributes();

            layout.SetText(Subst(headerText, page));

            int wout, hout;

            layout.GetSize(out wout, out hout);
            double w = wout / Pango.Scale.PangoScale;

            cr.MoveTo((pageWidth - w) / 2, yPos);
            Pango.CairoHelper.ShowLayout(cr, layout);

            yPos += lineHeight * headerLines;

            if (settings.HeaderSeparatorWeight > 0)
            {
                cr.LineWidth = settings.HeaderSeparatorWeight;
                cr.MoveTo(pageWidth / 3, yPos + (settings.HeaderPadding / 2));
                cr.LineTo(2 * pageWidth / 3, yPos + (settings.HeaderPadding / 2));
                cr.Stroke();
            }

            yPos += settings.HeaderPadding;
        }
コード例 #2
0
ファイル: MyPrinter.cs プロジェクト: deleteLater/CSharp
        private void OnDrawPage(object obj, Gtk.DrawPageArgs args)
        {
            PrintContext context = args.Context;

            Cairo.Context cr    = context.CairoContext;
            double        width = context.Width;

            cr.Rectangle(0, 0, width, headerHeight);
            cr.SetSourceRGB(0.8, 0.8, 0.8);
            cr.FillPreserve();

            cr.SetSourceRGB(0, 0, 0);
            cr.LineWidth = 1;
            cr.Stroke();

            Pango.Layout layout = context.CreatePangoLayout();

            Pango.FontDescription desc = Pango.FontDescription.FromString("sans 14");
            layout.FontDescription = desc;

            layout.SetText(fileName);
            layout.Width     = (int)width;
            layout.Alignment = Pango.Alignment.Center;

            int layoutWidth, layoutHeight;

            layout.GetSize(out layoutWidth, out layoutHeight);
            double textHeight = (double)layoutHeight / (double)pangoScale;

            cr.MoveTo(width / 2, (headerHeight - textHeight) / 2);
            Pango.CairoHelper.ShowLayout(cr, layout);

            string pageStr = String.Format("{0}/{1}", args.PageNr + 1, numPages);

            layout.SetText(pageStr);
            layout.Alignment = Pango.Alignment.Right;

            cr.MoveTo(width - 2, (headerHeight - textHeight) / 2);
            Pango.CairoHelper.ShowLayout(cr, layout);

            layout = null;
            layout = context.CreatePangoLayout();

            desc      = Pango.FontDescription.FromString("mono");
            desc.Size = (int)(fontSize * pangoScale);
            layout.FontDescription = desc;

            cr.MoveTo(0, headerHeight + headerGap);
            int line = args.PageNr * linesPerPage;

            for (int i = 0; i < linesPerPage && line < numLines; i++)
            {
                layout.SetText(lines[line]);
                Pango.CairoHelper.ShowLayout(cr, layout);
                cr.RelMoveTo(0, fontSize);
                line++;
            }
            (cr as IDisposable).Dispose();
            layout = null;
        }
コード例 #3
0
        public Size GetSize(object backend)
        {
            Pango.Layout tl = (Pango.Layout)backend;
            int          w, h;

            tl.GetSize(out w, out h);
            return(new Size((double)w / (double)Pango.Scale.PangoScale, (double)h / (double)Pango.Scale.PangoScale));
        }
コード例 #4
0
ファイル: ZoomableCairoArea.cs プロジェクト: tabrath/meshwork
        protected Size GetTextSize(Pango.Layout layout)
        {
            int textWidth, textHeight;

            layout.GetSize(out textWidth, out textHeight);
            textWidth  = Pango.Units.ToPixels(textWidth);
            textHeight = Pango.Units.ToPixels(textHeight);
            return(new Size(textWidth, textHeight));
        }
コード例 #5
0
        private Size MeasureString(Pango.FontDescription font, string s)
        {
            Pango.Layout ly = this.Layout;
            ly.SetText(s);

            ly.FontDescription = font;
            int width, height;

            ly.GetSize(out width, out height);
            return(new Size((int)(width / 1024.0f), (int)(height / 1024.0f)));
        }
コード例 #6
0
 public void GetSize(out int width, out int height)
 {
     if (this.width >= 0)
     {
         width  = this.width;
         height = this.height;
         return;
     }
     layout.GetSize(out width, out height);
     this.width  = width;
     this.height = height;
 }
コード例 #7
0
        protected void MeasureString(Cairo.Context graphics, string s, out int width, out int height)
        {
            Pango.FontDescription font   = Settings.Font;
            Pango.Layout          layout = Pango.CairoHelper.CreateLayout(graphics);

            layout.FontDescription = font;
            layout.SetText(s);

            layout.GetSize(out width, out height);

            height = (int)(height / Pango.Scale.PangoScale);
            width  = (int)(width / Pango.Scale.PangoScale);
        }
コード例 #8
0
        protected virtual void DrawLabel(Cairo.Context graphics)
        {
            string s = Label;

            if (String.IsNullOrEmpty(s))
            {
                return;
            }

            if (MouseFocus)
            {
                graphics.SetSourceRGB(0.3, 0.6, 0.3);
            }
            else
            {
                graphics.SetSourceRGB(0.3, 0.3, 0.3);
            }

            double uw = graphics.LineWidth;

            graphics.Save();
            graphics.Scale(uw, uw);

            Pango.Layout layout = Pango.CairoHelper.CreateLayout(graphics);
            Pango.CairoHelper.UpdateLayout(graphics, layout);
            layout.FontDescription = Settings.Font;

            layout.SetText(s);

            int width, height;

            layout.GetSize(out width, out height);

            width = (int)(width / Pango.Scale.PangoScale);

            graphics.MoveTo((Allocation.Width / uw - width) / 2.0, Allocation.Height / uw + 2);
            Pango.CairoHelper.ShowLayout(graphics, layout);
            graphics.Restore();
        }
コード例 #9
0
        private int RenderNotice(string text, Cairo.Context gc, int yOffset)
        {
            gc.Save();

            int leftPadding = 20;
            int rightPadding = 20;
            int topPadding = 20 + yOffset;
            int innerPadding = 5;
            int textWidth, textHeight;

            // Setup text
            Pango.Layout layout = Pango.CairoHelper.CreateLayout(gc);
            layout.FontDescription      = this.PangoContext.FontDescription.Copy();
            layout.FontDescription.Size = layout.FontDescription.Size + Pango.Units.FromPixels(3);
            layout.Wrap  = Pango.WrapMode.Word;
            layout.Width = Pango.Units.FromPixels(this.Allocation.Width - (leftPadding + innerPadding + noticeIcon.Width + innerPadding + rightPadding + innerPadding));
            layout.SetMarkup(text);
            layout.GetSize(out textWidth, out textHeight);
            textWidth  = Pango.Units.ToPixels(textWidth);
            textHeight = Pango.Units.ToPixels(textHeight);

            // Render background
            gc.Color = new Cairo.Color(0.59, 0.59, 0.59, 0.6);
            CreateRoundedRectPath(gc, leftPadding, topPadding, textWidth + 50, textHeight + (innerPadding * 2.0), 10);
            gc.Fill();

            // Render icon
            RenderPixbufToSurf(gc, noticeIcon, leftPadding + innerPadding, topPadding + innerPadding + ((textHeight / 2.0) - (noticeIcon.Height / 2.0)));

            // Render text
            gc.MoveTo(leftPadding + innerPadding + noticeIcon.Width + innerPadding, topPadding + innerPadding);
            gc.Color = white;
            Pango.CairoHelper.ShowLayout(gc, layout);

            gc.Restore();

            return(textHeight + topPadding - yOffset);
        }
コード例 #10
0
        protected override void OnDrawPage(PrintContext context, int pageNr)
        {
            using (var cr = context.CairoContext) {
                double xPos = 0, yPos = 0;

                PrintHeader(cr, context, pageNr, ref xPos, ref yPos);

                int startLine = pageNr * linesPerPage;
                int endLine   = Math.Min(startLine + linesPerPage - 1, doc.LineCount);

                //FIXME: use proper 1-layout-per-line
                for (int i = startLine; i < endLine; i++)
                {
                    var line = doc.GetLine(i + 1);
                    if (!settings.UseHighlighting)
                    {
                        string text = doc.GetTextAt(line);
                        text = text.Replace("\t", new string (' ', settings.TabSize));

                        layout.SetText(text);
                        cr.MoveTo(xPos, yPos);
                        Pango.CairoHelper.ShowLayout(cr, layout);

                        yPos += lineHeight;
                        continue;
                    }

                    Chunk startChunk = doc.SyntaxMode.GetChunks(doc, style, line, line.Offset, line.Length);
                    for (Chunk chunk = startChunk; chunk != null; chunk = chunk != null ? chunk.Next : null)
                    {
                        ChunkStyle chunkStyle = chunk != null?chunk.GetChunkStyle(style) : null;

                        string text = chunk.GetText(doc);
                        text = text.Replace("\t", new string (' ', settings.TabSize));
                        layout.SetText(text);

                        var atts = ResetAttributes();

                        atts.Insert(new Pango.AttrForeground(chunkStyle.Color.Red, chunkStyle.Color.Green, chunkStyle.Color.Blue));

                        if (chunkStyle.Bold)
                        {
                            atts.Insert(new Pango.AttrWeight(Pango.Weight.Bold));
                        }
                        if (chunkStyle.Italic)
                        {
                            atts.Insert(new Pango.AttrStyle(Pango.Style.Italic));
                        }
                        if (chunkStyle.Underline)
                        {
                            atts.Insert(new Pango.AttrUnderline(Pango.Underline.Single));
                        }

                        cr.MoveTo(xPos, yPos);
                        Pango.CairoHelper.ShowLayout(cr, layout);

                        int wout, hout;
                        layout.GetSize(out wout, out hout);
                        double w = wout / Pango.Scale.PangoScale;

                        xPos += w;

                        if (w > pageWidth)
                        {
                            break;
                        }
                    }
                    xPos  = 0;
                    yPos += lineHeight;
                }

                PrintFooter(cr, context, pageNr, ref xPos, ref yPos);
            }
        }
コード例 #11
0
        protected override async void OnDrawPage(PrintContext context, int pageNr)
        {
            using (var cr = context.CairoContext) {
                double xPos = 0, yPos = 0;

                PrintHeader(cr, context, pageNr, ref xPos, ref yPos);

                int startLine = pageNr * linesPerPage;
                int endLine   = Math.Min(startLine + linesPerPage - 1, editor.LineCount);
                var theme     = editor.Options.GetEditorTheme();

                //FIXME: use proper 1-layout-per-line
                for (int i = startLine; i < endLine; i++)
                {
                    var line = editor.GetLine(i + 1);
                    if (!settings.UseHighlighting)
                    {
                        string text = editor.GetTextAt(line);
                        text = text.Replace("\t", new string (' ', settings.TabSize));

                        layout.SetText(text);
                        cr.MoveTo(xPos, yPos);
                        Pango.CairoHelper.ShowLayout(cr, layout);

                        yPos += lineHeight;
                        continue;
                    }

                    var highlightedLine = await editor.SyntaxHighlighting.GetHighlightedLineAsync(line, default(CancellationToken));

                    var lineOffset = line.Offset;
                    foreach (var chunk in highlightedLine.Segments)
                    {
                        var    chunkStyle = theme.GetChunkStyle(chunk.ScopeStack);
                        string text       = editor.GetTextAt(lineOffset + chunk.Offset, chunk.Length);
                        text = text.Replace("\t", new string (' ', settings.TabSize));
                        layout.SetText(text);

                        var atts = ResetAttributes();

                        var foreground = (Cairo.Color)chunkStyle.Foreground;
                        atts.Insert(new Pango.AttrForeground((ushort)(foreground.R * ushort.MaxValue), (ushort)(foreground.G * ushort.MaxValue), (ushort)(foreground.B * ushort.MaxValue)));

                        if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal)
                        {
                            atts.Insert(new Pango.AttrWeight((Pango.Weight)chunkStyle.FontWeight));
                        }
                        if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal)
                        {
                            atts.Insert(new Pango.AttrStyle((Pango.Style)chunkStyle.FontStyle));
                        }
                        if (chunkStyle.Underline)
                        {
                            atts.Insert(new Pango.AttrUnderline(Pango.Underline.Single));
                        }

                        cr.MoveTo(xPos, yPos);
                        Pango.CairoHelper.ShowLayout(cr, layout);

                        int wout, hout;
                        layout.GetSize(out wout, out hout);
                        double w = wout / Pango.Scale.PangoScale;

                        xPos += w;

                        if (w > pageWidth)
                        {
                            break;
                        }
                    }

                    xPos  = 0;
                    yPos += lineHeight;
                }

                PrintFooter(cr, context, pageNr, ref xPos, ref yPos);
            }
        }
コード例 #12
0
            private void GetCoordLayoutDetails(Pango.
							    Context context,
							    FontDescription
							    font)
            {
                if (!showCoords)
                  {
                      fontwidth = 0;
                      fontheight = 0;
                      return;
                  }
                layoutx = new Pango.Layout[8];
                layouty = new Pango.Layout[8];
                char chx = 'a';
                char chy = '1';
                fontwidth = 0;
                fontheight = 0;
                for (int i = 0; i < layoutx.Length;
                     i++, chx++, chy++)
                  {
                      Pango.Layout layout;
                      layoutx[i] = layout =
                          new Pango.Layout (context);
                      layout.FontDescription = font;
                      layout.SetText (chx.ToString ());
                      int w, h;
                      layout.GetSize (out w, out h);
                      h = (int) Math.Round (h /
                                Pango.Scale.
                                PangoScale);
                      if (h > fontheight)
                          fontheight = h;

                      layouty[i] = layout =
                          new Pango.Layout (context);
                      layout.FontDescription = font;
                      layout.SetText (chy.ToString ());
                      layout.GetSize (out w, out h);
                      w = (int) Math.Round (w /
                                Pango.Scale.
                                PangoScale);
                      if (w > fontwidth)
                          fontwidth = w;
                  }
            }
コード例 #13
0
 public void GetSize(out int width, out int height)
 {
     layout.GetSize(out width, out height);
 }
コード例 #14
0
        protected override void OnDrawPage(PrintContext context, int pageNr)
        {
            using (var cr = context.CairoContext) {
                double xPos = 0, yPos = 0;

                PrintHeader(cr, context, pageNr, ref xPos, ref yPos);

                int startLine = pageNr * linesPerPage;
                int endLine   = Math.Min(startLine + linesPerPage - 1, doc.LineCount);

                //FIXME: use proper 1-layout-per-line
                for (int i = startLine; i < endLine; i++)
                {
                    var line = doc.GetLine(i + 1);
                    if (!settings.UseHighlighting)
                    {
                        string text = doc.GetTextAt(line);
                        text = text.Replace("\t", new string (' ', settings.TabSize));

                        layout.SetText(text);
                        cr.MoveTo(xPos, yPos);
                        Pango.CairoHelper.ShowLayout(cr, layout);

                        yPos += lineHeight;
                        continue;
                    }

                    var startChunk = doc.SyntaxMode.GetChunks(style, line, line.Offset, line.LengthIncludingDelimiter);
                    foreach (Chunk chunk in startChunk)
                    {
                        var chunkStyle = chunk != null?style.GetChunkStyle(chunk) : null;

                        string text = doc.GetTextAt(chunk);
                        text = text.Replace("\t", new string (' ', settings.TabSize));
                        layout.SetText(text);

                        var atts = ResetAttributes();

                        atts.Insert(new Pango.AttrForeground((ushort)(chunkStyle.Foreground.R * ushort.MaxValue), (ushort)(chunkStyle.Foreground.G * ushort.MaxValue), (ushort)(chunkStyle.Foreground.B * ushort.MaxValue)));

                        if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal)
                        {
                            atts.Insert(new Pango.AttrWeight((Pango.Weight)chunkStyle.FontWeight));
                        }
                        if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal)
                        {
                            atts.Insert(new Pango.AttrStyle((Pango.Style)chunkStyle.FontStyle));
                        }
                        if (chunkStyle.Underline)
                        {
                            atts.Insert(new Pango.AttrUnderline(Pango.Underline.Single));
                        }

                        cr.MoveTo(xPos, yPos);
                        Pango.CairoHelper.ShowLayout(cr, layout);

                        int wout, hout;
                        layout.GetSize(out wout, out hout);
                        double w = wout / Pango.Scale.PangoScale;

                        xPos += w;

                        if (w > pageWidth)
                        {
                            break;
                        }
                    }

                    xPos  = 0;
                    yPos += lineHeight;
                }

                PrintFooter(cr, context, pageNr, ref xPos, ref yPos);
            }
        }