Пример #1
0
        public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
        {
            // string format
            StringFormat sf = new StringFormat();

            switch (hAlignment)
            {
            case HAlignment.HA_RIGHT:
                sf.LineAlignment = StringAlignment.Far;
                break;

            case HAlignment.HA_CENTER:
                sf.LineAlignment = StringAlignment.Center;
                break;

            case HAlignment.HA_LEFT:
                sf.LineAlignment = StringAlignment.Near;
                break;

            default:
                throw new Exception("Unknown horizontal alignment");
            }
            switch (vAlignment)
            {
            case VAlignment.VA_BOTTOM:
                sf.Alignment = StringAlignment.Far;
                break;

            case VAlignment.VA_MIDDLE:
                sf.Alignment = StringAlignment.Center;
                break;

            case VAlignment.VA_TOP:
                sf.Alignment = StringAlignment.Near;
                break;

            default:
                throw new Exception("Unknown vertical alignment");
            }
            // font & brush
            Brush tb;

            switch (font)
            {
            case TextType.FT_COTATION:
                tb = new SolidBrush(System.Drawing.Color.FromArgb(0, 140, 0));
                break;

            default:
                throw new Exception("Unknown text type");
            }

            _gdiGraphics.TranslateTransform(ToPointF(pt).X, ToPointF(pt).Y);
            _gdiGraphics.RotateTransform(fAngle);

            // draw text
            _gdiGraphics.DrawString(text, ToFont(font), tb, new PointF(0, 0), sf);

            _gdiGraphics.ResetTransform();
        }
Пример #2
0
        public override void AddItem(MenuItem item, HAlignment alignment = DEFAULT_ITEM_HALIGNMENT)
        {
            MenuItems.Add(item);

            if (Alignment == BlazeraLib.Alignment.Vertical)
                ExtendedMainVBox.AddItem(item);
            else
                ExtendedMainHBox.AddItem(item);

            GetCurrentItem().CallOnSelection();
        }
Пример #3
0
        private static Excel.XlHAlign ToMsExcelHorizontalAlignment(HAlignment hAlign)
        {
            switch (hAlign)
            {
            case HAlignment.Center:
                return(Excel.XlHAlign.xlHAlignCenter);

            case HAlignment.Left:
                return(Excel.XlHAlign.xlHAlignLeft);

            case HAlignment.Right:
                return(Excel.XlHAlign.xlHAlignRight);

            default:
                return(Excel.XlHAlign.xlHAlignLeft);
            }
        }
Пример #4
0
 public RCell()
 {
     CellType     = CellType.ctData;
     RowSpan      = 1;
     ColSpan      = 1;
     Row          = 0;
     Col          = 0;
     HAlign       = HAlignment.NotSet;
     VAlign       = VAlignment.NotSet;
     FontSize     = -1;
     IsItalic     = false;
     IsBold       = false;
     IsUnderline  = false;
     IsStrikeout  = false;
     IsTotal      = false;
     DrillActions = 0;
     CellIndex    = -1;
 }
Пример #5
0
        public void SetAlignment(Alignment labelAlign, Alignment lineAlign)
        {
            _labelAlign = labelAlign;

            if ((lineAlign & Alignment.Left) != 0)
            {
                _lineAlign = HAlignment.Left;
            }
            else if ((lineAlign & Alignment.Right) != 0)
            {
                _lineAlign = HAlignment.Right;
            }
            else
            {
                _lineAlign = HAlignment.Center;
            }

            Invalidate();
        }
Пример #6
0
        /// <summary>
        /// Метод устанавливающий Горизонтальное выравнивание текста в ячейке
        /// </summary>
        /// <param name="cell">Ячейка</param>
        /// <param name="halign">Энум с типами выравнивания</param>
        public static void SetCellHAlignment(Cell cell, HAlignment halign)
        {
            if (workSheet != null)
            {
                switch (halign)
                {
                case HAlignment.Left:
                    workSheet.Cells[cell.Row, cell.Column].HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                    break;

                case HAlignment.Center:
                    workSheet.Cells[cell.Row, cell.Column].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                    break;

                case HAlignment.Right:
                    workSheet.Cells[cell.Row, cell.Column].HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
                    break;
                }
            }
        }
Пример #7
0
        public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
        {
            int alignment = 0;

            switch (hAlignment)
            {
            case HAlignment.VA_CENTER: alignment = PdfContentByte.ALIGN_CENTER; break;

            case HAlignment.VA_LEFT:   alignment = PdfContentByte.ALIGN_LEFT;   break;

            case HAlignment.VA_RIGHT:  alignment = PdfContentByte.ALIGN_RIGHT;  break;

            default: break;
            }

            float fontSize = FontSize(font);
            float fontRise = 0.0f;

            switch (vAlignment)
            {
            case VAlignment.VA_BOTTOM: fontRise = 0.5f; break;

            case VAlignment.VA_MIDDLE: fontRise = 0.0f * fontSize; break;

            case VAlignment.VA_TOP: fontRise = -0.5f * fontSize; break;

            default: break;
            }

            _cb.BeginText();
            BaseFont bf = ToBaseFont(font);

            _cb.SetTextRise(fontRise);
            _cb.SetTextMatrix(1.0f, 0.0f, 0.0f, 1.0f, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f / 72.0f);
            _cb.ShowTextAligned(alignment, text, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f / 72.0f, 0.0f);
            _cb.EndText();
        }
Пример #8
0
 public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
 {
     XStringFormat format = new XStringFormat();
     switch (hAlignment)
     {
         case HAlignment.HA_CENTER: format.Alignment = XStringAlignment.Center; break;
         case HAlignment.HA_LEFT: format.Alignment = XStringAlignment.Near; break;
         case HAlignment.HA_RIGHT: format.Alignment = XStringAlignment.Far; break;
         default: break;
     }
     switch (vAlignment)
     {
         case VAlignment.VA_BOTTOM: format.LineAlignment = XLineAlignment.Far; break;
         case VAlignment.VA_MIDDLE: format.LineAlignment = XLineAlignment.Center; break;
         case VAlignment.VA_TOP: format.LineAlignment = XLineAlignment.Near; break;
         default: break;
     }
     this.pdfGfx.DrawString(
         text
         , ToFont(font)
         , LineTypeToPdfBrush(PicGraphics.LT.LT_COTATION)
         , new XPoint(DX(pt.X), DY(pt.Y))
         , format);
 }
Пример #9
0
        public virtual void AddItem(MenuItem item, HAlignment alignment = DEFAULT_ITEM_HALIGNMENT)
        {
            MenuItems.Add(item);

            if (Alignment == BlazeraLib.Alignment.Vertical)
            {
                VMainBox.AddItem(item, 0, alignment);
                VMainBox.Refresh();
            }
            else
            {
                HMainBox.AddItem(item, 0, VAlignment.Center);
                HMainBox.Refresh();
            }

            BackgroundShape = new RoundedRectangleShape(Dimension, 20F, 3F, Color.Blue, Color.Green, true);
            if (Alignment == BlazeraLib.Alignment.Vertical)
                VMainBox.Position = GetGlobalFromLocal(new Vector2f());
            else
                HMainBox.Position = GetGlobalFromLocal(new Vector2f());
            Refresh();

            GetCurrentItem().CallOnSelection();
        }
Пример #10
0
        public TextBounds AddMultiLineText(CharSequence str, float x, float y, float alignmentWidth, HAlignment alignment)
        {
            BitmapFont font = Font;

            int length = str.Length;
            Require(length);

            y += Font.Data.Ascent;
            float down = font.Data.Down;

            float maxWidth = 0;
            float startY = y;
            int start = 0;
            int numLines = 0;

            while (start < length) {
                int lineEnd = BitmapFont.IndexOf(str, '\n', start);
                float xOffset = 0;
                float lineWidth = 0;

                if (alignment != HAlignment.Left) {
                    lineWidth = font.GetBounds(str, start, lineEnd).Width;
                    xOffset = alignmentWidth - lineWidth;

                    if (alignment == HAlignment.Center)
                        xOffset /= 2;
                }

                lineWidth = AddToCache(str, x + xOffset, y, start, lineEnd);
                maxWidth = Math.Max(maxWidth, lineWidth);
                start = lineEnd + 1;
                y += down;
                numLines++;
            }

            return Bounds = new TextBounds() {
                Width = maxWidth,
                Height = font.Data.CapHeight + (numLines - 1) * font.Data.LineHeight,
            };
        }
Пример #11
0
 public Widget SetAlign(HAlignment ha, VAlignment va)
 {
     HAlignment = ha;
     VAlignment = va;
     return(this);
 }
Пример #12
0
        public void Render(SpriteList[] spriteLists, Vector2 area, HAlignment hAlign, VAlignment vAlign, int maxCharacters = -1)
        {
            if (overflowMode == TextOverflowMode.Minify)
            {
                FitTextInsideArea(area);
            }
            List <int> lines;
            float      totalHeight;
            float      longestLineWidth;

            PrepareWordsAndLines(area.X, area.Y, out lines, out totalHeight, out longestLineWidth);
            // Draw all lines.
            int   b = 0;
            float y = 0;
            int   c = 0;

            foreach (int count in lines)
            {
                // Calculate height and width of line in pixels.
                float maxHeight  = 0;
                float totalWidth = 0;
                for (int j = 0; j < count; j++)
                {
                    var word  = fittedWords[b + j];
                    var style = Styles[word.Style];
                    maxHeight = Math.Max(maxHeight, ScaleSize(style.Size + style.SpaceAfter));
                    if (word.IsTagBegin)
                    {
                        maxHeight = Math.Max(maxHeight, ScaleSize(style.ImageSize.Y + style.SpaceAfter));
                    }
                    var ch = texts[word.TextIndex].Length > 0 ? texts[word.TextIndex][word.Start] : 0;
                    if (!(j == count - 1 && (ch == ' ' || ch == '\n') && !IsBullet(word)))
                    {
                        totalWidth += word.Width;
                    }
                }
                // Calculate offset for horizontal alignment.
                var offset = new Vector2();
                if (hAlign == HAlignment.Right)
                {
                    offset.X = area.X - totalWidth;
                }
                else if (hAlign == HAlignment.Center)
                {
                    offset.X = ((area.X - totalWidth) * 0.5f).Round();
                }
                // Calculate offset for vertical alignment.
                if (vAlign == VAlignment.Bottom)
                {
                    offset.Y = area.Y - totalHeight;
                }
                else if (vAlign == VAlignment.Center)
                {
                    offset.Y = ((area.Y - totalHeight) * 0.5f).Round();
                }
                // Draw string.
                for (int j = 0; j < count; j++)
                {
                    var       word     = fittedWords[b + j];
                    var       t        = texts[word.TextIndex];
                    TextStyle style    = Styles[word.Style];
                    Vector2   position = new Vector2(word.X, y) + offset;
                    if (IsBullet(word))
                    {
                        if (maxCharacters >= 0 && c >= maxCharacters)
                        {
                            break;
                        }
                        var sz = style.ImageSize * scaleFactor;
                        spriteLists[word.Style].Add(
                            style.ImageTexture, Color4.White, position + new Vector2(0, (maxHeight - sz.Y) * 0.5f),
                            sz, Vector2.Zero, Vector2.One, tag: word.Style);
                        position.X += sz.X;
                        c++;
                    }
                    var yOffset = new Vector2(0, (maxHeight - ScaleSize(style.Size)) * 0.5f);
                    var font    = style.Font;
                    if (style.CastShadow)
                    {
                        for (int k = 0; k < (style.Bold ? 2 : 1); k++)
                        {
                            Renderer.DrawTextLine(
                                font, position + style.ShadowOffset + yOffset, t, style.ShadowColor, ScaleSize(style.Size),
                                word.Start, word.Length, font.Spacing + style.LetterSpacing, spriteLists[word.Style], tag: word.Style
                                );
                        }
                    }
                    int wordLength = word.Length;
                    if (maxCharacters >= 0)
                    {
                        if (c >= maxCharacters)
                        {
                            break;
                        }
                        wordLength = wordLength.Min(maxCharacters - c);
                    }
                    for (int k = 0; k < (style.Bold ? 2 : 1); k++)
                    {
                        Renderer.DrawTextLine(
                            font, position + yOffset, t, style.TextColor, ScaleSize(style.Size),
                            word.Start, wordLength, font.Spacing + style.LetterSpacing, spriteLists[word.Style], tag: word.Style
                            );
                    }
                    c += wordLength;
                }
                // Draw overlays
                for (int j = 0; j < count; j++)
                {
                    var       word  = fittedWords[b + j];
                    TextStyle style = Styles[word.Style];
                    if (IsOverlay(word))
                    {
                        int k = j + 1;
                        for (; k < count; k++)
                        {
                            if (fittedWords[b + k].IsTagBegin)
                            {
                                break;
                            }
                        }
                        k -= 1;
                        var font       = Styles[word.Style].Font;
                        var fontHeight = Styles[word.Style].Size;
                        var fontChar   = font.CharSource.Get(texts[word.TextIndex][word.Start], fontHeight);
                        if (fontChar == FontChar.Null)
                        {
                            continue;
                        }
                        float   scale   = fontChar.Height != 0.0f ? fontHeight / fontChar.Height : 0.0f;
                        Vector2 lt      = new Vector2(word.X + (word.X > 0 ? scale * Styles[word.Style].LetterSpacing : 0.0f), y) + offset;
                        Vector2 rb      = new Vector2(fittedWords[b + k].X + fittedWords[b + k].Width, y) + offset;
                        float   yOffset = (maxHeight - ScaleSize(style.ImageSize.Y)) * 0.5f;
                        spriteLists[word.Style].Add(style.ImageTexture, Color4.White, lt + new Vector2(0, yOffset),
                                                    rb - lt + new Vector2(0, style.ImageSize.Y),
                                                    Vector2.Zero, Vector2.One, tag: word.Style);
                        j = k;
                    }
                }
                y += maxHeight;
                b += count;
            }
        }
Пример #13
0
 public TextBounds SetWrappedText(CharSequence str, float x, float y, float wrapWidth, HAlignment alignment)
 {
     Clear();
     return(AddWrappedText(str, x, y, wrapWidth, alignment));
 }
Пример #14
0
        /// <summary>
        /// Метод устанавливающий Горизонтальное выравнивание текста в ячейке
        /// </summary>
        /// <param name="cell">Ячейка</param>
        /// <param name="halign">Энум с типами выравнивания</param>
        public static void SetCellHAlignment(Cell cell,HAlignment halign)
        {
            if (workSheet != null)
            {
                switch (halign)
                {
                    case HAlignment.Left:
                        workSheet.Cells[cell.Row, cell.Column].HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                        break;
                    case HAlignment.Center:
                        workSheet.Cells[cell.Row, cell.Column].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
                        break;
                    case HAlignment.Right:
                        workSheet.Cells[cell.Row, cell.Column].HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
                        break;
                }

            }
        }
Пример #15
0
 public TextBounds DrawWrapped(GdxSpriteBatch spriteBatch, string str, float x, float y, float wrapWidth, HAlignment alignment)
 {
     _workingSequence.Value = str;
     return(DrawWrapped(spriteBatch, _workingSequence, x, y, wrapWidth, alignment));
 }
Пример #16
0
        public TextBounds DrawWrapped(GdxSpriteBatch spriteBatch, CharSequence str, float x, float y, float wrapWidth, HAlignment alignment)
        {
            _cache.Clear();
            TextBounds bounds = _cache.AddWrappedText(str, x, y, wrapWidth, alignment);

            _cache.Draw(spriteBatch);
            return(bounds);
        }
Пример #17
0
 public TextBounds DrawMultiLine(GdxSpriteBatch spriteBatch, string str, float x, float y, float alignmentWidth, HAlignment alignment)
 {
     _workingSequence.Value = str;
     return(DrawMultiLine(spriteBatch, _workingSequence, x, y, alignmentWidth, alignment));
 }
Пример #18
0
        public TextBounds DrawMultiLine(GdxSpriteBatch spriteBatch, CharSequence str, float x, float y, float alignmentWidth, HAlignment alignment)
        {
            _cache.Clear();
            TextBounds bounds = _cache.AddMultiLineText(str, x, y, alignmentWidth, alignment);

            _cache.Draw(spriteBatch);
            return(bounds);
        }
Пример #19
0
Файл: Box.cs Проект: jpx/blazera
        public void AddItemFirst(Widget widget, UInt32 level = DEFAULT_ITEM_LEVEL, HAlignment hAlignement = DEFAULT_HALIGNMENT)
        {
            AddFirst(widget);

            Levels.Add(widget, level);

            HAlignments.Add(widget, hAlignement);
        }
Пример #20
0
Файл: Box.cs Проект: jpx/blazera
 public void AddItem(List<Widget> widgets, UInt32 level = DEFAULT_ITEM_LEVEL, HAlignment hAlignement = DEFAULT_HALIGNMENT)
 {
     foreach (Widget widget in widgets)
         AddItem(widget, level, hAlignement);
 }
Пример #21
0
        public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
        {
            int alignment = 0;
            switch (hAlignment)
            {
                case HAlignment.VA_CENTER: alignment = PdfContentByte.ALIGN_CENTER; break;
                case HAlignment.VA_LEFT:   alignment = PdfContentByte.ALIGN_LEFT;   break;
                case HAlignment.VA_RIGHT:  alignment = PdfContentByte.ALIGN_RIGHT;  break;
                default: break;
            }

            float fontSize = FontSize(font);
            float fontRise = 0.0f;
            switch (vAlignment)
            {
                case VAlignment.VA_BOTTOM: fontRise =0.5f; break;
                case VAlignment.VA_MIDDLE: fontRise = 0.0f * fontSize; break;
                case VAlignment.VA_TOP: fontRise = -0.5f * fontSize; break;
                default: break;
            }

            _cb.BeginText();
            BaseFont bf = ToBaseFont(font);
            _cb.SetTextRise(fontRise);
            _cb.SetTextMatrix(1.0f, 0.0f, 0.0f, 1.0f, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f/72.0f);
            _cb.ShowTextAligned(alignment, text, DX(pt.X), DY(pt.Y) - 1.0f * (bf.GetAscentPoint(text, fontSize) - bf.GetDescentPoint(text, fontSize)) * 25.4f / 72.0f, 0.0f);
            _cb.EndText();
        }
Пример #22
0
        public TextBounds AddMultiLineText(CharSequence str, float x, float y, float alignmentWidth, HAlignment alignment)
        {
            BitmapFont font = Font;

            int length = str.Length;

            Require(length);

            y += Font.Data.Ascent;
            float down = font.Data.Down;

            float maxWidth = 0;
            float startY   = y;
            int   start    = 0;
            int   numLines = 0;

            while (start < length)
            {
                int   lineEnd   = BitmapFont.IndexOf(str, '\n', start);
                float xOffset   = 0;
                float lineWidth = 0;

                if (alignment != HAlignment.Left)
                {
                    lineWidth = font.GetBounds(str, start, lineEnd).Width;
                    xOffset   = alignmentWidth - lineWidth;

                    if (alignment == HAlignment.Center)
                    {
                        xOffset /= 2;
                    }
                }

                lineWidth = AddToCache(str, x + xOffset, y, start, lineEnd);
                maxWidth  = Math.Max(maxWidth, lineWidth);
                start     = lineEnd + 1;
                y        += down;
                numLines++;
            }

            return(Bounds = new TextBounds()
            {
                Width = maxWidth,
                Height = font.Data.CapHeight + (numLines - 1) * font.Data.LineHeight,
            });
        }
Пример #23
0
        public BitmapText(IBitmapFont bitmapFont, IBrush brush, string text, TexcoordGenerationMode uMappingMode = TexcoordGenerationMode.FullBoundingBox, TexcoordGenerationMode vMappingMode = TexcoordGenerationMode.FullBoundingBox, HAlignment hAlignment = HAlignment.Middle, VAlignment vAlignment = VAlignment.Middle)
        {
            Transform = (ConstantMatrix) Matrix.Identity;
            Rectangle fullRect = bitmapFont.Measure(text);

            Vector3 centerOffset = Vector3.Zero;
            switch (hAlignment)
            {
                case HAlignment.Left:
                    centerOffset.X = 0;
                    break;

                case HAlignment.Middle:
                    centerOffset.X = fullRect.Width / 2f;
                    break;

                case HAlignment.Right:
                    centerOffset.X = fullRect.Width;
                    break;
            }

            switch (vAlignment)
            {
                case VAlignment.Top:
                    centerOffset.Y = 0;
                    break;

                case VAlignment.Middle:
                    centerOffset.Y = fullRect.Height / 2f;
                    break;

                case VAlignment.Bottom:
                    centerOffset.Y = fullRect.Height;

                    break;
            }

            _bitmapFont = bitmapFont as BitmapFont;
            var pageCount = _bitmapFont.PageLayers.Count;
            _text = text;
            Brush = brush;

            _textQuads = new IIndexedMesh[pageCount];

            var charactersByPage = (from char ch in text
                                   select new KeyValuePair<int, char>(_bitmapFont.Chars[ch].Page, ch)).ToMultiValueDictionary();

            var w = (float)_bitmapFont.ScaleW;
            var h = (float)_bitmapFont.ScaleH;
            var xPos = 0f;

            foreach (var kvp in charactersByPage)
            {
                var charCount = kvp.Value.Count;
                _textQuads[kvp.Key] = new IndexedMesh(charCount * 4, charCount * 6)
                                          {
                                              Brush = new TextBrush { TextLayer = _bitmapFont.PageLayers[kvp.Key], SubBrush = Brush }
                                          };
            }

            var vertexIndexCounts = (from i in Enumerable.Range(0, _bitmapFont.Pages.Count)
                                    select Tuple.Create(0, 0)).ToArray();

            foreach (var ch in text)
            {
                var ci = _bitmapFont.Chars[ch];

                var vertices = _textQuads[ci.Page].Vertices;
                var indices = _textQuads[ci.Page].Indices;

                var vertexCount = vertexIndexCounts[ci.Page].Item1;
                var indexCount = vertexIndexCounts[ci.Page].Item2;

                var saveVertexCount = vertexCount;

                Vector2 quadTopLeft;
                Vector2 quadTopRight;
                Vector2 quadBottomRight;
                Vector2 quadBottomLeft;

                var left = xPos + ci.XOffset;
                var top = 0f + ci.YOffset;

                switch (uMappingMode)
                {
                    case TexcoordGenerationMode.PerQuad:
                        quadTopLeft.X = 0f;
                        quadTopRight.X = 1f;
                        quadBottomRight.X = 1f;
                        quadBottomLeft.X = 0f;

                        break;

                    // These two modes are the same in this case
                    case TexcoordGenerationMode.FullBoundingBox:
                    case TexcoordGenerationMode.Unwrapped_Linear:
                        quadTopLeft.X = left / fullRect.Width;
                        quadTopRight.X = (left + ci.Width) / fullRect.Width;
                        quadBottomRight.X = (left + ci.Width) / fullRect.Width;
                        quadBottomLeft.X = left / fullRect.Width;

                        break;

                    default:
                        throw new NotSupportedException(string.Format("Unsupported texture mapping mode along X-Axis: {0}", uMappingMode));
                }

                switch (vMappingMode)
                {
                    case TexcoordGenerationMode.PerQuad:
                        quadTopLeft.Y = 0f;
                        quadTopRight.Y = 0f;
                        quadBottomRight.Y = 1f;
                        quadBottomLeft.Y = 1f;

                        break;

                    // These two modes are the same in this case
                    case TexcoordGenerationMode.FullBoundingBox:
                    case TexcoordGenerationMode.Unwrapped_Linear:
                        quadTopLeft.Y = top / fullRect.Height;
                        quadTopRight.Y = top / fullRect.Height;
                        quadBottomRight.Y = (top + ci.Height) / fullRect.Height;
                        quadBottomLeft.Y = (top + ci.Height) / fullRect.Height;

                        break;

                    default:
                        throw new NotSupportedException(string.Format("Unsupported texture mapping mode along Y-Axis: {0}", vMappingMode));
                }

                var topLeft = new Texcoords(quadTopLeft, new Vector2(ci.X / w, ci.Y / h));
                var topRight = new Texcoords(quadTopRight, new Vector2(((ci.X + ci.Width) / w), ci.Y / h));
                var bottomRight = new Texcoords(quadBottomRight, new Vector2(((ci.X + ci.Width) / w), ((ci.Y + ci.Height) / h)));
                var bottomLeft = new Texcoords(quadBottomLeft, new Vector2(ci.X / w, ((ci.Y + ci.Height) / h)));

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left - centerOffset.X, top - centerOffset.Y, 0f),
                    Texcoords = topLeft,
                    Color = Color.White
                };

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left + ci.Width - centerOffset.X, top - centerOffset.Y, 0f),
                    Texcoords = topRight,
                    Color = Color.White
                };

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left + ci.Width - centerOffset.X, top + ci.Height - centerOffset.Y, 0f),
                    Texcoords = bottomRight,
                    Color = Color.White
                };

                vertices[vertexCount++] = new Vertex
                {
                    Position = new Vector3(left - centerOffset.X, top + ci.Height - centerOffset.Y, 0f),
                    Texcoords = bottomLeft,
                    Color = Color.White
                };

                xPos += ci.XAdvance;

                indices[indexCount++] = (short)(saveVertexCount + 0);
                indices[indexCount++] = (short)(saveVertexCount + 1);
                indices[indexCount++] = (short)(saveVertexCount + 2);
                indices[indexCount++] = (short)(saveVertexCount + 0);
                indices[indexCount++] = (short)(saveVertexCount + 2);
                indices[indexCount++] = (short)(saveVertexCount + 3);

                vertexIndexCounts[ci.Page] = Tuple.Create(vertexCount, indexCount);
            }
        }
Пример #24
0
 public TextBounds AddWrappedText(string str, float x, float y, float wrapWidth, HAlignment alignment)
 {
     _workingSequence.Value = str;
     return(AddWrappedText(_workingSequence, x, y, wrapWidth, alignment));
 }
        internal static Bitmap GenerateValuesTape(Color positiveBackgroundColor, Color positiveForegroundColor,
                                                  Color negativeBackgroundColor, Color negativeForegroundColor,
                                                  int majorUnitInterval, int minorUnitInterval,
                                                  int majorUnitLineLengthInPixels, int minorUnitLineLengthInPixels,
                                                  bool negativeUnitsLabelled, int verticalSeparationBetweenTicksInPixels,
                                                  int scaleMaxVal, int scaleMinVal, int tapeWidthInPixels,
                                                  HAlignment ticsAlignment, int textPaddingPixels, Font majorUnitFont,
                                                  HAlignment textAlignment, bool negativeUnitsHaveNegativeSign,
                                                  IEnumerable <TapeEdgeColoringInstruction> coloringInstructions)
        {
            var tapeHeightInPixels = ((((scaleMaxVal - scaleMinVal) / minorUnitInterval) *
                                       verticalSeparationBetweenTicksInPixels));
            var positiveRange = scaleMaxVal;

            if (scaleMinVal > 0)
            {
                positiveRange = scaleMaxVal - scaleMinVal;
            }
            var positiveRegionHeightInPixels = ((positiveRange / minorUnitInterval) * verticalSeparationBetweenTicksInPixels);
            var negativeRange = Math.Abs(scaleMinVal);

            if (scaleMaxVal <= 0)
            {
                negativeRange = Math.Abs(scaleMaxVal - scaleMinVal);
            }
            if (scaleMinVal >= 0)
            {
                negativeRange = 0;
            }
            var negativeRegionHeightInPixels = (negativeRange / minorUnitInterval) * verticalSeparationBetweenTicksInPixels;
            var toReturn = new Bitmap(tapeWidthInPixels, tapeHeightInPixels, PixelFormat.Format16bppRgb565);

            toReturn.MakeTransparent();
            var positiveRegionBoundingRectangle = new Rectangle(new Point(0, 0),
                                                                new Size(toReturn.Width, positiveRegionHeightInPixels));
            var negativeRegionBoundingRectangle = new Rectangle(new Point(0, positiveRegionBoundingRectangle.Bottom),
                                                                new Size(toReturn.Width, negativeRegionHeightInPixels));
            var baseFontSize = majorUnitFont.SizeInPoints;

            using (var g = Graphics.FromImage(toReturn))
            {
                g.SmoothingMode     = SmoothingMode.AntiAlias;
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                var   origTransform         = g.Transform;
                Brush negativeBrush         = new SolidBrush(negativeBackgroundColor);
                Brush positiveBrush         = new SolidBrush(positiveBackgroundColor);
                var   blackPen              = new Pen(Color.Black);
                var   positiveForegroundPen = new Pen(positiveForegroundColor);
                var   negativeForegroundPen = new Pen(negativeForegroundColor);
                blackPen.Width = 2;
                Brush positiveForegroundBrush = new SolidBrush(positiveForegroundColor);
                Brush negativeForegroundBrush = new SolidBrush(negativeForegroundColor);

                //color negative portion of tape
                g.FillRectangle(negativeBrush, negativeRegionBoundingRectangle);
                //color positive portion of tape
                g.FillRectangle(positiveBrush, positiveRegionBoundingRectangle);

                //draw black line between negative and positive portion of tape
                g.DrawLineFast(blackPen, negativeRegionBoundingRectangle.Left, negativeRegionBoundingRectangle.Top,
                               negativeRegionBoundingRectangle.Right, negativeRegionBoundingRectangle.Top);
                if (scaleMaxVal >= 0)
                {
                    var positiveScaleMin = 0;
                    if (scaleMinVal > 0)
                    {
                        positiveScaleMin = scaleMinVal;
                    }
                    //draw positive unit marks and numbers
                    for (var i = positiveScaleMin; i <= scaleMaxVal; i += minorUnitInterval)
                    {
                        if ((i % minorUnitInterval == 0) && (i % majorUnitInterval != 0)) //this is a minor unit
                        {
                            //draw minor unit tick mark
                            if (ticsAlignment == HAlignment.Right)
                            {
                                //draw tick on the right hand side
                                g.DrawLineFast(positiveForegroundPen,
                                               positiveRegionBoundingRectangle.Right - minorUnitLineLengthInPixels,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels),
                                               positiveRegionBoundingRectangle.Right,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels));
                            }
                            else if (ticsAlignment == HAlignment.Left)
                            {
                                //draw tic on the left hand side
                                g.DrawLineFast(positiveForegroundPen,
                                               positiveRegionBoundingRectangle.Left,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels),
                                               positiveRegionBoundingRectangle.Left + minorUnitLineLengthInPixels,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels));
                            }
                            else if (ticsAlignment == HAlignment.Center)
                            {
                                //draw tic in the center
                                g.DrawLineFast(positiveForegroundPen,
                                               positiveRegionBoundingRectangle.Left +
                                               ((positiveRegionBoundingRectangle.Width - minorUnitLineLengthInPixels) / 2),
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels),
                                               positiveRegionBoundingRectangle.Left +
                                               ((positiveRegionBoundingRectangle.Width - minorUnitLineLengthInPixels) / 2) +
                                               minorUnitLineLengthInPixels,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels));
                            }
                        }
                        else if (i % majorUnitInterval == 0) //this is a major unit
                        {
                            //draw major unit tick mark
                            if (ticsAlignment == HAlignment.Right)
                            {
                                //draw tic on the right hand side
                                g.DrawLineFast(positiveForegroundPen,
                                               positiveRegionBoundingRectangle.Right - majorUnitLineLengthInPixels,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels),
                                               positiveRegionBoundingRectangle.Right,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels));
                            }
                            else if (ticsAlignment == HAlignment.Left)
                            {
                                //draw tic on the left hand side
                                g.DrawLineFast(positiveForegroundPen,
                                               positiveRegionBoundingRectangle.Left,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels),
                                               positiveRegionBoundingRectangle.Left + majorUnitLineLengthInPixels,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels));
                            }
                            else if (ticsAlignment == HAlignment.Center)
                            {
                                //draw tic in the center
                                g.DrawLineFast(positiveForegroundPen,
                                               positiveRegionBoundingRectangle.Left +
                                               ((positiveRegionBoundingRectangle.Width - majorUnitLineLengthInPixels) / 2),
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels),
                                               positiveRegionBoundingRectangle.Left +
                                               ((positiveRegionBoundingRectangle.Width - majorUnitLineLengthInPixels) / 2) +
                                               majorUnitLineLengthInPixels,
                                               positiveRegionBoundingRectangle.Bottom -
                                               (((i - positiveScaleMin) / minorUnitInterval) *
                                                verticalSeparationBetweenTicksInPixels));
                            }
                            var majorUnitTextBoundingRectangle = Rectangle.Empty;
                            if (ticsAlignment == HAlignment.Right)
                            {
                                //tic is on the right, so draw major unit text to left of tic
                                majorUnitTextBoundingRectangle = new Rectangle(
                                    new Point(0,
                                              positiveRegionBoundingRectangle.Bottom - (
                                                  ((i - positiveScaleMin) /
                                                   minorUnitInterval) *
                                                  verticalSeparationBetweenTicksInPixels
                                                  ) -
                                              verticalSeparationBetweenTicksInPixels
                                              ),
                                    new Size(
                                        positiveRegionBoundingRectangle.Width - majorUnitLineLengthInPixels -
                                        textPaddingPixels, verticalSeparationBetweenTicksInPixels * 2)
                                    );
                            }
                            else if (ticsAlignment == HAlignment.Left)
                            {
                                //tic is on the left, so draw major unit text to right of tic
                                majorUnitTextBoundingRectangle = new Rectangle(
                                    new Point(majorUnitLineLengthInPixels + textPaddingPixels,
                                              positiveRegionBoundingRectangle.Bottom - (
                                                  ((i - positiveScaleMin) /
                                                   minorUnitInterval) *
                                                  verticalSeparationBetweenTicksInPixels
                                                  ) -
                                              verticalSeparationBetweenTicksInPixels
                                              ),
                                    new Size(
                                        positiveRegionBoundingRectangle.Width - majorUnitLineLengthInPixels -
                                        textPaddingPixels, verticalSeparationBetweenTicksInPixels * 2)
                                    );
                            }
                            else if (ticsAlignment == HAlignment.Center)
                            {
                                var lineLength = majorUnitLineLengthInPixels;
                                if (majorUnitLineLengthInPixels == 0)
                                {
                                    lineLength = minorUnitLineLengthInPixels;
                                }
                                lineLength += 8;

                                majorUnitTextBoundingRectangle = new Rectangle(
                                    new Point((positiveRegionBoundingRectangle.Width - lineLength) / 2,
                                              positiveRegionBoundingRectangle.Bottom - (
                                                  ((i - positiveScaleMin) /
                                                   minorUnitInterval) *
                                                  verticalSeparationBetweenTicksInPixels
                                                  ) -
                                              verticalSeparationBetweenTicksInPixels
                                              ),
                                    new Size(lineLength, verticalSeparationBetweenTicksInPixels * 2)
                                    );
                            }

                            var majorUnitString = String.Empty;

                            if (i.ToString().Length > 3) // num >= 1000
                            {
                                majorUnitString = String.Format("{0:0000}", i);
                                majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize - 2,
                                                           majorUnitFont.Style);
                            }
                            else if (i.ToString().Length > 2) // num >= 100
                            {
                                majorUnitString = String.Format("{0:000}", i);
                                majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize,
                                                           majorUnitFont.Style);
                            }
                            else if (i.ToString().Length > 1) // num >= 10
                            {
                                majorUnitString = String.Format("{0:00}", i);
                                majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize,
                                                           majorUnitFont.Style);
                            }
                            else if (i.ToString().Length == 1) // num between 1 and 10
                            {
                                majorUnitString = String.Format("{0:0}", i);
                                majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize,
                                                           majorUnitFont.Style);
                            }
                            if (i == 0)
                            {
                                majorUnitString = "0";
                            }
                            var majorUnitStringFormat = new StringFormat(StringFormatFlags.NoWrap);
                            if (textAlignment == HAlignment.Right)
                            {
                                majorUnitStringFormat.Alignment = StringAlignment.Far;
                            }
                            else if (textAlignment == HAlignment.Left)
                            {
                                majorUnitStringFormat.Alignment = StringAlignment.Near;
                            }
                            else if (textAlignment == HAlignment.Center)
                            {
                                majorUnitStringFormat.Alignment = StringAlignment.Center;
                            }
                            majorUnitStringFormat.LineAlignment = StringAlignment.Center;
                            g.TranslateTransform(0, 2);
                            g.DrawStringFast(majorUnitString, majorUnitFont, positiveForegroundBrush,
                                             majorUnitTextBoundingRectangle, majorUnitStringFormat);
                            g.Transform = origTransform;
                        } //end else
                    }     //end for
                }
                if (scaleMinVal <= 0)
                {
                    //draw negative unit marks and numbers
                    for (var i = 0 - minorUnitInterval; i >= scaleMinVal; i -= minorUnitInterval)
                    {
                        if ((i % minorUnitInterval == 0) && (i % majorUnitInterval != 0)) //this is a minor unit
                        {
                            if (ticsAlignment == HAlignment.Right)
                            {
                                //draw minor unit tic mark on right hand side
                                g.DrawLineFast(negativeForegroundPen,
                                               negativeRegionBoundingRectangle.Right - minorUnitLineLengthInPixels,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels),
                                               negativeRegionBoundingRectangle.Right,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels)
                                               );
                            }
                            else if (ticsAlignment == HAlignment.Left)
                            {
                                //draw minor unit tic mark on left hand side
                                g.DrawLineFast(negativeForegroundPen,
                                               negativeRegionBoundingRectangle.Left,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels),
                                               negativeRegionBoundingRectangle.Left + minorUnitLineLengthInPixels,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels)
                                               );
                            }
                            else if (ticsAlignment == HAlignment.Center)
                            {
                                //draw minor unit tic mark in center
                                g.DrawLineFast(negativeForegroundPen,
                                               negativeRegionBoundingRectangle.Left +
                                               ((negativeRegionBoundingRectangle.Width - minorUnitLineLengthInPixels) / 2),
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels),
                                               negativeRegionBoundingRectangle.Left +
                                               ((negativeRegionBoundingRectangle.Width - minorUnitLineLengthInPixels) / 2) +
                                               minorUnitLineLengthInPixels,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels)
                                               );
                            }
                        }
                        else if (i % majorUnitInterval == 0) //this is a major unit
                        {
                            if (ticsAlignment == HAlignment.Right)
                            {
                                //draw major unit tick mark on right hand side
                                g.DrawLineFast(negativeForegroundPen,
                                               negativeRegionBoundingRectangle.Right - majorUnitLineLengthInPixels,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels),
                                               negativeRegionBoundingRectangle.Right,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels));
                            }
                            else if (ticsAlignment == HAlignment.Left)
                            {
                                //draw major unit tick mark on left hand side
                                g.DrawLineFast(negativeForegroundPen,
                                               negativeRegionBoundingRectangle.Left,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels),
                                               negativeRegionBoundingRectangle.Left + majorUnitLineLengthInPixels,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels));
                            }
                            else if (ticsAlignment == HAlignment.Center)
                            {
                                //draw major unit tick mark in center
                                g.DrawLineFast(negativeForegroundPen,
                                               negativeRegionBoundingRectangle.Left +
                                               ((negativeRegionBoundingRectangle.Width - majorUnitLineLengthInPixels) / 2),
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels),
                                               negativeRegionBoundingRectangle.Left +
                                               ((negativeRegionBoundingRectangle.Width - majorUnitLineLengthInPixels) / 2) +
                                               majorUnitLineLengthInPixels,
                                               negativeRegionBoundingRectangle.Top +
                                               ((Math.Abs(i) / minorUnitInterval) * verticalSeparationBetweenTicksInPixels));
                            }
                            if (negativeUnitsLabelled) //if we're supposed to add text labels to negative units...
                            {
                                var majorUnitTextBoundingRectangle = Rectangle.Empty;
                                //draw major unit text
                                if (ticsAlignment == HAlignment.Right)
                                {
                                    //tics are on the right so draw text on the left
                                    majorUnitTextBoundingRectangle = new Rectangle(
                                        new Point(0,
                                                  negativeRegionBoundingRectangle.Top + (
                                                      ((Math.Abs(i) - 1) /
                                                       minorUnitInterval) *
                                                      verticalSeparationBetweenTicksInPixels
                                                      )
                                                  ),
                                        new Size(
                                            negativeRegionBoundingRectangle.Width - majorUnitLineLengthInPixels -
                                            textPaddingPixels, verticalSeparationBetweenTicksInPixels * 2)
                                        );
                                }
                                else if (ticsAlignment == HAlignment.Left)
                                {
                                    //tics are on the left so draw text to the right of them
                                    majorUnitTextBoundingRectangle = new Rectangle(
                                        new Point(majorUnitLineLengthInPixels + textPaddingPixels,
                                                  negativeRegionBoundingRectangle.Top + (
                                                      ((Math.Abs(i) - 1) /
                                                       minorUnitInterval) *
                                                      verticalSeparationBetweenTicksInPixels
                                                      )
                                                  ),
                                        new Size(
                                            negativeRegionBoundingRectangle.Width - majorUnitLineLengthInPixels -
                                            textPaddingPixels, verticalSeparationBetweenTicksInPixels * 2)
                                        );
                                }
                                else if (ticsAlignment == HAlignment.Center)
                                {
                                    var lineLength = majorUnitLineLengthInPixels;
                                    if (majorUnitLineLengthInPixels == 0)
                                    {
                                        lineLength = minorUnitLineLengthInPixels;
                                    }
                                    //tic is in the center so draw text in the center
                                    majorUnitTextBoundingRectangle = new Rectangle(
                                        new Point(
                                            ((negativeRegionBoundingRectangle.Width - lineLength) / 2) - 15,
                                            negativeRegionBoundingRectangle.Top + (
                                                ((Math.Abs(i) -
                                                  1 / minorUnitInterval) *
                                                 verticalSeparationBetweenTicksInPixels
                                                )
                                                )),
                                        new Size(negativeRegionBoundingRectangle.Width,
                                                 verticalSeparationBetweenTicksInPixels * 2)
                                        );
                                }
                                //*****

                                var majorUnitString = String.Empty;
                                var majorUnitVal    = i;
                                if (!negativeUnitsHaveNegativeSign && majorUnitVal < 0)
                                {
                                    majorUnitVal = Math.Abs(majorUnitVal);
                                }
                                if (Math.Abs(i).ToString().Length > 3) // num >= 1000
                                {
                                    majorUnitString = String.Format("{0:0000}", majorUnitVal);
                                    majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize - 2,
                                                               majorUnitFont.Style);
                                }
                                else if (Math.Abs(i).ToString().Length > 2) // num >= 100
                                {
                                    majorUnitString = String.Format("{0:000}", majorUnitVal);
                                    majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize,
                                                               majorUnitFont.Style);
                                }
                                else if (Math.Abs(i).ToString().Length > 1) // num >= 10
                                {
                                    majorUnitString = String.Format("{0:00}", majorUnitVal);
                                    majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize,
                                                               majorUnitFont.Style);
                                }
                                else if (Math.Abs(i).ToString().Length == 1) // num between 1 and 10
                                {
                                    majorUnitString = String.Format("{0:0}", majorUnitVal);
                                    majorUnitFont   = new Font(majorUnitFont.FontFamily.Name, baseFontSize,
                                                               majorUnitFont.Style);
                                }
                                if (i == 0)
                                {
                                    majorUnitString = "0";
                                }
                                var majorUnitStringFormat =
                                    new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
                                if (textAlignment == HAlignment.Right)
                                {
                                    majorUnitStringFormat.Alignment = StringAlignment.Far;
                                }
                                else if (textAlignment == HAlignment.Left)
                                {
                                    majorUnitStringFormat.Alignment = StringAlignment.Near;
                                }
                                else if (textAlignment == HAlignment.Center)
                                {
                                    majorUnitStringFormat.Alignment = StringAlignment.Center;
                                }
                                majorUnitStringFormat.LineAlignment = StringAlignment.Center;

                                g.TranslateTransform(0, 2);
                                g.DrawStringFast(majorUnitString, majorUnitFont, negativeForegroundBrush,
                                                 majorUnitTextBoundingRectangle, majorUnitStringFormat);
                                g.ResetTransform();
                                //*****
                            }
                        } //end else
                    }     //end for
                }
                if (coloringInstructions != null)
                {
                    foreach (var instruction in coloringInstructions)
                    {
                        var       color      = instruction.Color;
                        Brush     colorBrush = new SolidBrush(color);
                        Rectangle rect;
                        if (instruction.MinVal > 0)
                        {
                            rect = new Rectangle(
                                new Point(
                                    positiveRegionBoundingRectangle.Right - 5,
                                    positiveRegionBoundingRectangle.Bottom -
                                    ((instruction.MaxVal / minorUnitInterval) * verticalSeparationBetweenTicksInPixels)
                                    ),
                                new Size(
                                    5,
                                    (positiveRegionBoundingRectangle.Bottom -
                                     ((instruction.MinVal / minorUnitInterval) * verticalSeparationBetweenTicksInPixels)) -
                                    (positiveRegionBoundingRectangle.Bottom -
                                     ((instruction.MaxVal / minorUnitInterval) * verticalSeparationBetweenTicksInPixels))
                                    )
                                );
                        }
                        else
                        {
                            rect = new Rectangle(
                                new Point(
                                    negativeRegionBoundingRectangle.Right - 5,
                                    (negativeRegionBoundingRectangle.Top +
                                     ((instruction.MinVal / minorUnitInterval) * verticalSeparationBetweenTicksInPixels))
                                    ),
                                new Size(
                                    5,
                                    (negativeRegionBoundingRectangle.Top +
                                     ((instruction.MaxVal / minorUnitInterval) * verticalSeparationBetweenTicksInPixels)) -
                                    (negativeRegionBoundingRectangle.Top +
                                     ((instruction.MinVal / minorUnitInterval) * verticalSeparationBetweenTicksInPixels))
                                    )
                                );
                        }
                        g.FillRectangle(colorBrush, rect);
                    }
                }
            }
            return(toReturn);
        }
Пример #26
0
        public TextBounds AddWrappedText(CharSequence str, float x, float y, float wrapWidth, HAlignment alignment)
        {
            BitmapFont font = Font;

            int length = str.Length;

            Require(length);

            y += font.Data.Ascent;
            float down = font.Data.Down;

            if (wrapWidth <= 0)
            {
                wrapWidth = int.MaxValue;
            }
            float maxWidth = 0;
            int   start    = 0;
            int   numLines = 0;

            while (start < length)
            {
                int newLine = BitmapFont.IndexOf(str, '\n', start);
                while (start < newLine)
                {
                    if (!BitmapFont.IsWhitespace(str[start]))
                    {
                        break;
                    }
                    start++;
                }

                int lineEnd   = start + font.ComputeVisibleGlyphs(str, start, newLine, wrapWidth);
                int nextStart = lineEnd + 1;

                if (lineEnd < newLine)
                {
                    while (lineEnd > start)
                    {
                        if (BitmapFont.IsWhitespace(str[lineEnd]))
                        {
                            break;
                        }
                        lineEnd--;
                    }

                    if (lineEnd == start)
                    {
                        if (nextStart > start + 1)
                        {
                            nextStart--;
                        }
                        lineEnd = nextStart;
                    }
                    else
                    {
                        nextStart = lineEnd;
                        while (lineEnd > start)
                        {
                            if (!BitmapFont.IsWhitespace(str[lineEnd - 1]))
                            {
                                break;
                            }
                            lineEnd--;
                        }
                    }
                }

                if (lineEnd > start)
                {
                    float xOffset   = 0;
                    float lineWidth = 0;

                    if (alignment != HAlignment.Left)
                    {
                        lineWidth = font.GetBounds(str, start, lineEnd).Width;
                        xOffset   = wrapWidth - lineWidth;
                        if (alignment == HAlignment.Center)
                        {
                            xOffset /= 2;
                        }
                    }

                    lineWidth = AddToCache(str, x + xOffset, y, start, lineEnd);
                    maxWidth  = Math.Max(maxWidth, lineWidth);
                }

                start = nextStart;
                y    += down;
                numLines++;
            }

            return(Bounds = new TextBounds()
            {
                Width = maxWidth,
                Height = font.Data.CapHeight + (numLines - 1) * font.Data.LineHeight,
            });
        }
Пример #27
0
        public TextBounds AddWrappedText(CharSequence str, float x, float y, float wrapWidth, HAlignment alignment)
        {
            BitmapFont font = Font;

            int length = str.Length;
            Require(length);

            y += font.Data.Ascent;
            float down = font.Data.Down;

            if (wrapWidth <= 0)
                wrapWidth = int.MaxValue;
            float maxWidth = 0;
            int start = 0;
            int numLines = 0;

            while (start < length) {
                int newLine = BitmapFont.IndexOf(str, '\n', start);
                while (start < newLine) {
                    if (!BitmapFont.IsWhitespace(str[start]))
                        break;
                    start++;
                }

                int lineEnd = start + font.ComputeVisibleGlyphs(str, start, newLine, wrapWidth);
                int nextStart = lineEnd + 1;

                if (lineEnd < newLine) {
                    while (lineEnd > start) {
                        if (BitmapFont.IsWhitespace(str[lineEnd]))
                            break;
                        lineEnd--;
                    }

                    if (lineEnd == start) {
                        if (nextStart > start + 1)
                            nextStart--;
                        lineEnd = nextStart;
                    }
                    else {
                        nextStart = lineEnd;
                        while (lineEnd > start) {
                            if (!BitmapFont.IsWhitespace(str[lineEnd - 1]))
                                break;
                            lineEnd--;
                        }
                    }
                }

                if (lineEnd > start) {
                    float xOffset = 0;
                    float lineWidth = 0;

                    if (alignment != HAlignment.Left) {
                        lineWidth = font.GetBounds(str, start, lineEnd).Width;
                        xOffset = wrapWidth - lineWidth;
                        if (alignment == HAlignment.Center)
                            xOffset /= 2;
                    }

                    lineWidth = AddToCache(str, x + xOffset, y, start, lineEnd);
                    maxWidth = Math.Max(maxWidth, lineWidth);
                }

                start = nextStart;
                y += down;
                numLines++;
            }

            return Bounds = new TextBounds() {
                Width = maxWidth,
                Height = font.Data.CapHeight + (numLines - 1) * font.Data.LineHeight,
            };
        }
Пример #28
0
        // === === === === === === === === === ===

        public Widget SetAlign(HAlignment a)
        {
            HAlignment = a;
            return(this);
        }
Пример #29
0
 public TextBounds SetWrappedText(CharSequence str, float x, float y, float wrapWidth, HAlignment alignment)
 {
     Clear();
     return AddWrappedText(str, x, y, wrapWidth, alignment);
 }
Пример #30
0
 public static IBitmapText Build(this IBitmapFont font, string text, IBrush brush, TexcoordGenerationMode uMappingMode = TexcoordGenerationMode.FullBoundingBox, TexcoordGenerationMode vMappingMode = TexcoordGenerationMode.FullBoundingBox, HAlignment hAlignment = HAlignment.Middle, VAlignment vAlignment = VAlignment.Middle)
 {
     return new BitmapText(font as BitmapFont, brush, text, uMappingMode, vMappingMode, hAlignment, vAlignment);
 }
Пример #31
0
        public override void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle)
        {
            // string format
            StringFormat sf = new StringFormat();
            switch (hAlignment)
            {
                case HAlignment.HA_RIGHT:
                    sf.LineAlignment = StringAlignment.Far;
                    break;
                case HAlignment.HA_CENTER:
                    sf.LineAlignment = StringAlignment.Center;
                    break;
                case HAlignment.HA_LEFT:
                    sf.LineAlignment = StringAlignment.Near;
                    break;
                default:
                    throw new Exception("Unknown horizontal alignment");
            }
            switch (vAlignment)
            { 
                case VAlignment.VA_BOTTOM:
                    sf.Alignment = StringAlignment.Far;
                    break;
                case VAlignment.VA_MIDDLE:
                    sf.Alignment = StringAlignment.Center;
                    break;
                case VAlignment.VA_TOP:
                    sf.Alignment = StringAlignment.Near;
                    break;
                default:
                    throw new Exception("Unknown vertical alignment");
            }
            // font & brush
            Brush tb;
            switch (font)
            { 
                case TextType.FT_COTATION:
                    tb = new SolidBrush(System.Drawing.Color.FromArgb(0,140,0));
                    break;
                default:
                    throw new Exception("Unknown text type");
            }

            _gdiGraphics.TranslateTransform(ToPointF(pt).X, ToPointF(pt).Y);
            _gdiGraphics.RotateTransform(fAngle); 
            
            // draw text
            _gdiGraphics.DrawString(text, ToFont(font), tb, new PointF(0, 0), sf);

            _gdiGraphics.ResetTransform();
         }
Пример #32
0
 public abstract void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle);
Пример #33
0
 public TextBounds AddMultiLineText(string str, float x, float y, float alignmentWidth, HAlignment alignment)
 {
     _workingSequence.Value = str;
     return(AddMultiLineText(_workingSequence, x, y, alignmentWidth, alignment));
 }
Пример #34
0
 public TextBounds AddMultiLineText(string str, float x, float y, float alignmentWidth, HAlignment alignment)
 {
     _workingSequence.Value = str;
     return AddMultiLineText(_workingSequence, x, y, alignmentWidth, alignment);
 }
Пример #35
0
 public TextBounds SetMultiLineText(CharSequence str, float x, float y, float alignmentWidth, HAlignment alignment)
 {
     Clear();
     return(AddMultiLineText(str, x, y, alignmentWidth, alignment));
 }
Пример #36
0
 public TextBounds AddWrappedText(string str, float x, float y, float wrapWidth, HAlignment alignment)
 {
     _workingSequence.Value = str;
     return AddWrappedText(_workingSequence, x, y, wrapWidth, alignment);
 }
Пример #37
0
 public void SetAlignment(Alignment labelAlign, HAlignment lineAlign)
 {
     _labelAlign = labelAlign;
     _lineAlign  = lineAlign;
     Invalidate();
 }
Пример #38
0
 public TextBounds SetMultiLineText(CharSequence str, float x, float y, float alignmentWidth, HAlignment alignment)
 {
     Clear();
     return AddMultiLineText(str, x, y, alignmentWidth, alignment);
 }
Пример #39
0
 public void SetAlignment(Alignment labelAlign, HAlignment lineAlign)
 {
     _labelAlign = labelAlign;
     _lineAlign = lineAlign;
     Invalidate();
 }
Пример #40
0
 public abstract void DrawText(string text, TextType font, Vector2D pt, HAlignment hAlignment, VAlignment vAlignment, float fAngle);
Пример #41
0
        public void SetAlignment(Alignment labelAlign, Alignment lineAlign)
        {
            _labelAlign = labelAlign;

            if ((lineAlign & Alignment.Left) != 0)
                _lineAlign = HAlignment.Left;
            else if ((lineAlign & Alignment.Right) != 0)
                _lineAlign = HAlignment.Right;
            else
                _lineAlign = HAlignment.Center;

            Invalidate();
        }