示例#1
0
        /// <summary>Resets the clipping boundary back to the whole screen.</summary>
        public void ResetBoundary()
        {
            // Update viewport:
            if (InWorldUI != null)
            {
                ScreenViewport.Width  = InWorldUI.pixelWidth;
                ScreenViewport.Height = InWorldUI.pixelHeight;
            }
            else
            {
                ScreenViewport.Width  = ScreenInfo.ScreenX;
                ScreenViewport.Height = ScreenInfo.ScreenY;
            }

            // Apply screen viewport as the root one:
            Viewport = ScreenViewport;

            if (InWorldUI != null || ScreenClip)
            {
                ClippingBoundary.Set(0, 0, Viewport.Width, Viewport.Height);
            }
            else
            {
                ClippingBoundary.Set(-80000, -80000, 160000, 160000);
            }
        }
        /// <summary>Draws the given Emoji character.</summary>
        public void DrawEmoji(Glyph character, ref float left, Renderman renderer)
        {
            if (!character.Image.Loaded)
            {
                return;
            }

            BoxRegion screenRegion = renderer.CurrentRegion;
            float     top          = renderer.TopOffset;

            // It's an image (e.g. Emoji).
            AtlasLocation locatedAt = RequireImage(character.Image);

            if (locatedAt == null)
            {
                // It needs to be isolated. Big emoji image!
                return;
            }

            if (CharacterProviders.FixHeight)
            {
                // Set the region:
                screenRegion.Set(left, top, locatedAt.Width, locatedAt.Height);
            }
            else
            {
                screenRegion.Set(left, top, FontSize, FontSize);
            }

            if (screenRegion.Overlaps(renderer.ClippingBoundary))
            {
                // Ensure correct batch:
                renderer.SetupBatch(this, locatedAt.Atlas, null);

                // If the two overlap, this means it's actually visible.
                MeshBlock block = Add(renderer);

                // Set it's colour:
                block.SetColour(renderer.ColorOverlay);

                // And clip our meshblock to fit within boundary:
                block.TextUV = null;

                block.ImageUV = block.SetClipped(renderer.ClippingBoundary, screenRegion, renderer, RenderData.computedStyle.ZIndex, locatedAt, block.ImageUV);

                block.Done(renderer.Transform);
            }

            left += (character.AdvanceWidth) + LetterSpacing;

            if (character.Charcode == (int)' ')
            {
                left += WordSpacing;
            }
        }
        /// <summary>Draws a character with x-inverted UV's. Used for rendering e.g. "1 < 2" in right-to-left.</summary>
        protected virtual void DrawInvertCharacter(ref float left, Renderman renderer)
        {
            BoxRegion screenRegion = renderer.CurrentRegion;
            float     top          = renderer.TopOffset;
            int       index        = renderer.CharacterIndex;

            Glyph character = Characters[index];

            if (character == null)
            {
                return;
            }

            if (Kerning != null)
            {
                left += Kerning[index] * FontSize;
            }

            // Get atlas location (if it has one):
            AtlasLocation locatedAt = character.Location;

            if (locatedAt != null)
            {
                // We're on the atlas!

                float y = top + renderer.TextAscender - ((character.Height + character.MinY) * FontSize);

                float scaleFactor = renderer.TextScaleFactor;

                screenRegion.Set(left + (character.LeftSideBearing * FontSize), y, locatedAt.Width * scaleFactor, locatedAt.Height * scaleFactor);

                if (screenRegion.Overlaps(renderer.ClippingBoundary))
                {
                    // True if this character is visible.

                    // Ensure correct batch:
                    renderer.SetupBatch(this, null, locatedAt.Atlas);

                    MeshBlock block = Add(renderer);
                    block.SetColour(renderer.FontColour);
                    block.ApplyOutline();

                    // And clip our meshblock to fit within boundary:

                    // Clip our meshblock to fit within boundary:
                    if (Background != null && Isolated)
                    {
                        // Setup the batch material for this char:
                        Material imageMaterial = Background.Image.Contents.GetImageMaterial(renderer.CurrentShaderSet.Normal);
                        SetBatchMaterial(renderer, imageMaterial);

                        // Reapply text atlas:
                        renderer.CurrentBatch.SetFontAtlas(locatedAt.Atlas);

                        // Apply the image UV's (we're always isolated so these can tile by going out of range):
                        block.ImageUV = block.SetClipped(
                            renderer.ClippingBoundary,
                            screenRegion,
                            renderer,
                            RenderData.computedStyle.ZIndex,
                            Background.ImageLocation,
                            block.ImageUV
                            );
                    }
                    else
                    {
                        block.ImageUV = null;
                    }

                    UVBlock uvs = block.SetClipped(renderer.ClippingBoundary, screenRegion, renderer, RenderData.computedStyle.ZIndex, locatedAt, block.TextUV);

                    if (uvs.Shared)
                    {
                        uvs = new UVBlock(uvs);
                    }

                    // Invert along X:
                    float temp = uvs.MinX;
                    uvs.MinX = uvs.MaxX;
                    uvs.MaxX = temp;

                    // Assign to the block:
                    block.TextUV = uvs;

                    block.Done(renderer.Transform);
                }
            }

            left += (character.AdvanceWidth * FontSize) + LetterSpacing;

            if (character.Charcode == (int)' ')
            {
                left += WordSpacing;
            }
        }
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            if (Characters == null || Characters.Length == 0)
            {
                // Not ready yet or nothing here.
                return;
            }

            // Get indices:
            int startIndex = box.TextStart;
            int maxIndex   = box.TextEnd;

            if (startIndex >= maxIndex)
            {
                // No text selected.
                return;
            }

            // If we've got a background, set it up now:
            if (Background != null)
            {
                Background.Layout(box, renderer);
            }

            // Get the font colour:
            Color fontColour = BaseColour * renderer.ColorOverlay;

            // The blocks we allocate here come from FontToDraw.
            // They use the same renderer and same layout service, but just a different mesh.
            // This is to enable potentially very large font atlases with multiple fonts.

            float top  = box.Y + box.StyleOffsetTop + LineHeightOffset;
            float left = box.X + box.StyleOffsetLeft;

            // Should we auto-alias the text?

            // Note that this property "drags" to following elements which is correct.
            // We don't really want to break batching chains for aliasing.

            if (Alias == float.MaxValue)
            {
                // Yep!

                // Get quick ref to constants set:
                float[] hints = Fonts.AutoAliasHints;

                if (FontSize <= hints[0])
                {
                    renderer.FontAliasingBottom = hints[1];
                    renderer.FontAliasingTop    = hints[2];
                }
                else if (FontSize >= hints[12])
                {
                    renderer.FontAliasingBottom = hints[13];
                    renderer.FontAliasingTop    = hints[14];
                }
                else
                {
                    float minBottom;
                    float minTop;
                    float deltaSize;
                    float deltaBottom;
                    float deltaTop;
                    float relative;

                    // Note: Just about everything here is constant. Inlined for speed.

                    // Interpolate:
                    if (FontSize <= hints[3])
                    {
                        // Between 3 and 0.
                        minBottom   = hints[1];
                        minTop      = hints[2];
                        deltaSize   = hints[3] - hints[0];
                        deltaBottom = hints[4] - hints[1];
                        deltaTop    = hints[5] - hints[2];
                        relative    = (FontSize - hints[0]) / deltaSize;
                    }
                    else if (FontSize <= hints[6])
                    {
                        // Between 6 and 3.
                        minBottom   = hints[4];
                        minTop      = hints[5];
                        deltaSize   = hints[6] - hints[3];
                        deltaBottom = hints[7] - hints[4];
                        deltaTop    = hints[8] - hints[5];
                        relative    = (FontSize - hints[3]) / deltaSize;
                    }
                    else if (FontSize <= hints[9])
                    {
                        // Between 9 and 6.
                        minBottom   = hints[7];
                        minTop      = hints[8];
                        deltaSize   = hints[9] - hints[6];
                        deltaBottom = hints[10] - hints[7];
                        deltaTop    = hints[11] - hints[8];
                        relative    = (FontSize - hints[6]) / deltaSize;
                    }
                    else
                    {
                        // Must be between 12 and 9.
                        minBottom   = hints[10];
                        minTop      = hints[11];
                        deltaSize   = hints[12] - hints[9];
                        deltaBottom = hints[13] - hints[10];
                        deltaTop    = hints[14] - hints[11];
                        relative    = (FontSize - hints[9]) / deltaSize;
                    }

                    // Note: Most of the above is constant. Inlined for speed.

                    renderer.FontAliasingBottom = (relative * deltaBottom) + minBottom;
                    renderer.FontAliasingTop    = (relative * deltaTop) + minTop;
                }
            }
            else
            {
                // Write aliasing:
                renderer.FontAliasingTop    = InfiniText.Fonts.OutlineLocation + Alias;
                renderer.FontAliasingBottom = InfiniText.Fonts.OutlineLocation - Alias;
            }

            if (!AllEmpty)
            {
                // Firstly, make sure the batch is using the right font texture.
                // This may generate a new batch if the font doesn't match the previous or existing font.

                // Get the full shape of the element:
                float width  = box.PaddedWidth;
                float height = box.PaddedHeight;
                float minY   = box.Y + box.Border.Top;
                float minX   = box.X + box.Border.Left;

                BoxRegion boundary = new BoxRegion(minX, minY, width, height);

                if (!boundary.Overlaps(renderer.ClippingBoundary))
                {
                    if (Visible)
                    {
                        SetVisibility(false);
                    }

                    return;
                }
                else if (!Visible)
                {
                    // ImageLocation will allocate here if it's needed.
                    SetVisibility(true);
                }
            }

            float     zIndex       = RenderData.computedStyle.ZIndex;
            BoxRegion screenRegion = new BoxRegion();

            // Update renderer with various text properties:
            renderer.CurrentRegion   = screenRegion;
            renderer.CurrentBox      = box;
            renderer.TopOffset       = top;
            renderer.TextScaleFactor = FontSize / Fonts.Rasteriser.ScalarX;
            renderer.TextAscender    = (FontToDraw.Ascender * FontSize);

            // First up, underline.
            if (TextLine != null)
            {
                // We have one. Locate it next.
                float lineWeight = (FontToDraw.StrikeSize * FontSize);
                float yOffset    = 0f;

                switch (TextLine.Type)
                {
                case TextDecorationLineMode.Underline:
                    yOffset = renderer.TextAscender + (lineWeight * 2f);
                    break;

                case TextDecorationLineMode.LineThrough:
                    yOffset = (FontToDraw.StrikeOffset * FontSize);
                    yOffset = renderer.TextAscender - yOffset;
                    break;

                case TextDecorationLineMode.Overline:
                    yOffset = (lineWeight * 2f);
                    break;
                }

                // Note: The integer rounding is required here to prevent underlines from alternating between
                // a thick line and a thin one as you scroll around.
                screenRegion.Set(left, (int)(top + yOffset), box.Width, lineWeight);

                if (screenRegion.Overlaps(renderer.ClippingBoundary))
                {
                    // This region is visible. Clip it:
                    screenRegion.ClipBy(renderer.ClippingBoundary);

                    if (TextLine.ColourOverride)
                    {
                        renderer.FontColour = TextLine.BaseColour * renderer.ColorOverlay;
                    }
                    else
                    {
                        renderer.FontColour = fontColour;
                    }

                    renderer.TextDepth = zIndex;

                    // Draw the underline now!
                    DrawUnderline(renderer);
                }
            }

            // Update font colour:
            renderer.FontColour = fontColour;

            // Next, render the characters.
            // If we're rendering from right to left, flip the punctuation over.

            switch (box.UnicodeBidi)
            {
            case UnicodeBidiMode.LeftwardsNormal:

                // Render the text from the last char backwards.
                for (int i = maxIndex - 1; i >= startIndex; i--)
                {
                    renderer.CharacterIndex = i;
                    DrawCharacter(ref left, renderer);
                }

                break;

            case UnicodeBidiMode.LeftwardsMirrored:

                // Render the characters with horizontally inverted uv's.

                for (int i = maxIndex - 1; i >= startIndex; i--)
                {
                    renderer.CharacterIndex = i;
                    DrawInvertCharacter(ref left, renderer);
                }

                break;

            case UnicodeBidiMode.RightwardsMirrored:

                // Render the characters with horizontally inverted uv's.

                for (int i = startIndex; i < maxIndex; i++)
                {
                    renderer.CharacterIndex = i;
                    DrawInvertCharacter(ref left, renderer);
                }

                break;

            default:

                // Draw it as is.

                for (int i = startIndex; i < maxIndex; i++)
                {
                    renderer.CharacterIndex = i;
                    DrawCharacter(ref left, renderer);
                }

                break;
            }
        }
示例#5
0
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            if (Image == null || !Image.Loaded)
            {
                return;
            }

            if (Clipping == BackgroundClipping.Text)
            {
                return;
            }

            if (Image.Contents.Isolate || renderer.RenderMode == RenderMode.NoAtlas || Filtering != FilterMode.Point || ForcedIsolate)
            {
                // SPA is an animation format, so we need a custom texture atlas to deal with it.
                // This is because the frames of any animation would quickly exhaust our global texture atlas.
                // So to get a custom atlas, we must isolate this property.
                Isolate();
            }
            else
            {
                // Reverse isolation, if we are isolated already:
                Include();
            }

            // Get the full shape of the element:

            float width;
            float height;
            float minX;
            float minY;

            if (renderer.ViewportBackground)
            {
                // Applying to whole background:
                BoxRegion viewport = renderer.Viewport;

                minY   = (int)viewport.Y;
                minX   = (int)viewport.X;
                width  = (int)viewport.Width;
                height = (int)viewport.Height;

                renderer.ViewportBackground = false;
            }
            else
            {
                width  = (int)(box.PaddedWidth);
                height = (int)(box.PaddedHeight);
                minY   = (int)(box.Y + box.Border.Top);
                minX   = (int)(box.X + box.Border.Left);
            }

            if (width == 0 || height == 0)
            {
                if (Visible)
                {
                    SetVisibility(false);
                }
                return;
            }

            // Tell the image that the box has likely changed - this allows it to redraw (e.g. SVGs):
            float trueImageWidth;
            float trueImageHeight;

            Image.Contents.OnLayout(RenderData, box, out trueImageWidth, out trueImageHeight);

            BoxRegion boundary = new BoxRegion(minX, minY, width, height);

            if (!boundary.Overlaps(renderer.ClippingBoundary))
            {
                if (Visible)
                {
                    SetVisibility(false);
                }

                return;
            }
            else if (!Visible)
            {
                // ImageLocation will allocate here if it's needed.
                SetVisibility(true);
            }

            boundary.ClipBy(renderer.ClippingBoundary);

            // Texture time - get it's location on that atlas:
            AtlasLocation locatedAt = ImageLocation;

            if (locatedAt == null)
            {
                // We're not using the atlas here.

                if (!Isolated)
                {
                    Isolate();
                }

                locatedAt = new AtlasLocation(trueImageWidth, trueImageHeight);
            }

            // Isolation is all done - safe to setup the batch now:
            renderer.SetupBatch(this, locatedAt.Atlas, null);

            // Great - Use locatedAt.Width/locatedAt.Height - this removes any risk of overflowing into some other image.

            int   imageCountX = 1;
            int   imageCountY = 1;
            float imageWidth  = trueImageWidth * RenderData.ValueScale;
            float imageHeight = trueImageHeight * RenderData.ValueScale;
            bool  autoX       = false;
            bool  autoY       = false;

            if (SizeX != null)
            {
                if (SizeX.IsAuto)
                {
                    autoX = true;
                }
                else
                {
                    imageWidth = SizeX.GetDecimal(RenderData, Css.Properties.BackgroundSize.GlobalPropertyX);
                }
            }

            if (SizeY != null)
            {
                if (SizeY.IsAuto)
                {
                    autoY = true;
                }
                else
                {
                    imageHeight = SizeY.GetDecimal(RenderData, Css.Properties.BackgroundSize.GlobalPropertyY);
                }
            }

            if (autoX)
            {
                imageWidth = imageHeight * trueImageWidth / trueImageHeight;
            }
            else if (autoY)
            {
                imageHeight = imageWidth * trueImageHeight / trueImageWidth;
            }

            // offsetX and offsetY are the images position offset from where it should be (e.g. x of -200 means it's 200px left)

            // Apply the offset origin:
            float offsetX = OffsetOriginX * (width - imageWidth);
            float offsetY = OffsetOriginY * (height - imageHeight);

            float offset;

            // Resolve the offset values, if there is any:
            if (OffsetX != null)
            {
                offset = OffsetX.GetDecimal(RenderData, ValueAxis.X);

                if (OffsetOriginX == 1f)
                {
                    offsetX -= offset;
                }
                else
                {
                    offsetX += offset;
                }
            }

            if (OffsetY != null)
            {
                offset = OffsetY.GetDecimal(RenderData, ValueAxis.Y);

                if (OffsetOriginY == 1f)
                {
                    offsetY -= offset;
                }
                else
                {
                    offsetY += offset;
                }
            }

            if (RepeatX)
            {
                // Get the rounded up number of images:
                imageCountX = (int)Math.Ceiling(width / imageWidth);

                if (offsetX != 0)
                {
                    // If we have an offset, another image is introduced.
                    imageCountX++;
                }
            }

            if (RepeatY)
            {
                // Get the rounded up number of images:
                imageCountY = (int)Math.Ceiling(height / imageHeight);
                if (offsetY != 0)
                {
                    // If we have an offset, another image is introduced.
                    imageCountY++;
                }
            }

            float blockX = minX + offsetX;
            float blockY = minY + offsetY;

            if (RepeatX && offsetX > 0)
            {
                // We're repeating and the image is offset by a +ve number.
                // This means a small gap, OffsetX px wide, is open on this left side.
                // So to fill it, we need to offset this first image by a much bigger number - the value imageWidth-OffsetX.
                blockX -= (imageWidth - offsetX);
                // This results in the first image having OffsetX pixels exposed in the box - this is what we want.
            }

            if (RepeatY && offsetY > 0)
            {
                // Similar thing to above:
                blockY -= (imageHeight - offsetY);
            }

            BoxRegion screenRegion = new BoxRegion();

            bool  first  = true;
            float startX = blockX;
            Color colour = renderer.ColorOverlay;
            float zIndex = (RenderData.computedStyle.ZIndex - 0.003f);

            Transformation transform = renderer.Transform;

            for (int y = 0; y < imageCountY; y++)
            {
                for (int x = 0; x < imageCountX; x++)
                {
                    // Draw at blockX/blockY.
                    screenRegion.Set(blockX, blockY, imageWidth, imageHeight);

                    if (screenRegion.Overlaps(boundary))
                    {
                        // If the two overlap, this means it's actually visible.
                        MeshBlock block = Add(renderer);

                        if (first)
                        {
                            first = false;

                            if (Isolated)
                            {
                                // Set current material:
                                SetBatchMaterial(renderer, Image.Contents.GetImageMaterial(renderer.CurrentShaderSet.Isolated));
                            }
                        }

                        // Set its colour:
                        block.SetColour(colour);

                        // And clip our meshblock to fit within boundary:
                        block.TextUV  = null;
                        block.ImageUV = block.SetClipped(boundary, screenRegion, renderer, zIndex, locatedAt, block.ImageUV);

                        block.Done(transform);
                    }

                    blockX += imageWidth;
                }
                blockX  = startX;
                blockY += imageHeight;
            }
        }
        internal override void Layout(LayoutBox box, Renderman renderer)
        {
            // Dimensions:
            float width  = box.Width;
            float height = box.Height;

            if (Renderer == null)
            {
                // Create the FWUI now:
                Renderer = new FlatWorldUI("#Internal-PowerUI-Raster-" + RasterID, (int)width, (int)height);
                RasterID++;

                if (Filter != null)
                {
                    // Set source:
                    Filter.Set("source0", Renderer.Texture);
                }

                // Grab the output texture:
                Output = Renderer.Texture;
            }

            // Does the given renderer belong to the worldUI?
            if (renderer == Renderer.Renderer)
            {
                // Yes! We're actually drawing the element.

                return;
            }

            // Next we'll draw the rastered image.
            // It's essentially just the output from the renderer.

            // Get the top left inner corner (inside margin and border):
            float top  = box.Y;
            float left = box.X;

            // Update the FlatWorldUI next:
            UpdateRenderer(box, width, height);

            // Always isolated:
            Isolate();

            // Make sure the renderer stalls and doesn't draw anything else of this element or its kids.
            renderer.StallStatus = 2;

            // Setup boundary:
            BoxRegion boundary = new BoxRegion(left, top, width, height);

            if (!boundary.Overlaps(renderer.ClippingBoundary))
            {
                if (Visible)
                {
                    SetVisibility(false);
                }

                return;
            }
            else if (!Visible)
            {
                // ImageLocation will allocate here if it's needed.
                SetVisibility(true);
            }

            // Texture time - get its location on that atlas:
            if (LocatedAt == null)
            {
                LocatedAt = new AtlasLocation(width, height);
            }
            else
            {
                // Dimensions changed?
                int w = (int)width;
                int h = (int)height;

                if (LocatedAt.Width != w || LocatedAt.Height != h)
                {
                    // Update it:
                    LocatedAt.UpdateFixed(width, height);
                }
            }

            boundary.ClipBy(renderer.ClippingBoundary);

            // Ensure we have a batch:
            renderer.SetupBatch(this, null, null);

            if (Material == null)
            {
                // Create the material now using the isolated shader:
                Material = new Material(renderer.CurrentShaderSet.Isolated);

                // Hook up the output:
                Material.SetTexture("_MainTex", Output);
            }

            // Allocate the block:
            MeshBlock block = Add(renderer);

            // Set current material:
            SetBatchMaterial(renderer, Material);

            // Set the (overlay) colour:
            block.SetColour(renderer.ColorOverlay);
            block.TextUV = null;

            // Z-index (same as a background-image):
            float zIndex = (RenderData.computedStyle.ZIndex - 0.003f);

            BoxRegion screenRegion = new BoxRegion();

            screenRegion.Set(left, top, width, height);

            // Setup the block:
            block.ImageUV = block.SetClipped(boundary, screenRegion, renderer, zIndex, LocatedAt, block.ImageUV);

            // Flush it:
            block.Done(renderer.Transform);
        }
示例#7
0
        /// <summary>Draws a character and advances the pen onwards.</summary>
        protected virtual void DrawCharacter(ref float left, Renderman renderer)
        {
            BoxRegion screenRegion = renderer.CurrentRegion;
            Color     fontColour   = renderer.FontColour;
            float     top          = renderer.TopOffset;
            int       index        = renderer.CharacterIndex;

            Glyph character = Text.Characters[index];

            if (character == null)
            {
                return;
            }

            if (Text.Kerning != null)
            {
                left += Text.Kerning[index] * Text.FontSize;
            }

            AtlasLocation locatedAt;

            if (character.Image != null)
            {
                DrawEmoji(character, ref left, renderer);
                return;
            }

            // Get atlas location:
            locatedAt = character.Location;

            // Does this character have a visual glyph? E.g. a space does not.
            if (locatedAt != null)
            {
                float y = top + renderer.TextAscender - ((character.Height + character.MinY) * Text.FontSize);

                float scaleFactor = renderer.TextScaleFactor;

                screenRegion.Set(left + (character.LeftSideBearing * Text.FontSize), y, locatedAt.Width * scaleFactor, locatedAt.Height * scaleFactor);

                if (screenRegion.Overlaps(renderer.ClippingBoundary))
                {
                    // True if this character is visible.

                    // Ensure correct batch:
                    renderer.SetupBatch(this, null, locatedAt.Atlas);

                    MeshBlock block = Add(renderer);
                    block.SetColour(fontColour);
                    block.ApplyOutline();

                    // And clip our meshblock to fit within boundary:
                    block.ImageUV = null;
                    block.TextUV  = block.SetClipped(renderer.ClippingBoundary, screenRegion, renderer, RenderData.computedStyle.ZIndex, locatedAt, block.TextUV);

                    block.Done(renderer.Transform);
                }
            }

            left += (character.AdvanceWidth * Text.FontSize) + Text.LetterSpacing;

            if (character.Charcode == (int)' ')
            {
                left += Text.WordSpacing;
            }
        }
示例#8
0
        /// <summary>Draws a character with x-inverted UV's. Used for rendering e.g. "1 < 2" in right-to-left.</summary>
        protected virtual void DrawInvertCharacter(ref float left, Renderman renderer)
        {
            BoxRegion screenRegion = renderer.CurrentRegion;
            float     top          = renderer.TopOffset;
            int       index        = renderer.CharacterIndex;

            Glyph character = Text.Characters[index];

            if (character == null)
            {
                return;
            }

            if (Text.Kerning != null)
            {
                left += Text.Kerning[index] * Text.FontSize;
            }

            // Get atlas location (if it has one):
            AtlasLocation locatedAt = character.Location;

            if (locatedAt != null)
            {
                // We're on the atlas!

                float y = top + renderer.TextAscender - ((character.Height + character.MinY) * Text.FontSize);

                float scaleFactor = renderer.TextScaleFactor;

                screenRegion.Set(left + (character.LeftSideBearing * Text.FontSize), y, locatedAt.Width * scaleFactor, locatedAt.Height * scaleFactor);

                if (screenRegion.Overlaps(renderer.ClippingBoundary))
                {
                    // True if this character is visible.

                    // Ensure correct batch:
                    renderer.SetupBatch(this, null, locatedAt.Atlas);

                    MeshBlock block = Add(renderer);
                    block.SetColour(renderer.FontColour);
                    block.ApplyOutline();

                    // And clip our meshblock to fit within boundary:
                    block.ImageUV = null;
                    UVBlock uvs = block.SetClipped(renderer.ClippingBoundary, screenRegion, renderer, RenderData.computedStyle.ZIndex, locatedAt, block.TextUV);

                    if (uvs.Shared)
                    {
                        uvs = new UVBlock(uvs);
                    }

                    // Invert along X:
                    float temp = uvs.MinX;
                    uvs.MinX = uvs.MaxX;
                    uvs.MaxX = temp;

                    // Assign to the block:
                    block.TextUV = uvs;

                    block.Done(renderer.Transform);
                }
            }

            left += (character.AdvanceWidth * Text.FontSize) + Text.LetterSpacing;

            if (character.Charcode == (int)' ')
            {
                left += Text.WordSpacing;
            }
        }