Esempio n. 1
0
        public Size MeasureString(MNPageContext context, string plainText, int width)
        {
            if (width < 0)
            {
                width = 5000;
            }
            if (!p_prevText.Equals(plainText) || (p_prevWidth != width) || drawWords == null || richLayout == null)
            {
                p_prevText = plainText;
                drawWords  = WordListFromString(plainText);
                Rectangle textBounds = new Rectangle(0, 0, width, 100);
                richLayout = RecalculateWordsLayout(context, textBounds);
                drawLines  = richLayout.Lines;
            }

            return(new Size(richLayout.rightX, richLayout.bottomY));
        }
Esempio n. 2
0
        public void DrawString(MNPageContext context, SMStatusLayout layout, string plainText, Rectangle textBounds, int nPage)
        {
            if (!p_prevText.Equals(plainText) || (p_prevWidth != textBounds.Width) || drawWords == null)
            {
                p_prevText = plainText;
                drawWords  = WordListFromString(plainText);
                richLayout = RecalculateWordsLayout(context, textBounds);
            }

            foreach (SMWordBase wt in drawWords)
            {
                if (wt.PageNo == nPage)
                {
                    wt.Paint(context, layout, textBounds.X, textBounds.Y);
                }
            }
        }
Esempio n. 3
0
        public Rectangle[] CalcRectangles(MNPageContext context, string plainText, Rectangle textBounds)
        {
            p_prevText = plainText;
            drawWords  = WordListFromString(plainText);
            richLayout = RecalculateWordsLayout(context, textBounds);
            drawLines  = richLayout.Lines;

            List <Rectangle> ra = new List <Rectangle>();

            foreach (SMWordBase wb in drawWords)
            {
                if (wb is SMWordText)
                {
                    ra.Add(new Rectangle((int)wb.rect.X, (int)wb.rect.Y, (int)wb.rect.Width, (int)wb.rect.Height));
                }
            }

            return(ra.ToArray <Rectangle>());
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="textBounds"></param>
        /// <param name="drawWords"></param>
        /// <param name="control"></param>
        /// <param name="RunningLine"></param>
        /// <param name="Columns">Value -1 means, that no paging is done, normaly columns are 1,2,3...</param>
        /// <param name="ColumnSeparatorWidth"></param>
        /// <param name="PageCount"></param>
        /// <returns></returns>
        public static SMRichLayout RecalculateWordsLayout(MNPageContext context, Rectangle textBounds, List <SMWordBase> drawWords, SMControl control, SMRunningLine RunningLine,
                                                          int Columns)
        {
            textBounds.X = 0;
            textBounds.Y = 0;
            float        lineY       = textBounds.Y;
            float        lineX       = textBounds.X;
            float        lineEnd     = textBounds.Right;
            float        lineHeight  = 0f;
            float        lineWidth   = textBounds.Width;
            float        columnWidth = textBounds.Width;
            int          lineNo      = 0;
            int          columnNo    = 0;
            int          pageNo      = 0;
            int          rightX      = textBounds.X;
            bool         writeLineNo = false;
            bool         isNewLine   = false;
            bool         isNewColumn = false;
            SMWordLine   currLine    = new SMWordLine();
            SMRichLayout richLayout  = new SMRichLayout();

            richLayout.Lines = new List <SMWordLine>();
            richLayout.Lines.Add(currLine);
            richLayout.DropablesCount = 0;
            //context.g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            if (Columns > 1)
            {
                columnWidth = textBounds.Width / Columns;
                lineWidth   = textBounds.Width / Columns - control.ContentPadding.Left - control.ContentPadding.Right;
                lineX       = textBounds.X + columnNo * columnWidth + control.ContentPadding.Left;
                lineEnd     = lineX + lineWidth;
            }
            else
            {
                columnWidth = textBounds.Width;
                lineWidth   = textBounds.Width - control.ContentPadding.Left - control.ContentPadding.Right;
                lineX       = textBounds.X + control.ContentPadding.Left;
                lineEnd     = lineX + lineWidth;
            }

            float bottom                = textBounds.Bottom;
            bool  isSpaceText           = false;
            int   startsWithParentheses = 0;
            bool  isNewPage             = false;

            // first placement of word tokens
            foreach (SMWordBase wt in drawWords)
            {
                isSpaceText           = false;
                writeLineNo           = true;
                isNewLine             = false;
                isNewColumn           = false;
                isNewPage             = false;
                startsWithParentheses = 0;
                if (wt is SMWordSpecial)
                {
                    SMWordSpecial spwt = (SMWordSpecial)wt;
                    if (spwt.Type == SMWordSpecialType.Newline)
                    {
                        isNewLine   = true;
                        writeLineNo = false;
                    }
                    else if (spwt.Type == SMWordSpecialType.NewColumn)
                    {
                        isNewLine   = false;
                        writeLineNo = false;
                        isNewColumn = true;
                    }
                    else if (spwt.Type == SMWordSpecialType.HorizontalLine)
                    {
                        wt.rect.Width  = lineEnd - lineX - 1;
                        wt.rect.Height = 20;
                    }
                    else if (spwt.Type == SMWordSpecialType.NewPage)
                    {
                        isNewPage   = true;
                        writeLineNo = false;
                    }
                }
                else if (wt is SMWordToken)
                {
                    SMWordToken wtk = (SMWordToken)wt;
                    if (wtk.Cardinality == SMConnectionCardinality.One || wtk.Editable)
                    {
                        richLayout.DropablesCount++;
                    }
                    string s = wtk.GetCurrentText();
                    wt.rect.Size = context.g.MeasureString(s, wtk.Font.Font, textBounds.Width, StringFormat.GenericTypographic);
                }
                else if (wt is SMWordText)
                {
                    SMWordText wtt = wt as SMWordText;
                    if (wtt.Draggable != SMDragResponse.None && control.Draggable != wtt.Draggable)
                    {
                        control.Draggable = wtt.Draggable;
                    }
                    if (wtt.text.StartsWith("\"") || wtt.text.StartsWith("\u201c"))
                    {
                        SizeF sf = context.g.MeasureString("\u201c", wtt.Font.Font, textBounds.Width, StringFormat.GenericTypographic);
                        startsWithParentheses = (int)sf.Width;
                    }
                    if (wtt.text.Equals(" "))
                    {
                        wtt.rect.Size = context.g.MeasureString(wtt.text, wtt.Font.Font);
                        isSpaceText   = true;
                    }
                    else
                    {
                        wtt.rect.Size = context.g.MeasureString(wtt.text, wtt.Font.Font, textBounds.Width, StringFormat.GenericTypographic);
                    }
                }
                else if (wt is SMWordImage)
                {
                    SMWordImage wti = wt as SMWordImage;
                    wti.rect.Size = wti.imageSize;
                }

                if (writeLineNo && !control.Autosize)
                {
                    if ((lineX + wt.rect.Width > lineEnd) || RunningLine == SMRunningLine.SingleWord)
                    {
                        if (currLine.Count > 0)
                        {
                            isNewLine = true;
                        }
                    }
                }

                if (isNewLine)
                {
                    if (currLine.Count == 0)
                    {
                        lineY += lineHeight * control.Paragraph.LineSpacing / 2;
                    }
                    else
                    {
                        lineY += lineHeight * control.Paragraph.LineSpacing;
                    }

                    currLine = new SMWordLine();
                    richLayout.Lines.Add(currLine);

                    lineHeight = context.g.MeasureString("M", control.GetUsedFont()).Height / 2;
                    lineNo++;

                    if (Columns != -1 && !control.Autosize)
                    {
                        if (lineY + lineHeight > textBounds.Bottom)
                        {
                            isNewColumn = true;
                        }
                    }
                }

                if (isNewPage)
                {
                    lineNo   = 0;
                    columnNo = 0;
                    pageNo++;
                    lineY = textBounds.Top;
                }


                if (isNewColumn)
                {
                    columnNo++;
                    lineNo = 0;

                    if (columnNo >= Columns)
                    {
                        pageNo++;
                        columnNo = 0;
                    }

                    lineY = textBounds.Top;
                }

                if (isNewLine || isNewColumn || isNewPage)
                {
                    lineX   = textBounds.X + columnNo * columnWidth + control.ContentPadding.Left;
                    lineEnd = lineX + lineWidth;
                }

                if (writeLineNo)
                {
                    if (currLine.Count == 0 && startsWithParentheses > 0)
                    {
                        wt.rect.X -= startsWithParentheses;
                        lineX     -= startsWithParentheses;
                    }
                    if (currLine.Count > 0 || !isSpaceText)
                    {
                        currLine.Add(wt);

                        wt.LineNo        = lineNo;
                        wt.ColumnNo      = columnNo;
                        wt.PageNo        = pageNo;
                        wt.rect.Location = new PointF(lineX, lineY);
                        lineX           += wt.rect.Width;
                        rightX           = Math.Max(rightX, (int)lineX);
                    }

                    lineHeight  = Math.Max(lineHeight, wt.rect.Height);
                    writeLineNo = false;
                }
            }

            lineY += lineHeight * control.Paragraph.LineSpacing;

            // vertical alignment
            AdjustVerticaly(textBounds, richLayout.Lines, control.GetVerticalAlign());

            // horizontal aligment
            AdjustLinesHorizontaly((int)lineWidth, control.GetHorizontalAlign(), richLayout.Lines);

            richLayout.Pages   = pageNo + 1;
            richLayout.bottomY = (int)lineY + 1;
            richLayout.rightX  = rightX + 1;

            return(richLayout);
        }
Esempio n. 5
0
        public override void Paint(MNPageContext context)
        {
            Rectangle bounds = Area.GetBounds(context);
            Rectangle boundsWithoutNavigation = bounds;

            if (ShowNavigationButtons)
            {
                boundsWithoutNavigation.Height -= navigButtonsHeight;
            }

            Rectangle               textBounds = ContentPadding.ApplyPadding(bounds);
            SMStatusLayout          layout;
            SMConnectionCardinality scard = Cardinality;

            if (UIStateHover && DropablesCount == 1)
            {
                Cardinality = SMConnectionCardinality.One;
            }

            layout      = PrepareBrushesAndPens();
            Cardinality = scard;

            DrawStyledBackground(context, layout, bounds);
            DrawStyledBorder(context, layout, bounds);

            string stext = Text;

            if (Content != null)
            {
                if (Content is MNReferencedText)
                {
                    stext = (Content as MNReferencedText).Text;
                }
            }

            if (!p_prevText.Equals(stext))
            {
                Text       = stext;
                p_prevText = stext;
            }

            if (drawWordsModified)
            {
                Rectangle layoutBounds = textBounds;
                if (ShowNavigationButtons)
                {
                    layoutBounds.Height -= navigButtonsHeight;
                }
                SMRichLayout lay = null;
                lay            = RecalculateWordsLayout(context, layoutBounds, drawWords, this, RunningLine, Columns);
                drawLines      = lay.Lines;
                PageCount      = lay.Pages;
                DropablesCount = lay.DropablesCount;

                drawWordsModified = false;
            }

            PaintPageNo(context, layout, CurrentPage, textBounds.X, textBounds.Y);

            if (ShowNavigationButtons)
            {
                textBounds = DrawNavigationButtons(context, boundsWithoutNavigation);
            }

            if (Columns > 1)
            {
                textBounds = DrawColumnSeparators(context, textBounds);
            }

            // draw selection marks
            base.Paint(context);
        }