Exemplo n.º 1
0
 /// <summary>
 /// Adds a text string to this path.
 /// </summary>
 public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin, XStringFormat format)
 {
   this.gdipPath.AddString(s, family.family, (int)style, (float)emSize, origin.ToPointF(), format.RealizeGdiStringFormat());
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a cubic Bézier curve to the current figure.
 /// </summary>
 public void AddBezier(XPoint pt1, XPoint pt2, XPoint pt3, XPoint pt4)
 {
   this.items.Add(new XGraphicsPathItem(XGraphicsPathItemType.Beziers,
     new XPoint(pt1.X, pt1.Y), new XPoint(pt2.X, pt2.Y), new XPoint(pt3.X, pt3.Y), new XPoint(pt4.X, pt4.Y)));
   this.dirty = true;
   this.gdipPath.AddBezier(pt1.ToPointF(), pt2.ToPointF(), pt3.ToPointF(), pt4.ToPointF());
 }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a text string to this path.
        /// </summary>
        public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin,
            XStringFormat format)
        {
            try
            {
#if CORE
                DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString");
#endif
#if GDI
                if (family.GdiFamily == null)
                    throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name));

                PointF p = origin.ToPointF();
                p.Y += SimulateBaselineOffset(family, style, emSize, format);

                try
                {
                    Lock.EnterGdiPlus();
                    _gdipPath.AddString(s, family.GdiFamily, (int)style, (float)emSize, p, format.RealizeGdiStringFormat());
                }
                finally { Lock.ExitGdiPlus(); }
#endif
#if WPF
                if (family.WpfFamily == null)
                    throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name));
#if !SILVERLIGHT
                XFont font = new XFont(family.Name, emSize, style);

                double x = origin.X;
                double y = origin.Y;

                double lineSpace = font.GetHeight();
                double cyAscent = lineSpace * font.CellAscent / font.CellSpace;
                double cyDescent = lineSpace * font.CellDescent / font.CellSpace;

                Typeface typeface = FontHelper.CreateTypeface(family.WpfFamily, style);
                FormattedText formattedText = FontHelper.CreateFormattedText(s, typeface, emSize, WpfBrushes.Black);

                switch (format.Alignment)
                {
                    case XStringAlignment.Near:
                        // nothing to do, this is the default
                        //formattedText.TextAlignment = TextAlignment.Left;
                        break;

                    case XStringAlignment.Center:
                        formattedText.TextAlignment = TextAlignment.Center;
                        break;

                    case XStringAlignment.Far:
                        formattedText.TextAlignment = TextAlignment.Right;
                        break;
                }
                switch (format.LineAlignment)
                {
                    case XLineAlignment.Near:
                        //y += cyAscent;
                        break;

                    case XLineAlignment.Center:
                        // TODO use CapHeight. PDFlib also uses 3/4 of ascent
                        y += -lineSpace / 2; //-formattedText.Baseline + (cyAscent * 2 / 4);
                        break;

                    case XLineAlignment.Far:
                        y += -formattedText.Baseline - cyDescent;
                        break;

                    case XLineAlignment.BaseLine:
                        y -= formattedText.Baseline;
                        break;
                }

                Geometry geo = formattedText.BuildGeometry(new XPoint(x, y));
                _pathGeometry.AddGeometry(geo);
#else
                // AG-HACK
                throw new InvalidOperationException("Silverlight cannot create geometry of glyphs.");
                // TODO: Get the outline directly from the font.
#endif
#endif
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds  a line segment to current figure.
 /// </summary>
 public void AddLine(XPoint pt1, XPoint pt2)
 {
   this.items.Add(new XGraphicsPathItem(XGraphicsPathItemType.Lines, pt1, pt2));
   this.dirty = true;
   this.gdipPath.AddLine(pt1.ToPointF(), pt2.ToPointF());
 }
Exemplo n.º 5
0
    /// <summary>
    /// Adds a text string to this path.
    /// </summary>
    public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin, XStringFormat format)
    {
      try
      {
#if GDI
        // TODOWPF
        this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, origin.ToPointF(), format.RealizeGdiStringFormat());
#endif
#if WPF
        Typeface typeface = FontHelper.CreateTypeface(family, style);
        FormattedText ft = new FormattedText(s, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize,
          System.Windows.Media.Brushes.Black);
        Geometry geo = ft.BuildGeometry(origin);
        this.pathGeometry.AddGeometry(geo);
#endif
      }
      catch { }
    }