Esempio n. 1
0
        public MyRootGraphic(
            UIPlatform uiPlatform,
            IFonts ifonts,
            int width, int height)
            : base(width, height)
        {
            this.uiPlatform          = uiPlatform;
            this._ifonts             = ifonts;
            this.graphicTimerTaskMan = new GraphicsTimerTaskManager(this, uiPlatform);
            _defaultTextEditFont     = new RequestFont("tahoma", 10);

#if DEBUG
            dbugCurrentGlobalVRoot = this;
            dbug_Init(null, null, null);
#endif

            //create default render box***
            this.topWindowRenderBox = new TopWindowRenderBox(this, width, height);
            this.topWindowEventRoot = new TopWindowEventRoot(this.topWindowRenderBox);
            this.SubscribeGraphicsIntervalTask(normalUpdateTask,
                                               TaskIntervalPlan.Animation,
                                               20,
                                               (s, e) =>
            {
                this.PrepareRender();
                this.FlushAccumGraphics();
            });
        }
Esempio n. 2
0
        void SetupStartHitPoint(CssBoxHitChain startChain, IFonts ifonts)
        {
            //find global location of start point
            HitInfo startHit = startChain.GetLastHit();

            //-----------------------------
            this.startHitRun          = null;
            this.startHitRunCharIndex = 0;
            switch (startHit.hitObjectKind)
            {
            case HitObjectKind.Run:
            {
                CssRun run = (CssRun)startHit.hitObject;
                //-------------------------------------------------------
                int sel_index;
                int sel_offset;
                run.FindSelectionPoint(ifonts,
                                       startHit.localX,
                                       out sel_index,
                                       out sel_offset);
                this.startHitRunCharIndex = sel_index;
                //modify hitpoint
                this.startHitHostLine = (CssLineBox)startChain.GetHitInfo(startChain.Count - 2).hitObject;
                this.startLineBeginSelectionAtPixel = (int)(run.Left + sel_offset);
                this.startHitRun = run;
            }
            break;

            case HitObjectKind.LineBox:
            {
                this.startHitHostLine = (CssLineBox)startHit.hitObject;
                this.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);
                this.startLineBeginSelectionAtPixel = 0;
                if (startHitLine != null)
                {
                    this.startHitHostLine = startHitLine;
                }
                else
                {
                    //if not found?
                    this.startHitHostLine = null;
                }
            }
            break;

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Esempio n. 3
0
        internal static CssBox CreateIsolateBox(IFonts iFonts, RootGraphic rootgfx)
        {
            var spec = new BoxSpec();

            spec.CssDisplay = CssDisplay.Block;
            spec.Freeze();
            var box = new CssIsolateBox(spec, rootgfx);

            //------------------------------------
            box.ReEvaluateFont(iFonts, 10);
            //------------------------------------
            return(box);
        }
Esempio n. 4
0
        internal static CssBox CreateBridgeBox(IFonts iFonts, LayoutFarm.RenderElement containerElement, RootGraphic rootgfx)
        {
            var spec = new BoxSpec();

            spec.CssDisplay = CssDisplay.Block;
            spec.Freeze();
            var box = new RenderElementBridgeCssBox(spec, containerElement, rootgfx);

            //------------------------------------
            box.ReEvaluateFont(iFonts, 10);
            //------------------------------------
            return(box);
        }
Esempio n. 5
0
        public void ReEvaluateFont(IFonts iFonts, float parentFontSize)
        {
            FontInfo fontInfo = this._myspec.GetFontInfo(iFonts, parentFontSize);

            this._actualFont       = fontInfo.ResolvedFont;
            this._actualLineHeight = fontInfo.LineHeight;
            this._actualEmHeight   = fontInfo.LineHeight;
            if (_myspec.WordSpacing.IsNormalWordSpacing)
            {
                this._actualWordSpacing = iFonts.MeasureWhitespace(_actualFont);
            }
            else
            {
                this._actualWordSpacing = iFonts.MeasureWhitespace(_actualFont)
                                          + CssValueParser.ConvertToPx(_myspec.WordSpacing, 1, this);
            }
        }
Esempio n. 6
0
        public void ReEvaluateFont(IFonts iFonts, float parentFontSize)
        {
            RequestFont fontInfo = this._myspec.GetFont(parentFontSize);

            this._resolvedFont = fontInfo;


            if (_myspec.WordSpacing.IsNormalWordSpacing)
            {
                this._actualWordSpacing = iFonts.MeasureWhitespace(_resolvedFont);
            }
            else
            {
                this._actualWordSpacing = iFonts.MeasureWhitespace(_resolvedFont)
                                          + CssValueParser.ConvertToPx(_myspec.WordSpacing, 1, this);
            }
        }
Esempio n. 7
0
 public Services(IBackend backend,
                 IDisplay display,
                 IFps fps,
                 IStages stages,
                 IInput input,
                 ISurfaces surfaces,
                 ICameras cameras,
                 IFonts fonts,
                 IHelpers helpers)
 {
     Backend  = backend;
     Display  = display;
     FPS      = fps;
     Stages   = stages;
     Input    = input;
     Surfaces = surfaces;
     Cameras  = cameras;
     Fonts    = fonts;
     Helpers  = helpers;
 }
Esempio n. 8
0
        public SelectionRange(
            CssBoxHitChain startChain,
            CssBoxHitChain endChain,
            IFonts ifonts)
        {
            if (IsOnTheSameLine(startChain, endChain))
            {
                //on the same line
                if (endChain.RootGlobalX < startChain.RootGlobalX)
                {
                    //swap
                    var tmp = endChain;
                    endChain   = startChain;
                    startChain = tmp;
                }
            }
            else
            {
                //across line
                if (endChain.RootGlobalY < startChain.RootGlobalY)
                {    //swap
                    var tmp = endChain;
                    endChain   = startChain;
                    startChain = tmp;
                }
            }

            //1.
            this.SetupStartHitPoint(startChain, ifonts);
            //2.
            if (this.startHitHostLine == null)
            {
                this.isValid = false;
                return;
            }


            this.SetupEndHitPoint(startChain, endChain, ifonts);
            this.snapSelectionArea = this.GetSelectionRectArea();
        }
Esempio n. 9
0
        public SelectionRange(
            CssBoxHitChain startChain,
            CssBoxHitChain endChain,
            IFonts ifonts)
        {
            if (IsOnTheSameLine(startChain, endChain))
            {
                //on the same line
                if (endChain.RootGlobalX < startChain.RootGlobalX)
                {
                    //swap
                    var tmp = endChain;
                    endChain = startChain;
                    startChain = tmp;
                }
            }
            else
            {
                //across line 
                if (endChain.RootGlobalY < startChain.RootGlobalY)
                {    //swap
                    var tmp = endChain;
                    endChain = startChain;
                    startChain = tmp;
                }
            }

            //1.
            this.SetupStartHitPoint(startChain, ifonts);
            //2. 
            if (this.startHitHostLine == null)
            {
                this.isValid = false;
                return;
            }


            this.SetupEndHitPoint(startChain, endChain, ifonts);
            this.snapSelectionArea = this.GetSelectionRectArea();
        }
Esempio n. 10
0
 public static void Assign(IConfig config, ISettings settings, IThemes themes, IBackgroundMusic backgroundMusic,
                           IDrawing draw, IGraphics graphics, IFonts fonts, ILanguage language, IGame game, IProfiles profiles, IRecording record,
                           ISongs songs, IVideo video, ISound sound, ICover cover, IDataBase dataBase, IControllers controller, IPlaylist playlist)
 {
     Config          = config;
     Settings        = settings;
     Themes          = themes;
     BackgroundMusic = backgroundMusic;
     Drawing         = draw;
     Graphics        = graphics;
     Fonts           = fonts;
     Language        = language;
     Game            = game;
     Profiles        = profiles;
     Record          = record;
     Songs           = songs;
     Video           = video;
     Sound           = sound;
     Cover           = cover;
     DataBase        = dataBase;
     Controller      = controller;
     Playlist        = playlist;
 }
 public void Bind(HtmlContainer htmlCont)
 {
     this._htmlContainer = htmlCont;
     _isBinded           = htmlCont != null;
     this.ifonts         = ((RootGraphic)htmlCont.RootCssBox.RootGfx).IFonts;
 }
Esempio n. 12
0
        /// <summary>
        /// evaluate computed value
        /// </summary>
        internal void ReEvaluateComputedValues(IFonts iFonts, CssBox containingBlock)
        {

            //depend on parent
            //1. fonts 
            if (this.ParentBox != null)
            {
                ReEvaluateFont(iFonts, this.ParentBox.ResolvedFont.SizeInPixels);
                //2. actual word spacing
                //this._actualWordSpacing = this.NoEms(this.InitSpec.LineHeight);
                //3. font size 
                //len = len.ConvertEmToPoints(parentBox.ActualFont.SizeInPoints);
            }
            else
            {
                ReEvaluateFont(iFonts, containingBlock.ResolvedFont.SizeInPixels);
                //this._actualFont = this.Spec.GetFont(containingBlock.Spec);
            }

            //-----------------------------------------------------------------------
            float cbWidth = containingBlock.VisualWidth;
            int tmpBoxCompactFlags = this._boxCompactFlags;
            this._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
            var 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 (this.__aa_dbugId == 5)
                        //{
                        //    int a = spec.__aa_dbugId;

                        //}

                        this._actualMarginLeft = RecalculateMargin(spec.MarginLeft, cbWidth);
                        this._actualMarginTop = RecalculateMargin(spec.MarginTop, cbWidth);
                        this._actualMarginRight = RecalculateMargin(spec.MarginRight, cbWidth);
                        this._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
                        this._actualPaddingLeft = RecalculatePadding(spec.PaddingLeft, cbWidth);
                        this._actualPaddingTop = RecalculatePadding(spec.PaddingTop, cbWidth);
                        this._actualPaddingRight = RecalculatePadding(spec.PaddingRight, cbWidth);
                        this._actualPaddingBottom = RecalculatePadding(spec.PaddingBottom, cbWidth);
                    }
                    break;
            }

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

            this._borderLeftVisible = a1 > 0 && spec.BorderLeftStyle >= CssBorderStyle.Visible;
            this._borderTopVisible = a2 > 0 && spec.BorderTopStyle >= CssBorderStyle.Visible;
            this._borderRightVisible = a3 > 0 && spec.BorderRightStyle >= CssBorderStyle.Visible;
            this._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;
            }
            //---------------------------------------------------------------------------

            this._actualCornerNE = a1 = CssValueParser.ConvertToPx(spec.CornerNERadius, 0, this);
            this._actualCornerNW = a2 = CssValueParser.ConvertToPx(spec.CornerNWRadius, 0, this);
            this._actualCornerSE = a3 = CssValueParser.ConvertToPx(spec.CornerSERadius, 0, this);
            this._actualCornerSW = a4 = CssValueParser.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 ||
                RenderUtils.IsColorVisible(ActualBackgroundColor))
            {
                tmpBoxCompactFlags |= BoxFlags.HAS_VISIBLE_BG;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_VISIBLE_BG;
            }




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

            //text indent   
            this._actualTextIndent = CssValueParser.ConvertToPx(spec.TextIndent, containingBlock.VisualWidth, this);
            this._actualBorderSpacingHorizontal = spec.BorderSpacingHorizontal.Number;
            this._actualBorderSpacingVertical = spec.BorderSpacingVertical.Number;
            //-----------------------
            //this._actualLineHeight = 0.9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this); 
            //expected width expected height
            //this._expectedWidth = CssValueParser.ParseLength(Width, cbWidth, this);
            //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 (this._myspec.HasBoxShadow)
            {
                //temp fix here
                //TODO: review move shadow to external decoration object/box
                if (decorator == null)
                {
                    decorator = new CssBoxDecorator();
                }
                decorator.HBoxShadowOffset = (int)CssValueParser.ConvertToPx(spec.BoxShadowHOffset, 0, this);
                decorator.VBoxShadowOffset = (int)CssValueParser.ConvertToPx(spec.BoxShadowVOffset, 0, this);
                decorator.Color = spec.BoxShadowColor;
            }
            else
            {
                this.decorator = null;
            }
        }
Esempio n. 13
0
        public void ReEvaluateFont(IFonts iFonts, float parentFontSize)
        {
            RequestFont fontInfo = this._myspec.GetFont(parentFontSize);

            this._resolvedFont = fontInfo;

           
            if (_myspec.WordSpacing.IsNormalWordSpacing)
            {
                this._actualWordSpacing = iFonts.MeasureWhitespace(_resolvedFont);
            }
            else
            {
                this._actualWordSpacing = iFonts.MeasureWhitespace(_resolvedFont)
                    + CssValueParser.ConvertToPx(_myspec.WordSpacing, 1, this);
            }
        }
Esempio n. 14
0
 public LayoutVisitor(IFonts fontService)
 {
     this.fontService = fontService;
 }
Esempio n. 15
0
 internal static CssBox CreateBridgeBox(IFonts iFonts, LayoutFarm.RenderElement containerElement, RootGraphic rootgfx)
 {
     var spec = new BoxSpec();
     spec.CssDisplay = CssDisplay.Block;
     spec.Freeze();
     var box = new RenderElementBridgeCssBox(spec, containerElement, rootgfx);
     //------------------------------------
     box.ReEvaluateFont(iFonts, 10);
     //------------------------------------
     return box;
 }
 /// <summary>
 /// Get the <paramref name="minWidth"/> and <paramref name="maxWidth"/> width of the box content.<br/>
 /// </summary>
 /// <param name="minWidth">The minimum width the content must be so it won't overflow (largest word + padding).</param>
 /// <param name="maxWidth">The total width the content can take without line wrapping (with padding).</param>
 static void CalculateMinMaxContentWidths(CssBox box,
     CssBox cbBox,
     IFonts iFonts,
     out float minWidth, out float maxWidth)
 {
     float min = 0f;
     float maxSum = 0f;
     float paddingSum = 0f;
     float marginSum = 0f;
     if (box.NeedComputedValueEvaluation) { box.ReEvaluateComputedValues(iFonts, cbBox); }
     CalculateMinMaxSumWords(box, cbBox, iFonts, ref min, ref maxSum, ref paddingSum, ref marginSum);
     maxWidth = paddingSum + maxSum;
     minWidth = paddingSum + (min < CssBoxConstConfig.BOX_MAX_RIGHT ? min : 0);
 }
        /// <summary>
        /// Get the <paramref name="min"/> and <paramref name="maxSum"/> of the box words content and <paramref name="paddingSum"/>.<br/>
        /// </summary>
        /// <param name="box">the box to calculate for</param>
        /// <param name="min">the width that allows for each word to fit (width of the longest word)</param>
        /// <param name="maxSum">the max width a single line of words can take without wrapping</param>
        /// <param name="paddingSum">the total amount of padding the content has </param>
        /// <param name="marginSum"></param>
        /// <returns></returns>
        static void CalculateMinMaxSumWords(
            CssBox box,
            CssBox cbBox,
            IFonts iFonts,
            ref float min,
            ref float maxSum,
            ref float paddingSum,
            ref float marginSum)
        {
            //recursive 
            float? oldSum = null;
            // not inline (block) boxes start a new line so we need to reset the max sum 
            if (box.CssDisplay != CssDisplay.Inline &&
                box.CssDisplay != CssDisplay.TableCell &&
                box.WhiteSpace != CssWhiteSpace.NoWrap)
            {
                oldSum = maxSum;
                maxSum = marginSum;
            }

            // add the padding 
            paddingSum += box.ActualBorderLeftWidth + box.ActualBorderRightWidth + box.ActualPaddingRight + box.ActualPaddingLeft;
            // for tables the padding also contains the spacing between cells                
            if (box.CssDisplay == CssDisplay.Table)
            {
                paddingSum += CssTableLayoutEngine.CalculateTableSpacing(box);
            }

            if (box.HasOnlyRuns)
            {
                // calculate the min and max sum for all the words in the box 
                foreach (CssRun run in box.GetRunIter())
                {
                    maxSum += run.Width;
                    min = Math.Max(min, run.Width);
                }
            }
            else
            {
                // recursively on all the child boxes
                //if this box has containing property 
                if (box.HasContainingBlockProperty)
                {
                    foreach (CssBox childBox in box.GetChildBoxIter())
                    {
                        if (childBox.NeedComputedValueEvaluation) { childBox.ReEvaluateComputedValues(iFonts, box); }

                        float msum = childBox.ActualMarginLeft + childBox.ActualMarginRight;
                        marginSum += msum;
                        //recursive                        
                        CalculateMinMaxSumWords(childBox, box, iFonts, ref min, ref maxSum, ref paddingSum, ref marginSum);
                        marginSum -= msum;
                    }
                }
                else
                {
                    foreach (CssBox childBox in box.GetChildBoxIter())
                    {
                        if (childBox.NeedComputedValueEvaluation) { childBox.ReEvaluateComputedValues(iFonts, cbBox); }

                        float msum = childBox.ActualMarginLeft + childBox.ActualMarginRight;
                        marginSum += msum;
                        //recursive
                        CalculateMinMaxSumWords(childBox, cbBox, iFonts, ref min, ref maxSum, ref paddingSum, ref marginSum);
                        marginSum -= msum;
                    }
                }
            }

            // max sum is max of all the lines in the box
            if (oldSum.HasValue)
            {
                maxSum = Math.Max(maxSum, oldSum.Value);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// evaluate computed value
        /// </summary>
        internal void ReEvaluateComputedValues(IFonts iFonts, CssBox containingBlock)
        {
            //depend on parent
            //1. fonts
            if (this.ParentBox != null)
            {
                ReEvaluateFont(iFonts, this.ParentBox.ResolvedFont.SizeInPixels);
                //2. actual word spacing
                //this._actualWordSpacing = this.NoEms(this.InitSpec.LineHeight);
                //3. font size
                //len = len.ConvertEmToPoints(parentBox.ActualFont.SizeInPoints);
            }
            else
            {
                ReEvaluateFont(iFonts, containingBlock.ResolvedFont.SizeInPixels);
                //this._actualFont = this.Spec.GetFont(containingBlock.Spec);
            }

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

            this._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
            var     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 (this.__aa_dbugId == 5)
                //{
                //    int a = spec.__aa_dbugId;

                //}

                this._actualMarginLeft   = RecalculateMargin(spec.MarginLeft, cbWidth);
                this._actualMarginTop    = RecalculateMargin(spec.MarginTop, cbWidth);
                this._actualMarginRight  = RecalculateMargin(spec.MarginRight, cbWidth);
                this._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
                this._actualPaddingLeft   = RecalculatePadding(spec.PaddingLeft, cbWidth);
                this._actualPaddingTop    = RecalculatePadding(spec.PaddingTop, cbWidth);
                this._actualPaddingRight  = RecalculatePadding(spec.PaddingRight, cbWidth);
                this._actualPaddingBottom = RecalculatePadding(spec.PaddingBottom, cbWidth);
            }
            break;
            }

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

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

            this._borderLeftVisible  = a1 > 0 && spec.BorderLeftStyle >= CssBorderStyle.Visible;
            this._borderTopVisible   = a2 > 0 && spec.BorderTopStyle >= CssBorderStyle.Visible;
            this._borderRightVisible = a3 > 0 && spec.BorderRightStyle >= CssBorderStyle.Visible;
            this._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;
            }
            //---------------------------------------------------------------------------

            this._actualCornerNE = a1 = CssValueParser.ConvertToPx(spec.CornerNERadius, 0, this);
            this._actualCornerNW = a2 = CssValueParser.ConvertToPx(spec.CornerNWRadius, 0, this);
            this._actualCornerSE = a3 = CssValueParser.ConvertToPx(spec.CornerSERadius, 0, this);
            this._actualCornerSW = a4 = CssValueParser.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 ||
                RenderUtils.IsColorVisible(ActualBackgroundColor))
            {
                tmpBoxCompactFlags |= BoxFlags.HAS_VISIBLE_BG;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_VISIBLE_BG;
            }



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

            //text indent
            this._actualTextIndent = CssValueParser.ConvertToPx(spec.TextIndent, containingBlock.VisualWidth, this);
            this._actualBorderSpacingHorizontal = spec.BorderSpacingHorizontal.Number;
            this._actualBorderSpacingVertical   = spec.BorderSpacingVertical.Number;
            //-----------------------
            //this._actualLineHeight = 0.9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this);
            //expected width expected height
            //this._expectedWidth = CssValueParser.ParseLength(Width, cbWidth, this);
            //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 (this._myspec.HasBoxShadow)
            {
                //temp fix here
                //TODO: review move shadow to external decoration object/box
                if (decorator == null)
                {
                    decorator = new CssBoxDecorator();
                }
                decorator.HBoxShadowOffset = (int)CssValueParser.ConvertToPx(spec.BoxShadowHOffset, 0, this);
                decorator.VBoxShadowOffset = (int)CssValueParser.ConvertToPx(spec.BoxShadowVOffset, 0, this);
                decorator.Color            = spec.BoxShadowColor;
            }
            else
            {
                this.decorator = null;
            }
        }
Esempio n. 19
0
        internal void FindSelectionPoint(IFonts ifonts,
                                         int offset, out int selectionIndex,
                                         out int runSelectionOffsetPx)
        {
            int charFit;
            int charFitWidth;
            var maxWidth = offset;

            switch (this.Kind)
            {
            case CssRunKind.BlockRun:
            {
                //contains sub
                selectionIndex       = -1;
                runSelectionOffsetPx = 0;
            }
            break;

            case CssRunKind.SolidContent:
            {
                // not a text word - set full selection
                selectionIndex       = -1;
                runSelectionOffsetPx = 0;
            }
            break;

            case CssRunKind.Text:
            {
                char[]     ownerTextBuff = CssBox.UnsafeGetTextBuffer(this.OwnerBox);
                CssTextRun textRun       = (CssTextRun)this;
                ifonts.MeasureString(ownerTextBuff, textRun.TextStartIndex, textRun.TextLength,
                                     this.OwnerBox.ResolvedFont, maxWidth, out charFit, out charFitWidth);
                selectionIndex       = charFit;
                runSelectionOffsetPx = charFitWidth;
            }
            break;

            case CssRunKind.Space:
            {
                char[]     ownerTextBuff = CssBox.UnsafeGetTextBuffer(this.OwnerBox);
                CssTextRun textRun       = (CssTextRun)this;
                ifonts.MeasureString(ownerTextBuff, textRun.TextStartIndex, textRun.TextLength,
                                     this.OwnerBox.ResolvedFont, maxWidth, out charFit, out charFitWidth);
                selectionIndex       = charFit;
                runSelectionOffsetPx = charFitWidth;
            }
            break;

            case CssRunKind.SingleSpace:
            {
                if (offset > this.Width / 2)
                {
                    selectionIndex       = -1;
                    runSelectionOffsetPx = 0;
                }
                else
                {
                    selectionIndex       = 0;
                    runSelectionOffsetPx = (int)this.Width;
                }
            }
            break;

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Esempio n. 20
0
 void SetupStartHitPoint(CssBoxHitChain startChain, IFonts ifonts)
 {
     //find global location of start point
     HitInfo startHit = startChain.GetLastHit();
     //-----------------------------
     this.startHitRun = null;
     this.startHitRunCharIndex = 0;
     switch (startHit.hitObjectKind)
     {
         case HitObjectKind.Run:
             {
                 CssRun run = (CssRun)startHit.hitObject;
                 //-------------------------------------------------------
                 int sel_index;
                 int sel_offset;
                 run.FindSelectionPoint(ifonts,
                      startHit.localX,
                      out sel_index,
                      out sel_offset);
                 this.startHitRunCharIndex = sel_index;
                 //modify hitpoint
                 this.startHitHostLine = (CssLineBox)startChain.GetHitInfo(startChain.Count - 2).hitObject;
                 this.startLineBeginSelectionAtPixel = (int)(run.Left + sel_offset);
                 this.startHitRun = run;
             }
             break;
         case HitObjectKind.LineBox:
             {
                 this.startHitHostLine = (CssLineBox)startHit.hitObject;
                 this.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);
                 this.startLineBeginSelectionAtPixel = 0;
                 if (startHitLine != null)
                 {
                     this.startHitHostLine = startHitLine;
                 }
                 else
                 {
                     //if not found?
                     this.startHitHostLine = null;
                 }
             }
             break;
         default:
             {
                 throw new NotSupportedException();
             }
     }
 }
Esempio n. 21
0
        void SetupEndHitPoint(CssBoxHitChain startChain, CssBoxHitChain endChain, IFonts ifonts)
        {
            //find global location of end point
            HitInfo    endHit         = endChain.GetLastHit();
            int        xposOnEndLine  = 0;
            CssLineBox endline        = null;
            int        run_sel_offset = 0;

            //find endline first
            this.endHitRunCharIndex = 0;
            this.endHitRun          = null;

            switch (endHit.hitObjectKind)
            {
            default:
            {
                throw new NotSupportedException();
            }

            case HitObjectKind.Run:
            {
                CssRun endRun = (CssRun)endHit.hitObject;
                //if (endRun.Text != null && endRun.Text.Contains("Jose"))
                //{
                //}

                int run_sel_index;
                endRun.FindSelectionPoint(ifonts,
                                          endHit.localX,
                                          out run_sel_index,
                                          out run_sel_offset);

                endline       = endRun.HostLine;
                xposOnEndLine = (int)(endRun.Left + run_sel_offset);

                this.endHitRunCharIndex = run_sel_index;
                this.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

            //----------------------------------
            this.selectedLines = new List <CssLineBox>();
            if (startHitHostLine == endline)
            {
                this.selectedLines.Add(endline);
                startHitHostLine.Select(startLineBeginSelectionAtPixel, xposOnEndLine,
                                        this.startHitRun, this.startHitRunCharIndex,
                                        this.endHitRun, this.endHitRunCharIndex);
                return; //early exit here ***
            }
            //----------------------------------
            //select on different line
            LineWalkVisitor lineWalkVisitor = null;
            int             breakAtLevel;

            if (FindCommonGround(startChain, endChain, out breakAtLevel) && breakAtLevel > 0)
            {
                var hit1 = endChain.GetHitInfo(breakAtLevel).hitObject;

                var hitBlockRun = hit1 as CssBlockRun;

                //multiple select
                //1. first part
                if (hitBlockRun != null)
                {
                    startHitHostLine.Select(startLineBeginSelectionAtPixel, (int)hitBlockRun.Left,
                                            this.startHitRun, this.startHitRunCharIndex,
                                            this.endHitRun, this.endHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(hitBlockRun);
                }
                else
                {
                    startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
                }
            }
            else
            {
                startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                selectedLines.Add(this.startHitHostLine);
                lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
            }

            lineWalkVisitor.SetWalkTargetPosition(endChain.RootGlobalX, endChain.RootGlobalY);
            lineWalkVisitor.Walk(endline, (lineCoverage, linebox, partialLineRun) =>
            {
                switch (lineCoverage)
                {
                case LineCoverage.EndLine:
                    {
                        //found end line
                        linebox.SelectPartialFromStart(xposOnEndLine, this.endHitRun, this.endHitRunCharIndex);
                        selectedLines.Add(linebox);
                    } break;

                case LineCoverage.PartialLine:
                    {
                        linebox.SelectPartialFromStart((int)partialLineRun.Right, this.endHitRun, this.endHitRunCharIndex);
                        selectedLines.Add(linebox);
                    } break;

                case LineCoverage.FullLine:
                    {
                        //check if hitpoint is in the line area
                        linebox.SelectFull();
                        selectedLines.Add(linebox);
                    } break;
                }
            });
        }
Esempio n. 22
0
        void SetupEndHitPoint(CssBoxHitChain startChain, CssBoxHitChain endChain, IFonts ifonts)
        {
            //find global location of end point 
            HitInfo endHit = endChain.GetLastHit();
            int xposOnEndLine = 0;
            CssLineBox endline = null;
            int run_sel_offset = 0;
            //find endline first
            this.endHitRunCharIndex = 0;
            this.endHitRun = null;
            switch (endHit.hitObjectKind)
            {
                default:
                    {
                        throw new NotSupportedException();
                    }
                case HitObjectKind.Run:
                    {
                        CssRun endRun = (CssRun)endHit.hitObject;
                        //if (endRun.Text != null && endRun.Text.Contains("Jose"))
                        //{
                        //}

                        int run_sel_index;
                        endRun.FindSelectionPoint(ifonts,
                             endHit.localX,
                             out run_sel_index,
                             out run_sel_offset);
                        endline = endRun.HostLine;
                        xposOnEndLine = (int)(endRun.Left + run_sel_offset);
                        this.endHitRunCharIndex = run_sel_index;
                        this.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

            //----------------------------------
            this.selectedLines = new List<CssLineBox>();
            if (startHitHostLine == endline)
            {
                this.selectedLines.Add(endline);
                startHitHostLine.Select(startLineBeginSelectionAtPixel, xposOnEndLine,
                        this.startHitRun, this.startHitRunCharIndex,
                        this.endHitRun, this.endHitRunCharIndex);
                return; //early exit here ***
            }
            //---------------------------------- 
            //select on different line 
            LineWalkVisitor lineWalkVisitor = null;
            int breakAtLevel;
            if (FindCommonGround(startChain, endChain, out breakAtLevel) && breakAtLevel > 0)
            {
                var hit1 = endChain.GetHitInfo(breakAtLevel).hitObject;
                var hitBlockRun = hit1 as CssBlockRun;
                //multiple select 
                //1. first part        
                if (hitBlockRun != null)
                {
                    startHitHostLine.Select(startLineBeginSelectionAtPixel, (int)hitBlockRun.Left,
                     this.startHitRun, this.startHitRunCharIndex,
                     this.endHitRun, this.endHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(hitBlockRun);
                }
                else
                {
                    startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
                }
            }
            else
            {
                startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                selectedLines.Add(this.startHitHostLine);
                lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
            }

            lineWalkVisitor.SetWalkTargetPosition(endChain.RootGlobalX, endChain.RootGlobalY);
            lineWalkVisitor.Walk(endline, (lineCoverage, linebox, partialLineRun) =>
            {
                switch (lineCoverage)
                {
                    case LineCoverage.EndLine:
                        {
                            //found end line  
                            linebox.SelectPartialFromStart(xposOnEndLine, this.endHitRun, this.endHitRunCharIndex);
                            selectedLines.Add(linebox);
                        }
                        break;
                    case LineCoverage.PartialLine:
                        {
                            linebox.SelectPartialFromStart((int)partialLineRun.Right, this.endHitRun, this.endHitRunCharIndex);
                            selectedLines.Add(linebox);
                        }
                        break;
                    case LineCoverage.FullLine:
                        {
                            //check if hitpoint is in the line area
                            linebox.SelectFull();
                            selectedLines.Add(linebox);
                        }
                        break;
                }
            });
        }
Esempio n. 23
0
 public HtmlInputEventAdapter(IFonts ifonts)
 {
     this.ifonts = ifonts;
 }
Esempio n. 24
0
        internal FontInfo GetFontInfo(IFonts ifonts, float parentFontSize)
        {
            //---------------------------------------
            if (_actualFontInfo != null)
            {
                return(this._actualFontInfo);
            }
            //---------------------------------------
            bool   relateToParent = false;
            string fontFam        = this.FontFamily;

            if (string.IsNullOrEmpty(FontFamily))
            {
                fontFam = FontDefaultConfig.DEFAULT_FONT_NAME;
            }

            //-----------------------------------------------------------------------------
            //style
            FontStyle st = PixelFarm.Drawing.FontStyle.Regular;

            switch (FontStyle)
            {
            case CssFontStyle.Italic:
            case CssFontStyle.Oblique:
                st |= PixelFarm.Drawing.FontStyle.Italic;
                break;
            }
            //-----------------------------------------------------
            //weight
            CssFontWeight fontWight = this.FontWeight;

            switch (this.FontWeight)
            {
            case CssFontWeight.Normal:
            case CssFontWeight.Lighter:
            case CssFontWeight.NotAssign:
            case CssFontWeight.Inherit:
            {
                //do nothing
            }
            break;

            default:
            {
                st |= PixelFarm.Drawing.FontStyle.Bold;
            }
            break;
            }

            CssLength fontsize = this.FontSize;

            if (fontsize.IsEmpty || fontsize.Number == 0)
            {
                fontsize = CssLength.MakeFontSizePtUnit(FontDefaultConfig.DEFAULT_FONT_SIZE);
            }

            float fsize = FontDefaultConfig.DEFAULT_FONT_SIZE;

            if (fontsize.IsFontSizeName)
            {
                switch (fontsize.UnitOrNames)
                {
                case CssUnitOrNames.FONTSIZE_MEDIUM:
                    fsize = FontDefaultConfig.DEFAULT_FONT_SIZE; break;

                case CssUnitOrNames.FONTSIZE_XX_SMALL:
                    fsize = FontDefaultConfig.DEFAULT_FONT_SIZE - 4; break;

                case CssUnitOrNames.FONTSIZE_X_SMALL:
                    fsize = FontDefaultConfig.DEFAULT_FONT_SIZE - 3; break;

                case CssUnitOrNames.FONTSIZE_LARGE:
                    fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 2; break;

                case CssUnitOrNames.FONTSIZE_X_LARGE:
                    fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 3; break;

                case CssUnitOrNames.FONTSIZE_XX_LARGE:
                    fsize = FontDefaultConfig.DEFAULT_FONT_SIZE + 4; break;

                case CssUnitOrNames.FONTSIZE_SMALLER:
                {
                    relateToParent = true;
                    //float parentFontSize = ConstConfig.DEFAULT_FONT_SIZE;
                    //if (parentBox != null)
                    //{
                    //    parentFontSize = parentBox._actualFont.Size;
                    //}
                    fsize = parentFontSize - 2;
                }
                break;

                case CssUnitOrNames.FONTSIZE_LARGER:
                {
                    relateToParent = true;
                    //float parentFontSize = ConstConfig.DEFAULT_FONT_SIZE;
                    //if (parentBox != null)
                    //{
                    //    parentFontSize = parentBox._actualFont.Size;
                    //}
                    fsize = parentFontSize + 2;
                }
                break;

                default:
                    throw new NotSupportedException();
                }
            }
            else
            {
                fsize = fontsize.Number;
            }


            if (fontsize.UnitOrNames == CssUnitOrNames.Ems)
            {
                fsize          = fontsize.Number * FontDefaultConfig.DEFAULT_FONT_SIZE;
                relateToParent = true;
            }
            if (fsize <= 1f)
            {
                fsize = FontDefaultConfig.DEFAULT_FONT_SIZE;
            }

            FontInfo fontInfo = ifonts.GetFontInfo(fontFam, fsize, st);

            if (!relateToParent)
            {
                //cahce value
                this._actualFont     = fontInfo.ResolvedFont;
                this._actualFontInfo = fontInfo;
            }
            return(fontInfo);
        }
Esempio n. 25
0
 public void ChangeIFonts(IFonts ifonts)
 {
     this._ifonts = ifonts;
 }
Esempio n. 26
0
 internal void FindSelectionPoint(IFonts ifonts,
     int offset, out int selectionIndex,
     out int runSelectionOffsetPx)
 {
     int charFit;
     int charFitWidth;
     var maxWidth = offset;
     switch (this.Kind)
     {
         case CssRunKind.BlockRun:
             {
                 //contains sub  
                 selectionIndex = -1;
                 runSelectionOffsetPx = 0;
             }
             break;
         case CssRunKind.SolidContent:
             {
                 // not a text word - set full selection
                 selectionIndex = -1;
                 runSelectionOffsetPx = 0;
             }
             break;
         case CssRunKind.Text:
             {
                 char[] ownerTextBuff = CssBox.UnsafeGetTextBuffer(this.OwnerBox);
                 CssTextRun textRun = (CssTextRun)this;
                 ifonts.MeasureString(ownerTextBuff, textRun.TextStartIndex, textRun.TextLength,
                     this.OwnerBox.ResolvedFont, maxWidth, out charFit, out charFitWidth);
                 selectionIndex = charFit;
                 runSelectionOffsetPx = charFitWidth;
             }
             break;
         case CssRunKind.Space:
             {
                 char[] ownerTextBuff = CssBox.UnsafeGetTextBuffer(this.OwnerBox);
                 CssTextRun textRun = (CssTextRun)this;
                 ifonts.MeasureString(ownerTextBuff, textRun.TextStartIndex, textRun.TextLength,
                     this.OwnerBox.ResolvedFont, maxWidth, out charFit, out charFitWidth);
                 selectionIndex = charFit;
                 runSelectionOffsetPx = charFitWidth;
             }
             break;
         case CssRunKind.SingleSpace:
             {
                 if (offset > this.Width / 2)
                 {
                     selectionIndex = -1;
                     runSelectionOffsetPx = 0;
                 }
                 else
                 {
                     selectionIndex = 0;
                     runSelectionOffsetPx = (int)this.Width;
                 }
             }
             break;
         default:
             {
                 throw new NotSupportedException();
             }
     }
 }
Esempio n. 27
0
 internal static CssBox CreateIsolateBox(IFonts iFonts, RootGraphic rootgfx)
 {
     var spec = new BoxSpec();
     spec.CssDisplay = CssDisplay.Block;
     spec.Freeze();
     var box = new CssIsolateBox(spec, rootgfx);
     //------------------------------------
     box.ReEvaluateFont(iFonts, 10);
     //------------------------------------
     return box;
 }
        public HtmlInputEventAdapter()
        {

            this.ifonts = TextServices.IFonts;
        }