ToDeviceValue() 공개 메소드

Converts the current unit to one that can be used at render time.
public ToDeviceValue ( ISvgRenderer renderer, UnitRenderingType renderType, SvgElement owner ) : float
renderer ISvgRenderer
renderType UnitRenderingType
owner SvgElement
리턴 float
예제 #1
0
파일: SvgText.cs 프로젝트: messani/SVG
        private void DrawString(GraphicsPath path, SvgUnit x, SvgUnit y, SvgUnit dx, SvgUnit dy, Font font, float fontSize, string text)
        {
            PointF location = PointF.Empty;
            SizeF  stringBounds;

            lock (_stringMeasure)
            {
                stringBounds = _stringMeasure.MeasureString(text, font);
            }

            float xToDevice = x.ToDeviceValue(this) + dx.ToDeviceValue(this);
            float yToDevice = y.ToDeviceValue(this, true) + dy.ToDeviceValue(this, true);

            // Minus FontSize because the x/y coords mark the bottom left, not bottom top.
            switch (this.TextAnchor)
            {
            case SvgTextAnchor.Start:
                location = new PointF(xToDevice, yToDevice - stringBounds.Height);
                break;

            case SvgTextAnchor.Middle:
                location = new PointF(xToDevice - (stringBounds.Width / 2), yToDevice - stringBounds.Height);
                break;

            case SvgTextAnchor.End:
                location = new PointF(xToDevice - stringBounds.Width, yToDevice - stringBounds.Height);
                break;
            }

            // No way to do letter-spacing or word-spacing, so do manually
            if (this.LetterSpacing.Value > 0.0f || this.WordSpacing.Value > 0.0f)
            {
                // Cut up into words, or just leave as required
                string[] words         = (this.WordSpacing.Value > 0.0f) ? text.Split(' ') : new string[] { text };
                float    wordSpacing   = this.WordSpacing.ToDeviceValue(this);
                float    letterSpacing = this.LetterSpacing.ToDeviceValue(this);
                float    start         = this.X.ToDeviceValue(this);

                foreach (string word in words)
                {
                    // Only do if there is line spacing, just write the word otherwise
                    if (this.LetterSpacing.Value > 0.0f)
                    {
                        char[] characters = word.ToCharArray();
                        foreach (char currentCharacter in characters)
                        {
                            path.AddString(currentCharacter.ToString(), new FontFamily(this._fontFamily), (int)font.Style, fontSize, location, StringFormat.GenericTypographic);
                            location = new PointF(path.GetBounds().Width + start + letterSpacing, location.Y);
                        }
                    }
                    else
                    {
                        path.AddString(word, new FontFamily(this._fontFamily), (int)font.Style, fontSize, location, StringFormat.GenericTypographic);
                    }

                    // Move the location of the word to be written along
                    location = new PointF(path.GetBounds().Width + start + wordSpacing, location.Y);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(text))
                {
                    path.AddString(text, new FontFamily(this._fontFamily), (int)font.Style, fontSize, location, StringFormat.GenericTypographic);
                }
            }
        }
예제 #2
0
파일: SvgUnit.cs 프로젝트: thedeveus/SVG
 public static System.Drawing.PointF GetDevicePointOffset(SvgUnit x, SvgUnit y, ISvgRenderer renderer, SvgElement owner)
 {
     return(new System.Drawing.PointF(x.ToDeviceValue(renderer, UnitRenderingType.HorizontalOffset, owner),
                                      y.ToDeviceValue(renderer, UnitRenderingType.VerticalOffset, owner)));
 }
예제 #3
0
파일: SvgUnit.cs 프로젝트: thedeveus/SVG
 public static System.Drawing.SizeF GetDeviceSize(SvgUnit width, SvgUnit height, ISvgRenderer renderer, SvgElement owner)
 {
     return(new System.Drawing.SizeF(width.ToDeviceValue(renderer, UnitRenderingType.HorizontalOffset, owner),
                                     height.ToDeviceValue(renderer, UnitRenderingType.VerticalOffset, owner)));
 }
예제 #4
0
파일: SvgUnit.cs 프로젝트: vvvv/SVG
 public static System.Drawing.SizeF GetDeviceSize(SvgUnit width, SvgUnit height, ISvgRenderer renderer, SvgElement owner)
 {
     return new System.Drawing.SizeF(width.ToDeviceValue(renderer, UnitRenderingType.HorizontalOffset, owner),
                                     height.ToDeviceValue(renderer, UnitRenderingType.VerticalOffset, owner));
 }
예제 #5
0
파일: SvgUnit.cs 프로젝트: vvvv/SVG
 public static System.Drawing.PointF GetDevicePointOffset(SvgUnit x, SvgUnit y, ISvgRenderer renderer, SvgElement owner)
 {
     return new System.Drawing.PointF(x.ToDeviceValue(renderer, UnitRenderingType.HorizontalOffset, owner),
                                      y.ToDeviceValue(renderer, UnitRenderingType.VerticalOffset, owner));
 }
예제 #6
0
        /// <summary>
        /// Applies the required transforms to <see cref="SvgRenderer"/>.
        /// </summary>
        /// <param name="renderer">The <see cref="SvgRenderer"/> to be transformed.</param>
        protected internal override bool PushTransforms(SvgRenderer renderer)
        {
            if (!base.PushTransforms(renderer))
            {
                return(false);
            }

            if (!this.ViewBox.Equals(SvgViewBox.Empty))
            {
                var width  = this.Width.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this);
                var height = this.Height.ToDeviceValue(renderer, UnitRenderingType.Vertical, this);

                var fScaleX = width / this.ViewBox.Width;
                var fScaleY = height / this.ViewBox.Height;
                var fMinX   = -this.ViewBox.MinX;
                var fMinY   = -this.ViewBox.MinY;

                if (AspectRatio.Align != SvgPreserveAspectRatio.none)
                {
                    if (AspectRatio.Slice)
                    {
                        fScaleX = Math.Max(fScaleX, fScaleY);
                        fScaleY = Math.Max(fScaleX, fScaleY);
                    }
                    else
                    {
                        fScaleX = Math.Min(fScaleX, fScaleY);
                        fScaleY = Math.Min(fScaleX, fScaleY);
                    }
                    float fViewMidX = (this.ViewBox.Width / 2) * fScaleX;
                    float fViewMidY = (this.ViewBox.Height / 2) * fScaleY;
                    float fMidX     = width / 2;
                    float fMidY     = height / 2;

                    switch (AspectRatio.Align)
                    {
                    case SvgPreserveAspectRatio.xMinYMin:
                        break;

                    case SvgPreserveAspectRatio.xMidYMin:
                        fMinX += fMidX - fViewMidX;
                        break;

                    case SvgPreserveAspectRatio.xMaxYMin:
                        fMinX += width - this.ViewBox.Width * fScaleX;
                        break;

                    case SvgPreserveAspectRatio.xMinYMid:
                        fMinY += fMidY - fViewMidY;
                        break;

                    case SvgPreserveAspectRatio.xMidYMid:
                        fMinX += fMidX - fViewMidX;
                        fMinY += fMidY - fViewMidY;
                        break;

                    case SvgPreserveAspectRatio.xMaxYMid:
                        fMinX += width - this.ViewBox.Width * fScaleX;
                        fMinY += fMidY - fViewMidY;
                        break;

                    case SvgPreserveAspectRatio.xMinYMax:
                        fMinY += height - this.ViewBox.Height * fScaleY;
                        break;

                    case SvgPreserveAspectRatio.xMidYMax:
                        fMinX += fMidX - fViewMidX;
                        fMinY += height - this.ViewBox.Height * fScaleY;
                        break;

                    case SvgPreserveAspectRatio.xMaxYMax:
                        fMinX += width - this.ViewBox.Width * fScaleX;
                        fMinY += height - this.ViewBox.Height * fScaleY;
                        break;

                    default:
                        break;
                    }
                }

                var x = _x.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this);
                var y = _y.ToDeviceValue(renderer, UnitRenderingType.Vertical, this);

                renderer.AddClip(new Region(new RectangleF(x, y, width, height)));
                renderer.ScaleTransform(fScaleX, fScaleY, MatrixOrder.Prepend);
                renderer.TranslateTransform(x, y);
                renderer.TranslateTransform(fMinX, fMinY);
            }

            return(true);
        }
예제 #7
0
파일: SvgUnit.cs 프로젝트: AtomCrafty/SVG
 public static PointF GetDevicePoint(SvgUnit x, SvgUnit y, ISvgRenderer renderer, SvgElement owner)
 {
     return(new PointF(x.ToDeviceValue(renderer, UnitRenderingType.Horizontal, owner),
                       y.ToDeviceValue(renderer, UnitRenderingType.Vertical, owner)));
 }
예제 #8
0
파일: SvgUnit.cs 프로젝트: SoReinhard/SVG
 public static Vector2 GetDevicePointOffset(SvgUnit x, SvgUnit y, ISvgRenderer renderer, SvgElement owner)
 {
     return(new Vector2(x.ToDeviceValue(renderer, UnitRenderingType.HorizontalOffset, owner),
                        y.ToDeviceValue(renderer, UnitRenderingType.VerticalOffset, owner)));
 }