Ejemplo n.º 1
0
        public static StringLayout LayoutString(
            this SpriteFont font, AbstractString text, ArraySegment <BitmapDrawCall>?buffer = null,
            Vector2?position                  = null, Color?color = null, float scale = 1,
            DrawCallSortKey sortKey           = default(DrawCallSortKey),
            int characterSkipCount            = 0, int?characterLimit = null,
            float xOffsetOfFirstLine          = 0, float?lineBreakAtX = null,
            GlyphPixelAlignment alignToPixels = default(GlyphPixelAlignment),
            Dictionary <char, KerningAdjustment> kerningAdjustments = null,
            bool wordWrap = false, char wrapCharacter = '\0'
            )
        {
            var state = new StringLayoutEngine {
                position           = position,
                color              = color,
                scale              = scale,
                sortKey            = sortKey,
                characterSkipCount = characterSkipCount,
                characterLimit     = characterLimit,
                xOffsetOfFirstLine = xOffsetOfFirstLine,
                lineBreakAtX       = lineBreakAtX,
                alignToPixels      = alignToPixels,
                characterWrap      = lineBreakAtX.HasValue,
                wordWrap           = wordWrap,
                wrapCharacter      = wrapCharacter,
                buffer             = buffer.GetValueOrDefault(default(ArraySegment <BitmapDrawCall>))
            };
            var gs = new SpriteFontGlyphSource(font);

            state.Initialize();

            using (state) {
                var segment = state.AppendText(
                    gs, text, kerningAdjustments
                    );

                return(state.Finish());
            }
        }
Ejemplo n.º 2
0
 private MarkedStringAction ProcessMarkedString(ref AbstractString text, string id, ref RichTextLayoutState state, ref StringLayoutEngine layoutEngine)
 {
     if (text.TextEquals("quick"))
     {
         layoutEngine.overrideColor = Color.GreenYellow;
         text = "slow";
     }
     else if (text.TextEquals("rich substring"))
     {
         text = "<$[scale:2.0]b$[scale:1.66]i$[scale:1.33]g$[scale:1.0] rich substring>";
         return(MarkedStringAction.RichText);
     }
     return(default);