001package armyc2.c5isr.renderer.utilities;
002
003import android.graphics.Paint;
004import android.graphics.Point;
005import android.graphics.Rect;
006import android.graphics.Typeface;
007
008public class TextInfo {
009
010        String _fontName = "arial";
011        float _fontSize = 32;
012        int _fontStyle = Typeface.BOLD;
013        String _text = "";
014        Point _location = null;
015        Rect _bounds = null;
016        public TextInfo(String text, int x, int y, Paint font, String fontName)
017        {
018                if(text != null)
019                {
020                        _text = text;
021                }
022
023                _location = new Point(x,y);
024                _bounds = new Rect();
025
026                font.getTextBounds(_text, 0, _text.length(), _bounds);
027
028                if(font != null) {
029                        _fontName = fontName;//font.getTypeface().getSystemFontFamilyName();//Output: "Helvetica"
030                        //_fontName = font.getFontName();//Output: "Helvetica Bold"
031                        _fontSize = font.getTextSize();
032                        _fontStyle = font.getTypeface().getStyle();
033                }
034        
035        }
036        
037        public void setLocation(int x, int y)
038        {
039                _bounds.offset(x - _location.x, y - _location.y);
040                _location = new Point(x,y);
041                //_bounds.offsetTo(x, y - (_bounds.bottom - _bounds.top));
042        }
043        
044        public Point getLocation()
045        {
046                return _location;
047        }
048        
049        public void shift(int x, int y)
050        {
051                _location.offset(x, y);
052                _bounds.offset(x, y);
053        }
054        
055        public String getText()
056        {
057                return _text;
058        }
059        
060        public Rect getTextBounds()
061        {
062                return _bounds;
063        }
064        
065
066        public Rect getTextOutlineBounds()
067        {
068                RendererSettings RS = RendererSettings.getInstance();
069                int outlineOffset = RS.getTextOutlineWidth();
070                Rect bounds = new Rect(_bounds);
071                
072                if(outlineOffset > 0)
073                {
074                        if(RS.getTextBackgroundMethod() == RendererSettings.TextBackgroundMethod_OUTLINE)
075                                RectUtilities.grow(bounds, outlineOffset / 2);
076                        else
077                                RectUtilities.grow(bounds, outlineOffset);
078                }
079                
080                return bounds;
081        }
082
083
084        public String getFontName()
085        {
086                return _fontName;
087        }
088
089        public float getFontSize()
090        {
091                return _fontSize;
092        }
093
094        public int getFontStyle()
095        {
096                return _fontStyle;
097        }
098}