Ejemplo n.º 1
0
        public HtmlHost(HtmlHostCreationConfig config)
        {
            //use default style sheet

#if DEBUG
            if (!config.ValidateConfig())
            {
                throw new NotSupportedException();
            }
#endif

            _commonHtmlDoc = new HtmlDocument(this);
            if (config.ActiveSheet != null)
            {
                _commonHtmlDoc.CssActiveSheet = this.BaseStylesheet = config.ActiveSheet;
            }
            else
            {
                //use default
                _commonHtmlDoc.CssActiveSheet = this.BaseStylesheet =
                    LayoutFarm.WebDom.Parser.CssParserHelper.ParseStyleSheet(null,
                                                                             LayoutFarm.Composers.CssDefaults.DefaultCssData,
                                                                             true);
            }

            _rootgfx       = config.RootGraphic;
            _txtsx         = config.TextService;
            _svgCreator    = new PaintLab.Svg.SvgCreator();
            _mathMLCreator = new PaintLab.MathML.MathMLBoxTreeCreator();
        }
Ejemplo n.º 2
0
        void SetupStartHitPoint(CssBoxHitChain startChain, IHtmlTextService textService)
        {
            //find global location of start point
            HitInfo startHit = startChain.GetLastHit();

            //-----------------------------
            _startHitRun          = null;
            _startHitRunCharIndex = 0;
            switch (startHit.hitObjectKind)
            {
            case HitObjectKind.Run:
            {
                CssRun run = (CssRun)startHit.hitObject;
                //-------------------------------------------------------

                run.FindSelectionPoint(textService,
                                       startHit.localX,
                                       out int sel_index,
                                       out int sel_offset);
                _startHitRunCharIndex = sel_index;
                //modify hitpoint
                _startHitHostLine = (CssLineBox)startChain.GetHitInfo(startChain.Count - 2).hitObject;
                _startLineBeginSelectionAtPixel = (int)(run.Left + sel_offset);
                _startHitRun = run;
            }
            break;

            case HitObjectKind.LineBox:
            {
                _startHitHostLine = (CssLineBox)startHit.hitObject;
                _startLineBeginSelectionAtPixel = startHit.localX;
                //make global
            }
            break;

            case HitObjectKind.CssBox:
            {
                CssBox box = (CssBox)startHit.hitObject;
                //find first nearest line at point
                CssLineBox startHitLine = FindNearestLine(box, startChain.RootGlobalY, 5);
                _startLineBeginSelectionAtPixel = 0;
                if (startHitLine != null)
                {
                    _startHitHostLine = startHitLine;
                }
                else
                {
                    //if not found?
                    _startHitHostLine = null;
                }
            }
            break;

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Ejemplo n.º 3
0
        public void ReEvaluateFont(IHtmlTextService txtsx, float parentFontSize)
        {
            _resolvedFont1 = txtsx.ResolveFont(_reqFont = _myspec.GetFont(parentFontSize));

            if (_myspec.WordSpacing.IsNormalWordSpacing)
            {
                //use normal spacing
                _actualWordSpacing = _resolvedFont1.WhitespaceWidth;//use pre-rounding (int) or exact scaled value ???
            }
            else
            {
                //TODO: review here,***
                //additional to original whitespacing or REPLACE with the new value
                _actualWordSpacing = _resolvedFont1.WhitespaceWidth +//use pre-rounding (int) or exact scaled value ???
                                     CssLengthExt.ConvertToPx(_myspec.WordSpacing, 1, this);
            }
        }
Ejemplo n.º 4
0
        public SelectionRange(
            CssBoxHitChain startChain,
            CssBoxHitChain endChain,
            IHtmlTextService textservice)
        {
            if (IsOnTheSameLine(startChain, endChain))
            {
                //on the same line
                if (endChain.RootGlobalX < startChain.RootGlobalX)
                {
                    //swap
                    CssBoxHitChain tmp = endChain;
                    endChain   = startChain;
                    startChain = tmp;
                }
            }
            else
            {
                //across line
                if (endChain.RootGlobalY < startChain.RootGlobalY)
                {    //swap
                    CssBoxHitChain tmp = endChain;
                    endChain   = startChain;
                    startChain = tmp;
                }
            }

            //1.
            this.SetupStartHitPoint(startChain, textservice);
            //2.
            if (_startHitHostLine == null)
            {
                IsValid = false;
                return;
            }

            this.SetupEndHitPoint(startChain, endChain, textservice);
            SnapSelectionArea = this.GetSelectionRectArea();
        }
Ejemplo n.º 5
0
 public LayoutVisitor(IHtmlTextService txtClient)
 {
     _txtClient = txtClient;
 }
Ejemplo n.º 6
0
        void SetupEndHitPoint(CssBoxHitChain startChain, CssBoxHitChain endChain, IHtmlTextService textService)
        {
            //find global location of end point
            HitInfo    endHit        = endChain.GetLastHit();
            int        xposOnEndLine = 0;
            CssLineBox endline       = null;

            //find endline first
            _endHitRunCharIndex = 0;
            _endHitRun          = null;
            switch (endHit.hitObjectKind)
            {
            default:
            {
                throw new NotSupportedException();
            }

            case HitObjectKind.Run:
            {
                CssRun endRun = (CssRun)endHit.hitObject;
#if DEBUG
                //if (endRun.Text != null && endRun.Text.Contains("Jose"))
                //{
                //}
                if (endHit.localX > 23)
                {
                }
                System.Diagnostics.Debug.WriteLine(endHit.localX);
#endif
                endRun.FindSelectionPoint(textService,
                                          endHit.localX,
                                          out int run_sel_index,
                                          out int run_sel_offset);
                endline             = endRun.HostLine;
                xposOnEndLine       = (int)(endRun.Left + run_sel_offset);
                _endHitRunCharIndex = run_sel_index;

#if DEBUG
                System.Diagnostics.Debug.WriteLine(_endHitRunCharIndex);
#endif
                _endHitRun = endRun;
            }
            break;

            case HitObjectKind.LineBox:
            {
                endline       = (CssLineBox)endHit.hitObject;
                xposOnEndLine = endHit.localX;
            }
            break;

            case HitObjectKind.CssBox:
            {
                CssBox hitBox = (CssBox)endHit.hitObject;
                endline       = FindNearestLine(hitBox, endChain.RootGlobalY, 5);
                xposOnEndLine = endHit.localX;
            }
            break;
            }

#if DEBUG
            if (xposOnEndLine == 0)
            {
            }
#endif

            //----------------------------------
            _selectedLines = new List <CssLineBox>();
            if (_startHitHostLine == endline)
            {
                _selectedLines.Add(endline);
                _startHitHostLine.Select(_startLineBeginSelectionAtPixel, xposOnEndLine,
                                         _startHitRun, _startHitRunCharIndex,
                                         _endHitRun, _endHitRunCharIndex);
                return; //early exit here ***
            }
            //----------------------------------
            //select on different line
            LineWalkVisitor lineWalkVisitor = null;

            if (FindCommonGround(startChain, endChain, out int breakAtLevel) && breakAtLevel > 0)
            {
                //multiple select
                //1. first part
                if (endChain.GetHitInfo(breakAtLevel).hitObject is CssBlockRun hitBlockRun)
                {
                    _startHitHostLine.Select(_startLineBeginSelectionAtPixel, (int)hitBlockRun.Left,
                                             _startHitRun, _startHitRunCharIndex,
                                             _endHitRun, _endHitRunCharIndex);
                    _selectedLines.Add(_startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(hitBlockRun);
                }
                else
                {
                    _startHitHostLine.SelectPartialToEnd(_startLineBeginSelectionAtPixel, _startHitRun, _startHitRunCharIndex);
                    _selectedLines.Add(_startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(_startHitHostLine);
                }
            }
            else
            {
                _startHitHostLine.SelectPartialToEnd(_startLineBeginSelectionAtPixel, _startHitRun, _startHitRunCharIndex);
                _selectedLines.Add(_startHitHostLine);
                lineWalkVisitor = new LineWalkVisitor(_startHitHostLine);
            }

            lineWalkVisitor.SetWalkTargetPosition(endChain.RootGlobalX, endChain.RootGlobalY);

#if DEBUG
            int dbugExpectedId = 1;
#endif
            lineWalkVisitor.Walk(endline, (lineCoverage, linebox, partialLineRun) =>
            {
#if DEBUG
                //System.Diagnostics.Debug.WriteLine("sel:" + linebox.dbugId);
                if (dbugExpectedId != linebox.dbugId)
                {
                }
                dbugExpectedId++;
#endif
                switch (lineCoverage)
                {
                case LineCoverage.EndLine:
                    {
                        //found end line
                        linebox.SelectPartialFromStart(xposOnEndLine, _endHitRun, _endHitRunCharIndex);
                        _selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.PartialLine:
                    {
                        linebox.SelectPartialFromStart((int)partialLineRun.Right, _endHitRun, _endHitRunCharIndex);
                        _selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.FullLine:
                    {
                        //check if hitpoint is in the line area
                        linebox.SelectFull();
                        _selectedLines.Add(linebox);
                    }
                    break;
                }
            });
        }
Ejemplo n.º 7
0
 internal LayoutVisitor(IHtmlTextService txtClient)
 {
     _txtClient = txtClient;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// evaluate computed value
        /// </summary>
        internal void ReEvaluateComputedValues(IHtmlTextService iFonts, CssBox containingBlock)
        {
            //depend on parent
            //1. fonts
            if (this.ParentBox != null)
            {
                if (this.ParentBox.ResolvedFont == null)
                {
                    //TODO: review this ... WHY?

                    //SIZE in point unit or pixel???
                    ReEvaluateFont(iFonts, containingBlock._resolvedFont1.SizeInPoints);
                }
                else
                {
                    ReEvaluateFont(iFonts, this.ParentBox._resolvedFont1.SizeInPoints);
                }


                //2. actual word spacing
                //_actualWordSpacing = this.NoEms(this.InitSpec.LineHeight);
                //3. font size
                //len = len.ConvertEmToPoints(parentBox.ActualFont.SizeInPoints);
            }
            else
            {
                ReEvaluateFont(iFonts, containingBlock._resolvedFont1.SizeInPoints);
                //_actualFont = this.Spec.GetFont(containingBlock.Spec);
            }

            //-----------------------------------------------------------------------
            float cbWidth            = containingBlock.VisualWidth;
            int   tmpBoxCompactFlags = _boxCompactFlags;

            _boxCompactFlags |= BoxFlags.LAY_EVAL_COMPUTE_VALUES;
            //www.w3.org/TR/CSS2/box.html#margin-properties
            //w3c: margin applies to all elements except elements table display type
            //other than table-caption,table and inline table
            CssDisplay cssDisplay = this.CssDisplay;
            BoxSpec    spec       = _myspec;

            switch (cssDisplay)
            {
            case CssDisplay.None:
            {
                return;
            }

            case CssDisplay.TableCell:
            case CssDisplay.TableColumn:
            case CssDisplay.TableColumnGroup:
            case CssDisplay.TableFooterGroup:
            case CssDisplay.TableHeaderGroup:
            case CssDisplay.TableRow:
            case CssDisplay.TableRowGroup:
            {
                //no margin
            }
            break;

            default:
            {
                //if (__aa_dbugId == 5)
                //{
                //    int a = spec.__aa_dbugId;

                //}

                _actualMarginLeft   = RecalculateMargin(spec.MarginLeft, cbWidth);
                _actualMarginTop    = RecalculateMargin(spec.MarginTop, cbWidth);
                _actualMarginRight  = RecalculateMargin(spec.MarginRight, cbWidth);
                _actualMarginBottom = RecalculateMargin(spec.MarginBottom, cbWidth);
            }
            break;
            }
            //www.w3.org/TR/CSS2/box.html#padding-properties
            switch (cssDisplay)
            {
            case CssDisplay.TableRowGroup:
            case CssDisplay.TableHeaderGroup:
            case CssDisplay.TableFooterGroup:
            case CssDisplay.TableRow:
            case CssDisplay.TableColumnGroup:
            case CssDisplay.TableColumn:
            {
                //no padding
            }
            break;

            default:
            {
                //-----------------------------------------------------------------------
                //padding
                _actualPaddingLeft   = RecalculatePadding(spec.PaddingLeft, cbWidth);
                _actualPaddingTop    = RecalculatePadding(spec.PaddingTop, cbWidth);
                _actualPaddingRight  = RecalculatePadding(spec.PaddingRight, cbWidth);
                _actualPaddingBottom = RecalculatePadding(spec.PaddingBottom, cbWidth);
            }
            break;
            }

            //-----------------------------------------------------------------------
            //borders
            float a1, a2, a3, a4;

            _actualBorderLeftWidth   = a1 = (spec.BorderLeftStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderLeftWidth, this);
            _actualBorderTopWidth    = a2 = (spec.BorderTopStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderTopWidth, this);
            _actualBorderRightWidth  = a3 = (spec.BorderRightStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderRightWidth, this);
            _actualBorderBottomWidth = a4 = (spec.BorderBottomStyle == CssBorderStyle.None) ? 0 : CssLengthExt.GetActualBorderWidth(spec.BorderBottomWidth, this);
            //---------------------------------------------------------------------------

            _borderLeftVisible  = a1 > 0 && spec.BorderLeftStyle >= CssBorderStyle.Visible;
            _borderTopVisible   = a2 > 0 && spec.BorderTopStyle >= CssBorderStyle.Visible;
            _borderRightVisible = a3 > 0 && spec.BorderRightStyle >= CssBorderStyle.Visible;
            _borderBottomVisble = a4 > 0 && spec.BorderBottomStyle >= CssBorderStyle.Visible;
            //extension ***
            if (a1 + a2 + a3 + a4 > 0)
            {
                //css 2.1 border can't be nagative values

                tmpBoxCompactFlags |= BoxFlags.HAS_SOME_VISIBLE_BORDER;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_SOME_VISIBLE_BORDER;
            }
            //---------------------------------------------------------------------------

            _actualCornerNE = a1 = CssLengthExt.ConvertToPx(spec.CornerNERadius, 0, this);
            _actualCornerNW = a2 = CssLengthExt.ConvertToPx(spec.CornerNWRadius, 0, this);
            _actualCornerSE = a3 = CssLengthExt.ConvertToPx(spec.CornerSERadius, 0, this);
            _actualCornerSW = a4 = CssLengthExt.ConvertToPx(spec.CornerSWRadius, 0, this);
            if ((a1 + a2 + a3 + a4) > 0)
            {
                //evaluate
                tmpBoxCompactFlags |= BoxFlags.HAS_ROUND_CORNER;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_ROUND_CORNER;
            }
            //---------------------------------------------------------------------------
            //evaluate bg

            if (BackgroundGradient != Color.Transparent ||
                (ActualBackgroundColor.A > 0))

            {
                tmpBoxCompactFlags |= BoxFlags.HAS_VISIBLE_BG;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_VISIBLE_BG;
            }



            if (spec.WordSpacing.IsNormalWordSpacing)
            {
                _actualWordSpacing = iFonts.MeasureWhitespace(_reqFont);
            }
            else
            {
                _actualWordSpacing = iFonts.MeasureWhitespace(_reqFont)
                                     + CssLengthExt.ConvertToPx(spec.WordSpacing, 1, this);
            }
            //----------------------------------------------
            _boxCompactFlags = tmpBoxCompactFlags;
            //----------------------------------------------

            //text indent
            _actualTextIndent = CssLengthExt.ConvertToPx(spec.TextIndent, containingBlock.VisualWidth, this);
            _actualBorderSpacingHorizontal = spec.BorderSpacingHorizontal.Number;
            _actualBorderSpacingVertical   = spec.BorderSpacingVertical.Number;
            //-----------------------
            //_actualLineHeight = 0.9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this);
            //expected width expected height
            //_expectedWidth = CssValueParser.ParseLength(Width, cbWidth, this);
            //_expectedHight = CssValueParser.ParseLength(Height, containingBlock.SizeHeight, this);
            ////----------------------------------------------


            //www.w3.org/TR/CSS2/visudet.html#line-height
            //line height,
            //percent value of line height :
            // is refer to font size of the element itself
            //if (this.LineHeight.Number > 0)
            //{
            //    _actualLineHeight = .9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this);
            //}
            //else
            //{
            //    _actualLineHeight = .9f * (this.GetEmHeight());
            //}


            if (_myspec.HasBoxShadow)
            {
                //temp fix here
                //TODO: review move shadow to external decoration object/box
                if (_decorator == null)
                {
                    _decorator = new CssBoxDecorator();
                }
                _decorator.HBoxShadowOffset = (int)CssLengthExt.ConvertToPx(spec.BoxShadowHOffset, 0, this);
                _decorator.VBoxShadowOffset = (int)CssLengthExt.ConvertToPx(spec.BoxShadowVOffset, 0, this);
                _decorator.Color            = spec.BoxShadowColor;
            }
            else
            {
                _decorator = null;
            }
        }