Пример #1
0
        protected override bool ProcessMarkupHandler(ProjectLayoutElement zElement, FormattedTextData zData, FormattedTextProcessData zProcessData, Graphics zGraphics)
        {
            m_zFontBrush  = zProcessData.FontBrush;
            m_zFont       = zProcessData.Font;
            m_fFontHeight = zProcessData.FontHeight;
            m_fXOffset    = zProcessData.CurrentXOffset;
            m_fYOffset    = zProcessData.CurrentYOffset;

            LineNumber = zProcessData.CurrentLine;

            m_fFontOutlineSize = m_zFont.Size;

            // TODO: stop recalculating this, store it in the processData
            if (0 != zElement.outlinethickness)
            {
                switch (m_zFont.Unit)
                {
                case GraphicsUnit.Point:
                    m_fFontOutlineSize = zGraphics.DpiY * (m_zFont.Size / 72f);
                    break;

                default:
                    Logger.AddLogLine("This font is using the Unit: {0} (not currently supported)".FormatString(m_zFont.Unit.ToString()));
                    break;
                }
            }

            m_rectMeasuredRectangle = MeasureDisplayStringWidth(zGraphics, m_sVariable, m_zFont);

            var fMeasuredWidth = m_rectMeasuredRectangle.Width;

            var fMeasuredHeight = Math.Max(m_rectMeasuredRectangle.Height, m_fFontHeight);

            if (zProcessData.IsXPositionOutsideBounds(zProcessData.CurrentX + fMeasuredWidth))
            {
                zProcessData.MoveToNextLine(zElement);
            }

            TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, fMeasuredWidth, fMeasuredHeight);

            zProcessData.CurrentX += fMeasuredWidth;

            return(true);
        }
Пример #2
0
        protected override bool ProcessMarkupHandler(ProjectLayoutElement zElement, FormattedTextData zData, FormattedTextProcessData zProcessData, Graphics zGraphics)
        {
            m_fXOffset = zProcessData.CurrentXOffset;
            m_fYOffset = zProcessData.CurrentYOffset;

            var arrayComponents = m_sVariable.Split(new char[] { ';' });

            if (1 > arrayComponents.Length)
            {
                return(false);
            }

            int nXPush;

            if (!int.TryParse(arrayComponents[0], out nXPush))
            {
                return(false);
            }

            var nYPush = 0;

            if (2 <= arrayComponents.Length)
            {
                if (!int.TryParse(arrayComponents[1], out nYPush))
                {
                    return(false);
                }
            }

            TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY,
                                        Math.Max(0, nXPush),
                                        Math.Max(0, nYPush));

            zProcessData.CurrentX += nXPush;
            zProcessData.CurrentY += nYPush;

            if (zProcessData.IsXPositionOutsideBounds(zProcessData.CurrentX))
            {
                zProcessData.MoveToNextLine(zElement);
            }

            return(true);
        }
Пример #3
0
        protected override bool ProcessMarkupHandler(ProjectLayoutElement zElement, FormattedTextData zData, FormattedTextProcessData zProcessData, Graphics zGraphics)
        {
            var arrayComponents = m_sVariable.Split(new char[] { ';' });

            if (1 > arrayComponents.Length)
            {
                return(false);
            }
            LineNumber = zProcessData.CurrentLine;

            m_sImageFile = arrayComponents[0];
            m_colorImage = zProcessData.ImageColor;

            var zBmp = LoadImage(zElement);

            if (null == zBmp ||
                zBmp.Width == 0 ||
                zBmp.Height == 0)
            {
                return(false);
            }

            var fLineHeightPercent = -1f;

            // SOOOOO much duplication
            switch (arrayComponents.Length)
            {
            case 1:     // <img=[filename]>
                fLineHeightPercent = 1.0f;
                TargetRect         = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                break;

            case 2:     // <img=[filename];[percent]>
                ParseUtil.ParseFloat(arrayComponents[1], out fLineHeightPercent);
                TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                break;

            case 3:     // <img=[filename];[xoffset];[yoffset]>
                if (ParseUtil.ParseFloat(arrayComponents[1], out m_fXOffset) &&
                    ParseUtil.ParseFloat(arrayComponents[2], out m_fYOffset))
                {
                    TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                }
                break;

            case 4:     // <img=[filename];[percent];[xoffset];[yoffset]>
                ParseUtil.ParseFloat(arrayComponents[1], out fLineHeightPercent);
                if (ParseUtil.ParseFloat(arrayComponents[2], out m_fXOffset) &&
                    ParseUtil.ParseFloat(arrayComponents[3], out m_fYOffset))
                {
                    TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                }
                break;

            case 5:     // <img=[filename];[xoffset];[yoffset];[width];[height]>
            {
                int nWidth;
                int nHeight;
                if (ParseUtil.ParseFloat(arrayComponents[1], out m_fXOffset) &&
                    ParseUtil.ParseFloat(arrayComponents[2], out m_fYOffset) &&
                    int.TryParse(arrayComponents[3], out nWidth) &&
                    int.TryParse(arrayComponents[4], out nHeight))
                {
                    TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, nWidth, nHeight);
                }
            }
            break;
            }

            if (TargetRect == RectangleF.Empty)
            {
                return(false);
            }

            m_fXOffset += zProcessData.CurrentXOffset;
            m_fYOffset += zProcessData.CurrentYOffset;

            var fAspectRatio = (float)zBmp.Width / (float)zBmp.Height;

            if (-1f != fLineHeightPercent)
            {
                var fNewHeight = fLineHeightPercent * (zProcessData.FontHeight == 0f ? 1f : (float)zProcessData.FontHeight);
                var fNewWidth  = fNewHeight * fAspectRatio;
                TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, fNewWidth, fNewHeight);
            }

            // newline eval
            if (zProcessData.IsXPositionOutsideBounds(TargetRect.X + TargetRect.Width))
            {
                zProcessData.MoveToNextLine(zElement);
                TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, TargetRect.Width, TargetRect.Height);
            }

            // cap off excessively wide images
            if (zProcessData.IsXPositionOutsideBounds(TargetRect.X + TargetRect.Width))
            {
                var fNewHeight = zProcessData.GetMaxLineWidth() / fAspectRatio;
                TargetRect = new RectangleF(TargetRect.X, TargetRect.Y, zElement.width, fNewHeight);
            }

            // Center the image on the line based on font height or line height (todo figure out which...)
            TargetRect = new RectangleF(TargetRect.X,
                                        TargetRect.Y + (((float)zProcessData.FontHeight - (float)TargetRect.Height) / 2f), TargetRect.Width, TargetRect.Height);

            zProcessData.CurrentX += TargetRect.Width;

            return(true);
        }