static void DrawRoundRectangle(Xwt.Drawing.Context cr, double x, double y, double r, double w, double h) { const double ARC_TO_BEZIER = 0.55228475; double radius_x = r; double radius_y = r / 4; if (radius_x > w - radius_x) { radius_x = w / 2; } if (radius_y > h - radius_y) { radius_y = h / 2; } double c1 = ARC_TO_BEZIER * radius_x; double c2 = ARC_TO_BEZIER * radius_y; cr.NewPath(); cr.MoveTo(x + radius_x, y); cr.RelLineTo(w - 2 * radius_x, 0.0); cr.RelCurveTo(c1, 0.0, radius_x, c2, radius_x, radius_y); cr.RelLineTo(0, h - 2 * radius_y); cr.RelCurveTo(0.0, c2, c1 - radius_x, radius_y, -radius_x, radius_y); cr.RelLineTo(-w + 2 * radius_x, 0); cr.RelCurveTo(-c1, 0, -radius_x, -c2, -radius_x, -radius_y); cr.RelLineTo(0, -h + 2 * radius_y); cr.RelCurveTo(0.0, -c2, radius_x - c1, -radius_y, radius_x, -radius_y); cr.ClosePath(); }
private void DrawLine(Xwt.Drawing.Color c, BorderStyleEnum bs, float w, Xwt.Drawing.Context g, double x, double y, double x2, double y2) { if (bs == BorderStyleEnum.None || //|| c.IsEmpty w <= 0) // nothing to draw { return; } g.Save(); // Pen p = null; // p = new Pen(c, w); g.SetColor(c); g.SetLineWidth(w); switch (bs) { case BorderStyleEnum.Dashed: // p.DashStyle = DashStyle.Dash; g.SetLineDash(0.0, new double[] { 2, 1 }); break; case BorderStyleEnum.Dotted: // p.DashStyle = DashStyle.Dot; g.SetLineDash(0.0, new double[] { 1 }); break; case BorderStyleEnum.Double: case BorderStyleEnum.Groove: case BorderStyleEnum.Inset: case BorderStyleEnum.Solid: case BorderStyleEnum.Outset: case BorderStyleEnum.Ridge: case BorderStyleEnum.WindowInset: default: g.SetLineDash(0.0, new double[] { }); break; } g.MoveTo(x, y); g.LineTo(x2, y2); g.Stroke(); g.Restore(); }
private void DrawString(PageText pt, Xwt.Drawing.Context g, Xwt.Rectangle r) { StyleInfo si = pt.SI; string s = pt.Text; g.Save(); layout = new Xwt.Drawing.TextLayout(g); layout.Font = g.Font; float fontsize = (si.FontSize * 72 / 96); layout.Font.WithFamily(si.GetFontFamily().Name); layout.Font.WithPixelSize(fontsize * PixelsX(1)); if (si.FontStyle == FontStyleEnum.Italic) { layout.Font.WithStyle(Xwt.Drawing.FontStyle.Italic); } switch (si.FontWeight) { case FontWeightEnum.Bold: case FontWeightEnum.Bolder: case FontWeightEnum.W500: case FontWeightEnum.W600: case FontWeightEnum.W700: case FontWeightEnum.W800: case FontWeightEnum.W900: layout.Font.WithWeight(Xwt.Drawing.FontWeight.Bold); break; } // TODO: Fix Alignment //switch (si.TextAlign) //{ // case TextAlignEnum.Right: // layout.Alignment = Pango.Alignment.Right; // break; // case TextAlignEnum.Center: // layout.Alignment = Pango.Alignment.Center; // break; // case TextAlignEnum.Left: // default: // layout.Alignment = Pango.Alignment.Left; // break; //} // TODO: Fix with //layout.Width = Pango.Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2)); layout.Text = s; //Xwt.Rectangle logical; // Xwt.Rectangle ink; // TODO: Fix //layout.GetExtents(out ink, out logical); double height = 12; // logical.Height / Pango.Scale.PangoScale; double y = 0; switch (si.VerticalAlign) { case VerticalAlignEnum.Top: y = r.Y + si.PaddingTop; break; case VerticalAlignEnum.Middle: y = r.Y + (r.Height - height) / 2; break; case VerticalAlignEnum.Bottom: y = r.Y + (r.Height - height) - si.PaddingBottom; break; } // draw the background DrawBackground(g, r, si); Xwt.Rectangle box = new Xwt.Rectangle( r.X + si.PaddingLeft + 1, y, r.Width, r.Height); Xwt.Drawing.Color sicolor = XwtColor.SystemColorToXwtColor(si.Color); g.SetColor(sicolor); g.MoveTo(box.X, box.Y); g.DrawTextLayout(layout, box.X, box.Y); g.Restore(); }