Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region License
2
//
3
// The Open Toolkit Library License
4
//
5
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
6
//
7
// Permission is hereby granted, free of charge, to any person obtaining a copy
8
// of this software and associated documentation files (the "Software"), to deal
9
// in the Software without restriction, including without limitation the rights to 
10
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
// the Software, and to permit persons to whom the Software is furnished to do
12
// so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be included in all
15
// copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
// OTHER DEALINGS IN THE SOFTWARE.
25
//
26
#endregion
27
 
28
using System;
29
using System.Collections.Generic;
30
using System.Text;
31
using System.Drawing;
32
 
33
namespace OpenTK.Graphics
34
{
35
    /// <summary>
36
    /// Holds the results of a text measurement.
37
    /// </summary>
38
    public class TextExtents : IDisposable
39
    {
40
        #region Fields
41
 
42
        protected RectangleF text_extents;
43
        protected List<RectangleF> glyph_extents = new List<RectangleF>();
44
 
45
        public static readonly TextExtents Empty = new TextExtents();
46
 
47
        #endregion
48
 
49
        #region Constructors
50
 
51
        internal TextExtents()
52
        {
53
        }
54
 
55
        #endregion
56
 
57
        #region Public Members
58
 
59
        /// <summary>
60
        /// Gets the bounding box of the measured text.
61
        /// </summary>
62
        public RectangleF BoundingBox
63
        {
64
            get { return text_extents; }
65
            internal set { text_extents = value; }
66
        }
67
 
68
        /// <summary>
69
        /// Gets the extents of each glyph in the measured text.
70
        /// </summary>
71
        /// <param name="i">The index of the glyph.</param>
72
        /// <returns>The extents of the specified glyph.</returns>
73
        public RectangleF this[int i]
74
        {
75
            get { return glyph_extents[i]; }
76
            internal set { glyph_extents[i] = value; }
77
        }
78
 
79
        /// <summary>
80
        /// Gets the extents of each glyph in the measured text.
81
        /// </summary>
82
        public IEnumerable<RectangleF> GlyphExtents
83
        {
84
            get { return (IEnumerable<RectangleF>)glyph_extents; }
85
        }
86
 
87
        /// <summary>
88
        /// Gets the number of the measured glyphs.
89
        /// </summary>
90
        public int Count
91
        {
92
            get { return glyph_extents.Count; }
93
        }
94
 
95
        #endregion
96
 
97
        #region Internal Members
98
 
99
        internal void Add(RectangleF glyphExtent)
100
        {
101
            glyph_extents.Add(glyphExtent);
102
        }
103
 
104
        internal void AddRange(IEnumerable<RectangleF> glyphExtents)
105
        {
106
            glyph_extents.AddRange(glyphExtents);
107
        }
108
 
109
        internal void Clear()
110
        {
111
            BoundingBox = RectangleF.Empty;
112
            glyph_extents.Clear();
113
        }
114
 
115
        internal TextExtents Clone()
116
        {
117
            TextExtents extents = new TextExtents();
118
            extents.glyph_extents.AddRange(GlyphExtents);
119
            extents.BoundingBox = BoundingBox;
120
            return extents;
121
        }
122
 
123
        #endregion
124
 
125
        #region IDisposable Members
126
 
127
        /// <summary>
128
        /// Frees the resources consumed by this TextExtents instance.
129
        /// </summary>
130
        public virtual void Dispose()
131
        {
132
        }
133
 
134
        #endregion
135
    }
136
}