Exemple #1
0
        internal static ITextContext GetTextContext(string text, Size size, StyleRuleSet style, GUIState state)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (style == null)
            {
                throw new ArgumentNullException(nameof(style));
            }

            var fontFamily    = style.Get <string>(StylePropertyName.FontFamily, state);
            var fontSize      = style.Get <double>(StylePropertyName.FontSize, state);
            var textAlignment = (TextAlignment)style.Get <int>(StylePropertyName.TextAlignment, state);

            return(TextContextCache.Default.GetOrAdd(text, fontFamily, fontSize, textAlignment));
        }
Exemple #2
0
        public static Rect GetContentBox(Rect rect, StyleRuleSet style)
        {
            //Widths of border
            var bt = style.Get <double>(GUIStyleName.BorderTop);
            var br = style.Get <double>(GUIStyleName.BorderRight);
            var bb = style.Get <double>(GUIStyleName.BorderBottom);
            var bl = style.Get <double>(GUIStyleName.BorderLeft);

            //Widths of padding
            var pt = style.Get <double>(GUIStyleName.PaddingTop);
            var pr = style.Get <double>(GUIStyleName.PaddingRight);
            var pb = style.Get <double>(GUIStyleName.PaddingBottom);
            var pl = style.Get <double>(GUIStyleName.PaddingLeft);

            //4 corner of the border-box
            var btl = new Point(rect.Left, rect.Top);
            var btr = new Point(rect.Right, rect.Top);
            var bbr = new Point(rect.Right, rect.Bottom);
            var bbl = new Point(rect.Left, rect.Bottom);

            //4 corner of the padding-box
            var ptl = new Point(btl.X + bl, btl.Y + bt);
            var ptr = new Point(btr.X - br, btr.Y + bt);
            var pbr = new Point(bbr.X - br, bbr.Y - bb);
            var pbl = new Point(bbl.X + bl, bbl.Y - bb);

            Debug.Assert(ptl.X < ptr.X);//TODO what if (ptl.X > ptr.X) happens?

            //4 corner of the content-box
            var ctl = new Point(ptl.X + pl, ptl.Y + pt);
            var ctr = new Point(ptr.X - pr, ptr.Y + pr);
            var cbr = new Point(pbr.X - pr, pbr.Y - pb);
            var cbl = new Point(pbl.X + pl, pbl.Y - pb);

            if (ctl.X >= ctr.X)
            {
                Log.Warning("Content box is zero-sized.");
                return(new Rect(ctl, Size.Zero));
            }

            return(new Rect(ctl, cbr));
        }
Exemple #3
0
        internal static ITextContext GetTextContext(string text, Size size, StyleRuleSet style, GUIState state)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (style == null)
            {
                throw new ArgumentNullException(nameof(style));
            }

            int textMeshId = GetTextId(text, state);

            ITextContext textContext;

            if (TextContextCache.TryGetValue(textMeshId, out textContext))
            {
                return(textContext);
            }
            else
            {
                // create a TextContent for the text
                var fontFamily    = style.Get <string>(GUIStyleName.FontFamily, state);
                var fontSize      = style.Get <double>(GUIStyleName.FontSize, state);
                var fontStretch   = (FontStretch)style.Get <int>(GUIStyleName.FontStretch, state);
                var fontStyle     = (FontStyle)style.Get <int>(GUIStyleName.FontStyle, state);
                var fontWeight    = (FontWeight)style.Get <int>(GUIStyleName.FontWeight, state);
                var textAlignment = (TextAlignment)style.Get <int>(GUIStyleName.TextAlignment, state);
                textContext = Application.PlatformContext.CreateTextContext(
                    text,
                    fontFamily, (int)fontSize, fontStretch, fontStyle, fontWeight,
                    (int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height),
                    textAlignment);
                textContext.Build(Point.Zero);
                TextContextCache.Add(textMeshId, textContext);
            }
            return(textContext);
        }