Beispiel #1
0
        public string ProcessInlineShape(IShapeRenderer zShapeRenderer, Graphics zGraphics, ProjectLayoutElement zElement, string sInput)
        {
            var   zExtendedMatch = regexShapeExtendedBG.Match(sInput);
            Match zMatch         = null;

            if (!zExtendedMatch.Success)
            {
                zMatch = regexShapeBG.Match(sInput);
                if (!zMatch.Success)
                {
                    return(sInput);
                }
            }

            var sToReplace = String.Empty;
            int nXOffset = 0, nYOffset = 0;

            var zBgShapeElement = new ProjectLayoutElement(Guid.NewGuid().ToString());

            if (zExtendedMatch.Success)
            {
                nXOffset                         = ParseUtil.ParseDefault(zExtendedMatch.Groups[6].Value, 0);
                nYOffset                         = ParseUtil.ParseDefault(zExtendedMatch.Groups[8].Value, 0);
                zBgShapeElement.x                = zElement.x;
                zBgShapeElement.y                = zElement.y;
                zBgShapeElement.width            = zElement.width + ParseUtil.ParseDefault(zExtendedMatch.Groups[10].Value, 0);
                zBgShapeElement.height           = zElement.height + ParseUtil.ParseDefault(zExtendedMatch.Groups[12].Value, 0);
                zBgShapeElement.outlinethickness = ParseUtil.ParseDefault(zExtendedMatch.Groups[14].Value, 0);
                zBgShapeElement.outlinecolor     = zExtendedMatch.Groups[16].Value;
                zBgShapeElement.elementcolor     = zExtendedMatch.Groups[4].Value;
                zBgShapeElement.variable         = zExtendedMatch.Groups[2].Value;
                zBgShapeElement.type             = ElementType.Shape.ToString();
                sToReplace                       = zExtendedMatch.Groups[0].Value;
            }
            else if (zMatch.Success)
            {
                zBgShapeElement.x            = zElement.x;
                zBgShapeElement.y            = zElement.y;
                zBgShapeElement.width        = zElement.width;
                zBgShapeElement.height       = zElement.height;
                zBgShapeElement.elementcolor = zMatch.Groups[4].Value;
                zBgShapeElement.variable     = zMatch.Groups[2].Value;
                zBgShapeElement.type         = ElementType.Shape.ToString();
                sToReplace = zMatch.Groups[0].Value;
            }

            zBgShapeElement.InitializeTranslatedFields();
            zBgShapeElement.opacity = zBgShapeElement.GetElementColor().A;

            zShapeRenderer.HandleShapeRender(zGraphics, zBgShapeElement.variable, zBgShapeElement, nXOffset, nYOffset);

            return(sInput.Replace(sToReplace, string.Empty));
        }
Beispiel #2
0
        public string ProcessInlineBackgroundGraphic(IDrawGraphic zDrawGraphic, Graphics zGraphics, ProjectLayoutElement zElement, string sInput)
        {
            var   zExtendedMatch = regexGraphicExtendedBG.Match(sInput);
            Match zMatch         = null;

            if (!zExtendedMatch.Success)
            {
                zMatch = regexGraphicBG.Match(sInput);
                if (!zMatch.Success)
                {
                    return(sInput);
                }
            }

            var sToReplace = String.Empty;

            int[] arrayReplaceIndcies = null;
            var   zBgGraphicElement   = new ProjectLayoutElement(Guid.NewGuid().ToString());
            var   nXOffset            = 0;
            var   nYOffset            = 0;

            if (zExtendedMatch.Success)
            {
                nXOffset = ParseUtil.ParseDefault(zExtendedMatch.Groups[4].Value, 0);
                nYOffset = ParseUtil.ParseDefault(zExtendedMatch.Groups[6].Value, 0);
                zBgGraphicElement.width           = zElement.width + ParseUtil.ParseDefault(zExtendedMatch.Groups[8].Value, 0);
                zBgGraphicElement.height          = zElement.height + ParseUtil.ParseDefault(zExtendedMatch.Groups[10].Value, 0);
                zBgGraphicElement.opacity         = zElement.opacity;
                zBgGraphicElement.lockaspect      = ParseUtil.ParseDefault(zExtendedMatch.Groups[12].Value, false);
                zBgGraphicElement.tilesize        = zExtendedMatch.Groups[14].Value;
                zBgGraphicElement.horizontalalign = ParseUtil.ParseDefault(zExtendedMatch.Groups[16].Value, 0);
                zBgGraphicElement.verticalalign   = ParseUtil.ParseDefault(zExtendedMatch.Groups[18].Value, 0);
                zBgGraphicElement.variable        = zExtendedMatch.Groups[2].Value;
                zBgGraphicElement.type            = ElementType.Graphic.ToString();
                sToReplace = zExtendedMatch.Groups[0].Value;
            }
            else if (zMatch.Success)
            {
                zBgGraphicElement.width    = zElement.width;
                zBgGraphicElement.height   = zElement.height;
                zBgGraphicElement.opacity  = zElement.opacity;
                zBgGraphicElement.variable = zMatch.Groups[2].Value;
                zBgGraphicElement.type     = ElementType.Graphic.ToString();
                sToReplace = zMatch.Groups[0].Value;
            }

            zDrawGraphic.DrawGraphicFile(zGraphics, zBgGraphicElement.variable, zBgGraphicElement, nXOffset, nYOffset);

            return(sInput.Replace(sToReplace, string.Empty));
        }
        public void DrawGraphicFile(Graphics zGraphics, string sFile, ProjectLayoutElement zElement, int nXGraphicOffset = 0, int nYGraphicOffset = 0)
        {
            var sPath = sFile;

            if (string.IsNullOrEmpty(sFile) ||
                sPath.Equals("none", StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }
            if (sPath.StartsWith(APPLICATION_FOLDER_MARKER))
            {
                sPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                     sPath.Replace(APPLICATION_FOLDER_MARKER, string.Empty));
            }
            if (!File.Exists(sPath))
            {
                sPath = ProjectManager.Instance.ProjectPath + sFile;
            }
            if (!File.Exists(sPath))
            {
                IssueManager.Instance.FireAddIssueEvent("Image file not found: " + sFile);
                return;
            }

            var zBmp = ImageCache.LoadCustomImageFromCache(sPath, zElement);

            var nWidth  = zElement.width;
            var nHeight = zElement.height;

            // TODO: sub processor methods (at a minimum)

            if (!string.IsNullOrWhiteSpace(zElement.tilesize) &&
                zElement.tilesize.Trim() != "-")
            {
                var zMatch = regexImageTile.Match(zElement.tilesize);
                if (zMatch.Success)
                {
                    var nTileWidth  = Math.Max(-1, ParseUtil.ParseDefault(zMatch.Groups[1].Value, -1));
                    var nTileHeight = Math.Max(-1, ParseUtil.ParseDefault(zMatch.Groups[3].Value, -1));
                    GetAspectRatioHeight(zBmp, nTileWidth, nTileHeight, out nTileWidth, out nTileHeight);
                    // paranoia...
                    nTileWidth  = Math.Max(1, nTileWidth);
                    nTileHeight = Math.Max(1, nTileHeight);

                    zBmp = ImageCache.LoadCustomImageFromCache(sFile, zElement, nTileWidth, nTileHeight);
                }
                using (var zTextureBrush = new TextureBrush(zBmp, WrapMode.Tile))
                {
                    // backup the transform
                    var zOriginalTransform = zGraphics.Transform;
                    // need to translate so the tiling starts with a full image if offset
                    zGraphics.TranslateTransform(nXGraphicOffset, nYGraphicOffset);
                    zGraphics.FillRectangle(zTextureBrush, 0, 0, nWidth, nHeight);
                    zGraphics.Transform = zOriginalTransform;
                }
                return;
            }

            if (zElement.keeporiginalsize)
            {
                DrawGraphicOriginalSize(zGraphics, zBmp, zElement);
                return;
            }

            if (zElement.lockaspect)
            {
                GetSizeFromAspectRatio((float)zBmp.Tag, nWidth, nHeight, out nWidth, out nHeight);
            }

            var nX = 0;
            var nY = 0;

            // standard alignment adjustment
            UpdateAlignmentValue(zElement.GetHorizontalAlignment(), ref nX, zElement.width, nWidth);
            UpdateAlignmentValue(zElement.GetVerticalAlignment(), ref nY, zElement.height, nHeight);
            zGraphics.DrawImage(zBmp, nX + nXGraphicOffset, nY + nYGraphicOffset, nWidth, nHeight);
        }