Beispiel #1
0
 private void TranslateImage(float xDistance, float yDistance, AffineTransform t)
 {
     t.Translate(xDistance, yDistance);
     t.GetMatrix(matrix);
     if (fixedXPosition != null)
     {
         fixedXPosition += (float)t.GetTranslateX();
     }
     if (fixedYPosition != null)
     {
         fixedYPosition += (float)t.GetTranslateY();
     }
 }
Beispiel #2
0
        internal static MatrixFP ToMatrixFP(AffineTransform matrix)
        {
            if (matrix == null)
            {
                return(null);
            }
            if (matrix.IsIdentity())
            {
                return(MatrixFP.Identity);
            }

            MatrixFP matrixFP = new MatrixFP(SingleFP.FromDouble(matrix.GetScaleX()),
                                             SingleFP.FromDouble(matrix.GetScaleY()),
                                             SingleFP.FromDouble(matrix.GetShearX()),
                                             SingleFP.FromDouble(matrix.GetShearY()),
                                             SingleFP.FromDouble(matrix.GetTranslateX()),
                                             SingleFP.FromDouble(matrix.GetTranslateY()));

            return(matrixFP);
        }
Beispiel #3
0
 // transformation already happened in AbstractSvgNodeRenderer, so no need to do a transformation here
 /// <summary>Applies a transformation based on a viewBox for a given branch node.</summary>
 /// <param name="context">current svg draw context</param>
 internal virtual void ApplyViewBox(SvgDrawContext context)
 {
     if (this.attributesAndStyles != null && this.attributesAndStyles.ContainsKey(SvgConstants.Attributes.VIEWBOX
                                                                                  ))
     {
         //Parse aspect ratio related stuff
         String         viewBoxValues = attributesAndStyles.Get(SvgConstants.Attributes.VIEWBOX);
         IList <String> valueStrings  = SvgCssUtils.SplitValueList(viewBoxValues);
         float[]        values        = new float[valueStrings.Count];
         for (int i = 0; i < values.Length; i++)
         {
             values[i] = CssUtils.ParseAbsoluteLength(valueStrings[i]);
         }
         Rectangle currentViewPort     = context.GetCurrentViewPort();
         String[]  alignAndMeet        = RetrieveAlignAndMeet();
         String    align               = alignAndMeet[0];
         String    meetOrSlice         = alignAndMeet[1];
         float     scaleWidth          = currentViewPort.GetWidth() / values[2];
         float     scaleHeight         = currentViewPort.GetHeight() / values[3];
         bool      forceUniformScaling = !(SvgConstants.Values.NONE.Equals(align));
         if (forceUniformScaling)
         {
             //Scaling should preserve aspect ratio
             if (SvgConstants.Values.MEET.Equals(meetOrSlice))
             {
                 scaleWidth = Math.Min(scaleWidth, scaleHeight);
             }
             else
             {
                 scaleWidth = Math.Max(scaleWidth, scaleHeight);
             }
             scaleHeight = scaleWidth;
         }
         AffineTransform scale = AffineTransform.GetScaleInstance(scaleWidth, scaleHeight);
         float[]         scaledViewBoxValues = ScaleViewBoxValues(values, scaleWidth, scaleHeight);
         AffineTransform transform           = ProcessAspectRatioPosition(context, scaledViewBoxValues, align, scaleWidth, scaleHeight
                                                                          );
         if (!scale.IsIdentity())
         {
             context.GetCurrentCanvas().ConcatMatrix(scale);
             //Inverse scaling needs to be applied to viewport dimensions
             context.GetCurrentViewPort().SetWidth(currentViewPort.GetWidth() / scaleWidth).SetX(currentViewPort.GetX()
                                                                                                 / scaleWidth).SetHeight(currentViewPort.GetHeight() / scaleHeight).SetY(currentViewPort.GetY() / scaleHeight
                                                                                                                                                                         );
         }
         if (!transform.IsIdentity())
         {
             context.GetCurrentCanvas().ConcatMatrix(transform);
             //Apply inverse translation to viewport to make it line up nicely
             context.GetCurrentViewPort().SetX(currentViewPort.GetX() + -1 * (float)transform.GetTranslateX()).SetY(currentViewPort
                                                                                                                    .GetY() + -1 * (float)transform.GetTranslateY());
         }
     }
 }
Beispiel #4
0
        internal virtual void CalculateAndApplyViewBox(SvgDrawContext context, float[] values, Rectangle currentViewPort
                                                       )
        {
            String[] alignAndMeet        = RetrieveAlignAndMeet();
            String   align               = alignAndMeet[0];
            String   meetOrSlice         = alignAndMeet[1];
            float    scaleWidth          = currentViewPort.GetWidth() / values[2];
            float    scaleHeight         = currentViewPort.GetHeight() / values[3];
            bool     forceUniformScaling = !(SvgConstants.Values.NONE.Equals(align));

            if (forceUniformScaling)
            {
                //Scaling should preserve aspect ratio
                if (SvgConstants.Values.MEET.Equals(meetOrSlice))
                {
                    scaleWidth = Math.Min(scaleWidth, scaleHeight);
                }
                else
                {
                    scaleWidth = Math.Max(scaleWidth, scaleHeight);
                }
                scaleHeight = scaleWidth;
            }
            AffineTransform scale = AffineTransform.GetScaleInstance(scaleWidth, scaleHeight);

            float[]         scaledViewBoxValues = ScaleViewBoxValues(values, scaleWidth, scaleHeight);
            AffineTransform transform           = ProcessAspectRatioPosition(context, scaledViewBoxValues, align, scaleWidth, scaleHeight
                                                                             );

            if (!scale.IsIdentity())
            {
                context.GetCurrentCanvas().ConcatMatrix(scale);
                //Inverse scaling needs to be applied to viewport dimensions
                context.GetCurrentViewPort().SetWidth(currentViewPort.GetWidth() / scaleWidth).SetX(currentViewPort.GetX()
                                                                                                    / scaleWidth).SetHeight(currentViewPort.GetHeight() / scaleHeight).SetY(currentViewPort.GetY() / scaleHeight
                                                                                                                                                                            );
            }
            if (!transform.IsIdentity())
            {
                context.GetCurrentCanvas().ConcatMatrix(transform);
                //Apply inverse translation to viewport to make it line up nicely
                context.GetCurrentViewPort().SetX(currentViewPort.GetX() + -1 * (float)transform.GetTranslateX()).SetY(currentViewPort
                                                                                                                       .GetY() + -1 * (float)transform.GetTranslateY());
            }
        }