Example #1
0
        public override bool Load(Serializer.RSFileReader br)
        {
            if (base.Load(br))
            {
                byte b;
                while ((b = br.ReadByte()) != 0)
                {
                    switch (b)
                    {
                    case 10:
                        Columns = br.ReadInt32();
                        break;

                    case 11:
                        ColumnSeparatorStyle = (SMLineStyle)br.ReadInt32();
                        break;

                    case 12:
                        ColumnSeparatorWidth = br.ReadFloat();
                        break;

                    case 13:
                        ShowNavigationButtons = br.ReadBool();
                        break;

                    case 14:
                        RunningLine = (SMRunningLine)br.ReadInt32();
                        break;
                    }
                }
                return(true);
            }

            return(false);
        }
Example #2
0
        public override bool Load(RSFileReader br)
        {
            if (base.Load(br))
            {
                byte tag;
                while ((tag = br.ReadByte()) != 0)
                {
                    switch (tag)
                    {
                    case 10:
                        RunningLine = (SMRunningLine)br.ReadInt32();
                        break;

                    case 11:
                        RichContent = br.ReadBool();
                        break;

                    default:
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
Example #3
0
 public SMLabel(MNPage p)
     : base(p)
 {
     Text          = "Label";
     RichContent   = true;
     RunningLine   = SMRunningLine.Natural;
     richText      = new SMRichText(this);
     Area.BackType = SMBackgroundType.None;
 }
Example #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);
        }