示例#1
0
        public override void SetFont(string fontFace, int fontHeight, string characterSet)
        {
            string fontName = string.Format("{0}-{1}", fontFace, fontHeight);

            if (!FontManager.Instance.ContainsKey(fontName))
            {
                FontManager.Instance.CreateFont(fontName, fontFace, fontHeight, 0, characterSet);
            }
            font = FontManager.Instance.GetFont(fontName);
        }
示例#2
0
        private void DrawText(string text, int offset, int count, Vector3 drawPos, Rect clipRect, TextStyle style)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Drawing '{0}' at [{1},{2}] clipped by {3}", text.Substring(offset, count), drawPos.x, drawPos.y, clipRect);
            }
            float      textZ    = drawPos.z - (int)SubLevel.Normal * GuiZSubLevelStep;
            float      shadowZ  = drawPos.z - (int)SubLevel.Shadow * GuiZSubLevelStep;
            float      bgZ      = drawPos.z - (int)SubLevel.Background * GuiZSubLevelStep;
            SimpleFont textFont = this.Font;
            float      x        = textFont.GetTextExtent(text, offset, count);
            float      y        = textFont.LineSpacing;

            if (clipRect != null)
            {
                if (drawPos.x > clipRect.Right || drawPos.x + x < clipRect.Left ||
                    drawPos.y > clipRect.Bottom || drawPos.y + y < clipRect.Top)
                {
                    // this line is entirely out of bounds - technically, the drop shadow
                    // could extend outside this area (as could the font), but I think
                    // that if we wouldn't have drawn the background for the text, we don't
                    // need to draw the text.
                    log.DebugFormat("text with dimensions ({4},{5}) fully clipped by rect [{0},{1} - {2},{3}]", clipRect.Left, clipRect.Top, clipRect.Right, clipRect.Bottom, x, y);
                    return;
                }
            }
            // Draw these on integer boundaries
            drawPos.x = (int)drawPos.x;
            drawPos.y = (int)drawPos.y;
            drawPos.z = textZ;
            ColorRect colorRect;

            if (style.bgEnabled)
            {
                colorRect = new ColorRect(style.bgColor);
                colorRect.SetAlpha(this.EffectiveAlpha);
                Rect bgRect = new Rect(drawPos.x, drawPos.x + x,
                                       drawPos.y, drawPos.y + y);
                bgImage.Draw(bgRect, bgZ, clipRect, colorRect);
            }
            colorRect = new ColorRect(style.textColor);
            colorRect.SetAlpha(this.EffectiveAlpha);
            textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect);
            if (style.shadowEnabled)
            {
                drawPos.x += shadowOffset.X;
                drawPos.y += shadowOffset.Y;
                drawPos.z  = shadowZ;
                colorRect  = new ColorRect(style.shadowColor);
                colorRect.SetAlpha(this.EffectiveAlpha);
                textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect);
            }
        }
示例#3
0
        protected override void DrawText(float z)
        {
            Rect       absRect  = GetVisibleTextArea();
            Rect       clipRect = absRect.GetIntersection(this.PixelRect);
            SimpleFont textFont = this.Font;

            // textColors.SetAlpha(EffectiveAlpha);

            Vector3 drawPos = new Vector3();

            drawPos.x = absRect.Left;
            drawPos.y = absRect.Top;
            drawPos.z = z;

            // int debug_count = 0;
            foreach (TextChunk chunk in textChunks)
            {
                // find the intersection of chunks and lines
                foreach (TextRange line in lines)
                {
                    if (line.end <= chunk.range.start)
                    {
                        // this line comes before the chunk - skip it
                        continue;
                    }
                    else if (line.start >= chunk.range.end)
                    {
                        // this line comes after the chunk, so we must be done
                        // with the chunk.
                        break;
                    }
                    // some portion of this line is in this chunk
                    int start = line.start > chunk.range.start ? line.start : chunk.range.start;
                    int end   = line.end > chunk.range.end ? chunk.range.end : line.end;
                    if (end <= start)
                    {
                        continue;
                    }
                    TextRange range = new TextRange(start, end);
                    PointF    pt    = font.GetOffset(text, lines, range.start, horzFormat, vertFormat, absRect.Width, absRect.Height, true);
                    drawPos.x = absRect.Left + pt.X;
                    drawPos.y = absRect.Top + pt.Y;
                    DrawText(text, start, end - start, drawPos, clipRect, chunk.style);
                    // debug_count++;
                }
            }
            // log.DebugFormat("Wrote {0} lines", debug_count);
        }
        public SimpleFont CreateFont(string name, FontFamily family, int height, FontStyle style, string characterSet)
        {
            SimpleFont rv = null;

            if (characterSet == null)
            {
                rv = new SimpleFont(name, family, height, style, (char)32, (char)127);
            }
            else
            {
                rv = new SimpleFont(name, family, height, style, characterSet);
            }
            // rv.Initialize(name, family, height, style);
            fonts[name] = rv;
            return(rv);
        }
 public override void SetFont(string fontFace, int fontHeight, string characterSet)
 {
     string fontName = string.Format("{0}-{1}", fontFace, fontHeight);
     if (!FontManager.Instance.ContainsKey(fontName))
         FontManager.Instance.CreateFont(fontName, fontFace, fontHeight, 0, characterSet);
     font = FontManager.Instance.GetFont(fontName);
 }
 public static List<TextRange> GetWrappedLines(SimpleFont font, List<TextRange> hardWrappedLines, string text, float width, bool nonSpaceWrap)
 {
     List<TextRange> lines = new List<TextRange>();
     foreach (TextRange range in hardWrappedLines) {
         // Does the whole line fit?
         if (font.GetTextExtent(text, range.start, range.Length) < width) {
             lines.Add(range);
         } else {
             int start = range.start;
             // loop for adding multiple lines for the one hard-break line
             while (start < range.end) {
                 float curWidth = 0;
                 TextRange curLine = new TextRange();
                 curLine.start = start;
                 // loop for adding words to the line
                 while (start < range.end) {
                     int wordEndIndex = 0;
                     int chunkEndIndex = 0;
                     // this method should get words.
                     // bounds.start will be the start of the word
                     // bounds.end will be after the end of the word with whitespace trimmed.
                     // chunkEndIndex is after the end of the word including trailing whitespace.
                     TextUtil.GetWordBounds(text, start, range.end, out wordEndIndex, out chunkEndIndex);
                     float wordWidth = font.GetTextExtent(text, start, wordEndIndex - start);
                     if (curWidth + wordWidth < width) {
                         // include the word
                         curLine.end = wordEndIndex;
                         curWidth += wordWidth;
                         // include the trailing space
                         curWidth += font.GetTextExtent(text, wordEndIndex, chunkEndIndex - wordEndIndex);
                         start = chunkEndIndex;
                     } else if (nonSpaceWrap && start == curLine.start) {
                         // FIXME - the one word didn't fit on this line -- deal with non-space wrap
                         Debug.Assert(false, "Still need to handle lines that don't break");
                     } else if (start == curLine.start) {
                         // We don't do non-space wrap, but the first word doesn't fit..
                         // We will have to pretend it does, so that we can make progress.
                         // include the word
                         curLine.end = wordEndIndex;
                         curWidth += wordWidth;
                         // include the trailing space
                         curWidth += font.GetTextExtent(text, wordEndIndex, chunkEndIndex - wordEndIndex);
                         start = chunkEndIndex;
                     } else {
                         // the word doesn't fit on this line, so I'm through with this line
                         curLine.end = start;
                         break;
                     }
                 }
                 lines.Add(curLine);
             }
         }
     }
     //Trace.TraceInformation("GetWrappedLines():");
     //foreach (TextRange range in lines)
     //    Trace.TraceInformation("  '{0}'", text.Substring(range.start, range.end - range.start));
     return lines;
 }
 public static List<TextRange> GetWrappedLines(SimpleFont font, string text, float width, bool nonSpaceWrap)
 {
     List<TextRange> hardWrappedLines = GetLines(text);
     return GetWrappedLines(font, hardWrappedLines, text, width, nonSpaceWrap);
 }
示例#8
0
        public static List <TextRange> GetWrappedLines(SimpleFont font, List <TextRange> hardWrappedLines, string text, float width, bool nonSpaceWrap)
        {
            List <TextRange> lines = new List <TextRange>();

            foreach (TextRange range in hardWrappedLines)
            {
                // Does the whole line fit?
                if (font.GetTextExtent(text, range.start, range.Length) < width)
                {
                    lines.Add(range);
                }
                else
                {
                    int start = range.start;
                    // loop for adding multiple lines for the one hard-break line
                    while (start < range.end)
                    {
                        float     curWidth = 0;
                        TextRange curLine  = new TextRange();
                        curLine.start = start;
                        // loop for adding words to the line
                        while (start < range.end)
                        {
                            int wordEndIndex  = 0;
                            int chunkEndIndex = 0;
                            // this method should get words.
                            // bounds.start will be the start of the word
                            // bounds.end will be after the end of the word with whitespace trimmed.
                            // chunkEndIndex is after the end of the word including trailing whitespace.
                            TextUtil.GetWordBounds(text, start, range.end, out wordEndIndex, out chunkEndIndex);
                            float wordWidth = font.GetTextExtent(text, start, wordEndIndex - start);
                            if (curWidth + wordWidth < width)
                            {
                                // include the word
                                curLine.end = wordEndIndex;
                                curWidth   += wordWidth;
                                // include the trailing space
                                curWidth += font.GetTextExtent(text, wordEndIndex, chunkEndIndex - wordEndIndex);
                                start     = chunkEndIndex;
                            }
                            else if (nonSpaceWrap && start == curLine.start)
                            {
                                // FIXME - the one word didn't fit on this line -- deal with non-space wrap
                                Debug.Assert(false, "Still need to handle lines that don't break");
                            }
                            else if (start == curLine.start)
                            {
                                // We don't do non-space wrap, but the first word doesn't fit..
                                // We will have to pretend it does, so that we can make progress.
                                // include the word
                                curLine.end = wordEndIndex;
                                curWidth   += wordWidth;
                                // include the trailing space
                                curWidth += font.GetTextExtent(text, wordEndIndex, chunkEndIndex - wordEndIndex);
                                start     = chunkEndIndex;
                            }
                            else
                            {
                                // the word doesn't fit on this line, so I'm through with this line
                                curLine.end = start;
                                break;
                            }
                        }
                        lines.Add(curLine);
                    }
                }
            }
            //Trace.TraceInformation("GetWrappedLines():");
            //foreach (TextRange range in lines)
            //    Trace.TraceInformation("  '{0}'", text.Substring(range.start, range.end - range.start));
            return(lines);
        }
示例#9
0
        public static List <TextRange> GetWrappedLines(SimpleFont font, string text, float width, bool nonSpaceWrap)
        {
            List <TextRange> hardWrappedLines = GetLines(text);

            return(GetWrappedLines(font, hardWrappedLines, text, width, nonSpaceWrap));
        }
 public SimpleFont CreateFont(string name, FontFamily family, int height, FontStyle style, string characterSet)
 {
     SimpleFont rv = null;
     if (characterSet == null)
         rv = new SimpleFont(name, family, height, style, (char)32, (char)127);
     else
         rv = new SimpleFont(name, family, height, style, characterSet);
     // rv.Initialize(name, family, height, style);
     fonts[name] = rv;
     return rv;
 }