Ejemplo n.º 1
0
        public override bool Render(ProjectLayoutElement zElement, Graphics zGraphics)
        {
            var zFormat = new StringFormat
            {
                Alignment     = StringAlignment.Near,
                LineAlignment = StringAlignment.Near,
            };

            // indicate any text being cut off
            if (zElement.height < TargetRect.Y + TargetRect.Height)
            {
                // completely end the draw
                return(false);
            }

            // NOTE: when rendering there is no need for a target rect as that information has already been processed
            float targetX = TargetRect.X + m_fXOffset;
            float targetY = TargetRect.Y + m_fYOffset;

            // draw border (debugging)
            if (CardMakerInstance.DrawFormattedTextBorder)
            {
                zGraphics.DrawRectangle(Pens.Green, targetX, targetY, TargetRect.Width, TargetRect.Height);
            }

            // when a string is measured there is a bit of an offset to where it renders (into the target rect a few pixels right ---->)
            targetX -= m_rectMeasuredRectangle.X;

            if (0 == zElement.outlinethickness)
            {
                try
                {
                    zGraphics.DrawString(m_sVariable, m_zFont, m_zFontBrush, targetX, targetY, zFormat);
                }
                catch (Exception)
                {
                    Logger.AddLogLine("Unable to render text (font issue?)");
                }
            }
            else
            {
                // prepare to draw text
                var zPath = new GraphicsPath();

                try
                {
                    zPath.AddString(m_sVariable, m_zFont.FontFamily, (int)m_zFont.Style, m_fFontOutlineSize,
                                    new PointF(targetX, targetY), zFormat);

                    DrawItem.DrawOutline(zElement, zGraphics, zPath);
                }
                catch (Exception)
                {
                    Logger.AddLogLine("Unable to render text (font issue?)");
                }
                // fill in the outline
                zGraphics.FillPath(m_zFontBrush, zPath);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static void HandleShapeRender(Graphics zGraphics, string sShapeInfo, ProjectLayoutElement zElement)
        {
            if (s_regexShapes.IsMatch(sShapeInfo))
            {
                var           zMatch     = s_regexShapes.Match(sShapeInfo);
                ShapeInfo     zInfo      = null;
                var           bParse     = false;
                var           arraySplit = zMatch.Groups[3].ToString().Split(new char[] { ';' });
                var           sShapeName = arraySplit[(int)AbstractShape.ShapeInformationIndex.Name];
                AbstractShape zShape;
                if (s_dictionaryShapeByName.TryGetValue(sShapeName, out zShape))
                {
                    // allow any shapes with extended settings to read in the values (ShapeInformationIndex extension)
                    zShape.InitializeItem(sShapeInfo);

                    if ((int)AbstractShape.ShapeInformationIndex.BasicShapeInformation < arraySplit.Length)
                    {
                        int nThickness;
                        var nOverrideWidth  = int.MinValue;
                        var nOverrideHeight = int.MinValue;
                        bParse = int.TryParse(arraySplit[(int)AbstractShape.ShapeInformationIndex.Thickness], out nThickness);
                        if (!arraySplit[(int)AbstractShape.ShapeInformationIndex.OverrideWidth].Equals(AbstractShape.NO_SIZE_OVERRIDE))
                        {
                            bParse &= int.TryParse(arraySplit[(int)AbstractShape.ShapeInformationIndex.OverrideWidth], out nOverrideWidth);
                        }
                        if (!arraySplit[(int)AbstractShape.ShapeInformationIndex.OverrideHeight].Equals(AbstractShape.NO_SIZE_OVERRIDE))
                        {
                            bParse &= int.TryParse(arraySplit[(int)AbstractShape.ShapeInformationIndex.OverrideHeight], out nOverrideHeight);
                        }
                        zInfo = new ShapeInfo(nThickness, nOverrideWidth, nOverrideHeight, arraySplit);
                    }
                    if (!bParse)
                    {
                        return; // invalid (error?)
                    }

                    var previousTransform = zGraphics.Transform;
                    var zPath             = new GraphicsPath();

                    var targetRect = new Rectangle(0, 0, zElement.width - 1, zElement.height - 1);

                    // internally int.MinValue indicates no override
                    if (int.MinValue != zInfo.OverrideWidth || int.MinValue != zInfo.OverrideHeight)
                    {
                        var nOverrideWidth  = int.MinValue == zInfo.OverrideWidth ? zElement.width : zInfo.OverrideWidth;
                        var nOverrideHeight = int.MinValue == zInfo.OverrideHeight ? zElement.height : zInfo.OverrideHeight;

                        if (0 == nOverrideWidth || 0 == nOverrideHeight)
                        {
                            // nothing to draw
                            return;
                        }
                        targetRect = GetZeroRectangle(nOverrideWidth, nOverrideHeight);
                        zGraphics.TranslateTransform(targetRect.X, targetRect.Y);
                        targetRect = new Rectangle(0, 0, Math.Abs(nOverrideWidth), Math.Abs(nOverrideHeight));
                    }

                    zShape.DrawShape(zPath, targetRect, zInfo);
                    DrawItem.DrawOutline(zElement, zGraphics, zPath);

                    if (0 == zInfo.Thickness)
                    {
                        var zShapeBrush = 255 != zElement.opacity
                            ? new SolidBrush(Color.FromArgb(zElement.opacity, zElement.GetElementColor()))
                            : new SolidBrush(zElement.GetElementColor());
                        zGraphics.FillPath(zShapeBrush, zPath);
                    }
                    else
                    {
                        var zShapePen = 255 != zElement.opacity
                            ? new Pen(Color.FromArgb(zElement.opacity, zElement.GetElementColor()), zInfo.Thickness)
                            : new Pen(zElement.GetElementColor(), zInfo.Thickness);
                        zGraphics.DrawPath(zShapePen, zPath);
                    }
                    zGraphics.Transform = previousTransform;
                }
            }
        }