コード例 #1
0
        static public void DrawMorseText(Graphics g, GraphicsPath gp2, ref PointF pos, string sSplit, Font newFont, FontStyle fontStyle, StringAlignment stringAlign, RectangleF newLabelBounds)
        {
            string sText       = TextExpression.GetTextWithoutTag(sSplit);
            SizeF  stringfSize = g.MeasureString(sText, newFont);
            var    format      = new StringFormat {
                Alignment = StringAlignment.Near
            };

            PointF posText = new PointF(pos.X, pos.Y);

            float fHeightUsed      = stringfSize.Height;
            float fHeightUsedMorse = 0.0F;
            float fWidthUsed       = stringfSize.Width;
            Font  newFontMorse     = new Font(new FontFamily("CGXAERO-MorseCode"), TextExpression.GetSizeFromTag(sSplit, newFont.SizeInPoints));
            SizeF fSizeMorse       = g.MeasureString(sText, newFontMorse);
            float fMorsePos        = pos.Y;

            fWidthUsed += TextExpression.GetLargerMorseWidth(g, sText, TextExpression.GetSizeFromTag(sSplit, newFont.SizeInPoints));
            if (stringAlign == StringAlignment.Center)
            {
                posText = new PointF((pos.X + newLabelBounds.Width / 2) - (fWidthUsed / 2) + 1, pos.Y);
            }
            if (stringAlign == StringAlignment.Far)
            {
                posText = new PointF((pos.X + newLabelBounds.Width) - (fWidthUsed + 3), pos.Y);
            }

            PointF posMorse = new PointF(posText.X + stringfSize.Width, posText.Y);

            foreach (char c in sText)
            {
                //gp2.AddString(c.ToString(), new FontFamily("CGXAERO-MorseCode"), (int)fontStyle, newFont.Size * g.DpiY / 72F, posMorse, format);
                g.DrawString(c.ToString(), newFontMorse, new SolidBrush(Color.Black), posMorse, format);
                posMorse          = new PointF(posMorse.X, posMorse.Y + fSizeMorse.Height);
                fHeightUsedMorse += fSizeMorse.Height;
            }

            float fLargerHighOffset = fHeightUsed;

            if (fHeightUsedMorse > fHeightUsed)
            {
                posText           = new PointF(posText.X, posText.Y + (fHeightUsedMorse / 2) - stringfSize.Height / 2);
                fLargerHighOffset = fHeightUsedMorse;
            }


            //gp2.AddString(sText + " ", newFont.FontFamily, (int)fontStyle, newFont.Size * g.DpiY / 72F, posText, format);
            g.DrawString(sText + " ", newFont, new SolidBrush(Color.Black), posText, format);

            pos.Y += fLargerHighOffset;
        }
コード例 #2
0
        private void PanelPreview_Paint(object sender, PaintEventArgs e)
        {
            string sResult = "";

            if (IsComplexExpression(Expression))
            {
                Expression = TB_Advanced.Text;
                sResult    = Compute(Expression);
                sResult    = Python.Script.Evaluate(sResult);
            }
            else
            {
                Expression = TB_Simple.Text;
                sResult    = Compute(Expression);
            }
            if (string.IsNullOrEmpty(sResult))
            {
                return;
            }


            var g = e.Graphics;
            var p = sender as Panel;

            var format = new StringFormat {
                Alignment = StringAlignment.Near
            };
            Font       textFont    = new System.Drawing.Font("Arial", 10);
            RectangleF currentView = new RectangleF(PanelPreview.DisplayRectangle.X + 10, PanelPreview.DisplayRectangle.Y + 10, PanelPreview.DisplayRectangle.Width, PanelPreview.DisplayRectangle.Height);

            RectangleF labelBounds = TextExpression.GetComputedLabelBounds(g, sResult, textFont, format, currentView, 1.0F);

            RectangleF fTitleClip = new RectangleF();

            string[] sSplitted = sResult.Split('\n');
            PointF   pos       = new PointF(labelBounds.X, labelBounds.Y);

            foreach (string sSplit in sSplitted)
            {
                using (var gp2 = new GraphicsPath())
                {
                    FontStyle  fontStyle        = TextExpression.GetFontFromTag(sSplit);
                    FontFamily fontFamily       = textFont.FontFamily;
                    FontFamily customFontFamily = null;
                    if (TextExpression.GetFontFamilyFromTag(sSplit, out customFontFamily))
                    {
                        fontFamily = customFontFamily;
                    }
                    Font  newFont   = new Font(fontFamily, TextExpression.GetSizeFromTag(sSplit, textFont.SizeInPoints));
                    Color textColor = Color.Black;
                    Color tempColor = Color.Black;
                    if (TextExpression.GetColorFromTag(sSplit, out tempColor))
                    {
                        textColor = tempColor;
                    }
                    Bullet.style bulletStyle = Bullet.style.None;
                    bool         bDrawBullet = TextExpression.GetBulletStyle(sSplit, out bulletStyle);

                    string sTextWithoutTag = TextExpression.GetTextWithoutTag(sSplit);
                    SizeF  stringfSize     = g.MeasureString(sTextWithoutTag, newFont);

                    if (!TextExpression.IsMorse(sSplit))
                    {
                        PointF textPosition = new PointF(pos.X, pos.Y);

                        if (TextExpression.IsTitle(sSplit))
                        {
                            textPosition = new PointF((labelBounds.X + labelBounds.Width / 2) - (stringfSize.Width / 2), labelBounds.Y);

                            fTitleClip = new RectangleF(textPosition, stringfSize);
                            //gp2.AddString(sTextWithoutTag, newFont.FontFamily, (int)fontStyle, newFont.Size * g.DpiY / 72F, textPosition, format);
                            e.Graphics.DrawString(sTextWithoutTag, newFont, new SolidBrush(textColor), textPosition, format);

                            labelBounds = new RectangleF(labelBounds.X, labelBounds.Y + (stringfSize.Height / 2), labelBounds.Width, labelBounds.Height - (stringfSize.Height / 2));
                        }
                        else
                        {
                            //gp2.AddString(sTextWithoutTag, newFont.FontFamily, (int)fontStyle, newFont.Size * g.DpiY / 72F, textPosition, format);
                            if (bulletStyle == Bullet.style.Left || bulletStyle == Bullet.style.Both)
                            {
                                textPosition.X += (stringfSize.Height / 2);
                            }
                            e.Graphics.DrawString(sTextWithoutTag, newFont, new SolidBrush(textColor), textPosition, format);
                        }

                        // Draw a limit above the text if needed
                        TextExpression.DrawUpperScore(g, sSplit, textPosition, textColor, newFont, 1.0F);
                        TextExpression.DrawUnderScore(g, sSplit, textPosition, textColor, newFont, 1.0F);
                        if (bDrawBullet)
                        {
                            TextExpression.DrawBullet(g, textColor, bulletStyle, stringfSize, textPosition);
                        }

                        pos.Y += stringfSize.Height;
                    }
                    else
                    {
                        TextExpression.DrawMorseText(g, gp2, ref pos, sSplit, newFont, fontStyle, StringAlignment.Near, labelBounds);
                    }

                    // Draw a label
                    //g.FillPath(new SolidBrush(textColor), gp2);
                    gp2.Dispose();
                }
            }
            e.Graphics.DrawRectangle(new Pen(Color.Black), (int)labelBounds.X, (int)labelBounds.Y, (int)labelBounds.Width, (int)labelBounds.Height);
        }
コード例 #3
0
        /// <summary>
        /// Compute label bound considering the size of the texts, the font and the format
        /// </summary>
        static public RectangleF GetComputedLabelBoundsWithTitle(Graphics g, string labelText, Font textFont, StringFormat format, RectangleF labelBounds, float fRapport)
        {
            RectangleF newLabelBounds = new RectangleF(labelBounds.Location, labelBounds.Size);
            float      fWidth = 0.0F;
            float      fHeight = 0.0F;
            PointF     pos = new PointF(labelBounds.X, labelBounds.Y);
            bool       bTitled = false, bFirstLine = true;


            string[] sSplitted = labelText.Split('\n');
            foreach (string sSplit in sSplitted)
            {
                float      size             = TextExpression.GetSizeFromTag(sSplit, textFont.SizeInPoints);
                FontFamily fontFamily       = textFont.FontFamily;
                FontFamily customFontFamily = null;
                if (TextExpression.GetFontFamilyFromTag(sSplit, out customFontFamily))
                {
                    fontFamily = customFontFamily;
                }
                Font   newFont = new Font(fontFamily, size);
                string sText   = TextExpression.GetTextWithoutTag(sSplit);

                SizeF stringfSize = g.MeasureString(sText, newFont);

                if (!IsMorse(sSplit))
                {
                    if (fWidth < stringfSize.Width)
                    {
                        fWidth = stringfSize.Width;
                    }
                    fHeight += stringfSize.Height;

                    if ((!bTitled) && (bFirstLine))
                    {
                        if (sSplit.Contains("<title>") && sSplit.Contains("</title>"))
                        {
                            pos.Y   = pos.Y + ((stringfSize.Height / 2) * fRapport);
                            fHeight = fHeight - (stringfSize.Height / 2);
                        }
                        bTitled = true;
                    }
                }
                else
                {
                    fWidth += stringfSize.Width;
                    float fHeightUsed      = stringfSize.Height;
                    float fHeightUsedMorse = 0.0F;

                    float fLargerWidth = 0.0F;
                    Font  newFontMorse = new Font(new FontFamily("CGXAERO-MorseCode"), TextExpression.GetSizeFromTag(sSplit, textFont.SizeInPoints));
                    foreach (char c in sText)
                    {
                        SizeF fSizeMorse = g.MeasureString(c.ToString(), newFontMorse);
                        fHeightUsedMorse += fSizeMorse.Height;
                        if (fLargerWidth < fSizeMorse.Width)
                        {
                            fLargerWidth = fSizeMorse.Width;
                        }
                    }
                    fWidth += fLargerWidth + 1;

                    float fLargerPos = fHeightUsed;
                    if (fHeightUsedMorse > fHeightUsed)
                    {
                        fLargerPos = fHeightUsedMorse;
                    }

                    fHeight += fLargerPos;
                }
                bFirstLine = false;
            }
            newLabelBounds.Location = new PointF(pos.X, pos.Y);
            newLabelBounds.Size     = new SizeF(fWidth * fRapport + 10, fHeight * fRapport + 2);

            return(newLabelBounds);
        }
コード例 #4
0
        /// <summary>
        /// Compute label bound considering the size of the texts, the font and the format
        /// </summary>
        static public RectangleF GetComputedLabelBounds(Graphics g, string labelText, Font textFont, StringFormat format, RectangleF labelBounds, float fRapport)
        {
            RectangleF newLabelBounds = new RectangleF(labelBounds.Location, labelBounds.Size);
            float      fWidth         = 0.0F;
            float      fHeight        = 0.0F;

            string[] sSplitted = labelText.Split('\n');
            foreach (string sSplit in sSplitted)
            {
                float      size             = TextExpression.GetSizeFromTag(sSplit, textFont.SizeInPoints);
                FontFamily fontFamily       = textFont.FontFamily;
                FontFamily customFontFamily = null;
                if (TextExpression.GetFontFamilyFromTag(sSplit, out customFontFamily))
                {
                    fontFamily = customFontFamily;
                }
                Font   newFont     = new Font(fontFamily, size);
                string sText       = TextExpression.GetTextWithoutTag(sSplit);
                SizeF  stringfSize = g.MeasureString(sText, newFont);

                if (fWidth < stringfSize.Width)
                {
                    fWidth = stringfSize.Width;
                }
                if (!IsMorse(sSplit))
                {
                    fHeight += stringfSize.Height;
                }
                else
                {
                    if (fWidth < stringfSize.Width)
                    {
                        fWidth = stringfSize.Width;
                    }
                    float fHeightUsed      = stringfSize.Height;
                    float fHeightUsedMorse = 0.0F;

                    float fLargerWidth = 0.0F;
                    Font  newFontMorse = new Font(new FontFamily("CGXAERO-MorseCode"), TextExpression.GetSizeFromTag(sSplit, textFont.SizeInPoints));
                    foreach (char c in sText)
                    {
                        SizeF fSizeMorse = g.MeasureString(c.ToString(), newFontMorse);
                        fHeightUsedMorse += fSizeMorse.Height;
                        if (fLargerWidth < fSizeMorse.Width)
                        {
                            fLargerWidth = fSizeMorse.Width;
                        }
                    }
                    float fWidthMorse = stringfSize.Width + fLargerWidth + 1;
                    if (fWidth < fWidthMorse)
                    {
                        fWidth = fWidthMorse;
                    }

                    float fLargerPos = fHeightUsed;
                    if (fHeightUsedMorse > fHeightUsed)
                    {
                        fLargerPos = fHeightUsedMorse;
                    }

                    fHeight += fLargerPos;
                }
            }
            newLabelBounds.Size = new SizeF(fWidth * fRapport + 10, fHeight * fRapport + 2);

            return(newLabelBounds);
        }