Пример #1
0
        private void AppendWord(List <SMWordBase> list, string text, RunningFormat fmt)
        {
            // TODO

            SMWordText wt = new SMWordText(Font);

            wt.text       = text;
            wt.tag        = text.Trim();
            wt.Draggable  = fmt.dragResponse;
            wt.Evaluation = MNEvaluationType.None;
            wt.Font       = fmt.GetFont();
            wt.lineOffset = Convert.ToInt32(-55 * fmt.lineOffset);
            list.Add(wt);
        }
Пример #2
0
        private static void AppendWord(List <SMWordBase> list, string text, SMControl control, RunningFormat fmt)
        {
            // TODO

            SMWordText wt = new SMWordText(control.Font);

            wt.text              = text;
            wt.tag               = text.Trim();
            wt.Draggable         = fmt.dragResponse;
            wt.Evaluation        = MNEvaluationType.None;
            wt.Font              = fmt.GetFont();
            wt.replacementTarget = fmt.selectForReplacementTarget;
            list.Add(wt);
        }
Пример #3
0
        public override bool OnDropFinished(PVDragContext dc)
        {
            bool needUpdateDrawWords = false;

            /*if (this.Cardinality == SMConnectionCardinality.One && dc.draggedItem != null)
             * {
             *  drawWords.Clear();
             *  DroppedItems.Clear();
             *  drawWordsModified = true;
             *  needUpdateDrawWords = true;
             * }
             * else if (this.Cardinality == SMConnectionCardinality.Many)
             * {
             *  needUpdateDrawWords = true;
             * }
             * else*/
            {
                if (dc.draggedItem != null)
                {
                    Point p = dc.lastPoint;
                    p.Offset(-Area.Left, -Area.Top);
                    SMWordToken lastToken = null;
                    foreach (SMWordBase wt in drawWords)
                    {
                        if (wt is SMWordToken)
                        {
                            lastToken = wt as SMWordToken;
                        }
                        if (wt.rect.Contains(p))
                        {
                            if (wt is SMWordToken)
                            {
                                SMWordToken wtk = (SMWordToken)wt;
                                if (wtk.Editable)
                                {
                                    wtk.AcceptString(dc.draggedItem.Tag);
                                    wtk.UIStateHover  = false;
                                    drawWordsModified = true;
                                    return(true);
                                }
                                else if (wtk.Cardinality == SMConnectionCardinality.One || wtk.Cardinality == SMConnectionCardinality.Many)
                                {
                                    wtk.UIStateHover = false;
                                    return(SendContentToToken(dc, wtk));
                                }
                            }
                        }
                    }
                    if (DropablesCount == 1 && lastToken != null)
                    {
                        return(SendContentToToken(dc, lastToken));
                    }
                }
            }

            if (base.OnDropFinished(dc) && needUpdateDrawWords)
            {
                SMWordBase wr = null;
                if (dc.draggedItem.Image != null)
                {
                    wr = new SMWordImage(this.Font, dc.draggedItem);
                }
                else
                {
                    wr = new SMWordText(this.Font, dc.draggedItem);
                }
                wr.Evaluation = this.HasImmediateEvaluation ? MNEvaluationType.Immediate : MNEvaluationType.Lazy;
                drawWords.Add(wr);
                drawWordsModified = true;
                return(true);
            }

            return(false);
        }
Пример #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);
        }