Source Code Cross Referenced for FontMetricsImpl.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » gl » font » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.awt.gl.font 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Ilya S. Okomin
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.gl.font;
021:
022:        import java.awt.Font;
023:        import java.awt.FontMetrics;
024:        import java.awt.geom.AffineTransform;
025:
026:        /**
027:         *  FontMetrics implementation
028:         */
029:
030:        public class FontMetricsImpl extends FontMetrics {
031:
032:            private static final long serialVersionUID = 844695615201925138L;
033:
034:            // ascent of the font
035:            private int ascent;
036:
037:            //descent of the font
038:            private int descent;
039:
040:            // leading of the font
041:            private int leading;
042:
043:            // maximum ascent of the font
044:            private int maxAscent;
045:
046:            // maximum descent of the font
047:            private int maxDescent;
048:
049:            // maximum advance of the font
050:            private int maxAdvance;
051:
052:            // array of char advance widths
053:            private int[] widths = new int[256];
054:
055:            // font peer corresponding to this FontPeerImpl 
056:            private transient FontPeerImpl peer;
057:
058:            // X scale parameter of the font transform
059:            private float scaleX = 1;
060:
061:            // Y scale parameter of the font transform
062:            // private float scaleY = 1;
063:
064:            /**
065:             * Creates new FontMericsImpl object described by the specified Font.
066:             * 
067:             * @param fnt the specified Font object
068:             */
069:            public FontMetricsImpl(Font fnt) {
070:                super (fnt);
071:                peer = getFontPeer();
072:                AffineTransform at = fnt.getTransform();
073:                if (!at.isIdentity()) {
074:                    scaleX = (float) at.getScaleX();
075:                    // scaleY = (float)at.getScaleY();
076:                }
077:
078:                LineMetricsImpl lm = (LineMetricsImpl) peer.getLineMetrics(
079:                        "", null, at); //$NON-NLS-1$
080:
081:                this .ascent = lm.getLogicalAscent();
082:                this .descent = lm.getLogicalDescent();
083:                this .leading = lm.getLogicalLeading();
084:                this .maxAscent = ascent;
085:                this .maxDescent = descent;
086:                this .maxAdvance = lm.getLogicalMaxCharWidth();
087:                //        initWidths();
088:            }
089:
090:            /**
091:             * Initialize the array of the first 256 chars' advance widths
092:             * of the Font describing this FontMetricsImpl object.
093:             */
094:            private void initWidths() {
095:
096:                this .widths = new int[256];
097:                for (int chr = 0; chr < 256; chr++) {
098:                    widths[chr] = (int) (getFontPeer().charWidth((char) chr) * scaleX);
099:                }
100:
101:            }
102:
103:            /**
104:             * Returns the ascent of the Font describing this FontMetricsImpl object.
105:             */
106:            @Override
107:            public int getAscent() {
108:                return this .ascent;
109:            }
110:
111:            /**
112:             * Returns the descent of the Font describing this FontMetricsImpl object.
113:             */
114:            @Override
115:            public int getDescent() {
116:                return this .descent;
117:            }
118:
119:            /**
120:             * Returns the leading of the Font describing this FontMetricsImpl object.
121:             */
122:            @Override
123:            public int getLeading() {
124:                return this .leading;
125:            }
126:
127:            /**
128:             * Returns the advance width of the specified char of the Font 
129:             * describing this FontMetricsImpl object.
130:             * 
131:             * @param ch the char which width is to be returned
132:             * @return the advance width of the specified char of the Font 
133:             * describing this FontMetricsImpl object
134:             */
135:            @Override
136:            public int charWidth(int ch) {
137:                //        if (ch < 256){
138:                //            return widths[ch];
139:                //        }
140:
141:                return getFontPeer().charWidth((char) ch);
142:            }
143:
144:            /**
145:             * Returns the advance width of the specified char of the Font 
146:             * describing this FontMetricsImpl object.
147:             * 
148:             * @param ch the char which width is to be returned
149:             * @return the advance width of the specified char of the Font 
150:             * describing this FontMetricsImpl object
151:             */
152:            @Override
153:            public int charWidth(char ch) {
154:                //        if (ch < 256){
155:                //            return widths[ch];
156:                //        }
157:
158:                return (int) (getFontPeer().charWidth(ch) * scaleX);
159:            }
160:
161:            /**
162:             * Returns the maximum advance of the Font describing this 
163:             * FontMetricsImpl object.
164:             */
165:            @Override
166:            public int getMaxAdvance() {
167:                return this .maxAdvance;
168:            }
169:
170:            /**
171:             * Returns the maximum ascent of the Font describing this 
172:             * FontMetricsImpl object.
173:             */
174:            @Override
175:            public int getMaxAscent() {
176:                return this .maxAscent;
177:            }
178:
179:            /**
180:             * Returns the maximum descent of the Font describing this 
181:             * FontMetricsImpl object.
182:             */
183:            @SuppressWarnings("deprecation")
184:            @Deprecated
185:            @Override
186:            public int getMaxDecent() {
187:                return this .maxDescent;
188:            }
189:
190:            /**
191:             * Returns the maximum descent of the Font describing this 
192:             * FontMetricsImpl object.
193:             */
194:            @Override
195:            public int getMaxDescent() {
196:                return this .maxDescent;
197:            }
198:
199:            /**
200:             * Returns the advance widths of the first 256 characters in the Font 
201:             * describing this FontMetricsImpl object.
202:             */
203:            @Override
204:            public int[] getWidths() {
205:                this .widths = new int[256];
206:                for (int chr = 0; chr < 256; chr++) {
207:                    widths[chr] = (int) (getFontPeer().charWidth((char) chr) * scaleX);
208:                }
209:                return this .widths;
210:            }
211:
212:            /**
213:             * Returns the total advance width of the specified string in the metrics
214:             * of the Font describing this FontMetricsImpl object.
215:             * 
216:             * @param str the String which width is to be measured
217:             * @return the total advance width of the specified string in the metrics 
218:             * of the Font describing this FontMetricsImpl object
219:             */
220:            @Override
221:            public int stringWidth(String str) {
222:                int width = 0;
223:                char chr;
224:
225:                for (int i = 0; i < str.length(); i++) {
226:                    chr = str.charAt(i);
227:                    width += charWidth(chr);
228:                }
229:
230:                return width;
231:
232:            }
233:
234:            /**
235:             * Returns FontPeer implementation of the Font describing this 
236:             * FontMetricsImpl object. 
237:             *  
238:             * @return a FontPeer object, that is the platform dependent FontPeer 
239:             * implementation for the Font describing this FontMetricsImpl object.
240:             */
241:            @SuppressWarnings("deprecation")
242:            public FontPeerImpl getFontPeer() {
243:                if (peer == null) {
244:                    peer = (FontPeerImpl) font.getPeer();
245:                }
246:                return peer;
247:            }
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.