Source Code Cross Referenced for SVGKernElementBridge.java in  » Graphic-Library » batik » org » apache » batik » bridge » 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 » Graphic Library » batik » org.apache.batik.bridge 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Licensed to the Apache Software Foundation (ASF) under one or more
004:           contributor license agreements.  See the NOTICE file distributed with
005:           this work for additional information regarding copyright ownership.
006:           The ASF licenses this file to You under the Apache License, Version 2.0
007:           (the "License"); you may not use this file except in compliance with
008:           the License.  You may obtain a copy of the License at
009:
010:               http://www.apache.org/licenses/LICENSE-2.0
011:
012:           Unless required by applicable law or agreed to in writing, software
013:           distributed under the License is distributed on an "AS IS" BASIS,
014:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:           See the License for the specific language governing permissions and
016:           limitations under the License.
017:
018:         */
019:        package org.apache.batik.bridge;
020:
021:        import java.util.StringTokenizer;
022:        import java.util.List;
023:        import java.util.ArrayList;
024:
025:        import org.apache.batik.gvt.font.Kern;
026:        import org.apache.batik.gvt.font.UnicodeRange;
027:        import org.w3c.dom.Element;
028:
029:        /**
030:         * A base Bridge class for the kerning elements.
031:         *
032:         * @author <a href="mailto:dean.jackson@cmis.csiro.au">Dean Jackson</a>
033:         * @version $Id: SVGKernElementBridge.java 478160 2006-11-22 13:35:06Z dvholten $
034:         */
035:        public abstract class SVGKernElementBridge extends AbstractSVGBridge {
036:
037:            /**
038:             * Creates a Kern object that repesents the specified kerning element.
039:             *
040:             * @param ctx The bridge context.
041:             * @param kernElement The kerning element. Should be either a &lt;hkern>
042:             * or &lt;vkern> element.
043:             * @param font The font the kerning is related to.
044:             *
045:             * @return kern The new Kern object
046:             */
047:            public Kern createKern(BridgeContext ctx, Element kernElement,
048:                    SVGGVTFont font) {
049:
050:                // read all of the kern attributes
051:                String u1 = kernElement.getAttributeNS(null, SVG_U1_ATTRIBUTE);
052:                String u2 = kernElement.getAttributeNS(null, SVG_U2_ATTRIBUTE);
053:                String g1 = kernElement.getAttributeNS(null, SVG_G1_ATTRIBUTE);
054:                String g2 = kernElement.getAttributeNS(null, SVG_G2_ATTRIBUTE);
055:                String k = kernElement.getAttributeNS(null, SVG_K_ATTRIBUTE);
056:                if (k.length() == 0) {
057:                    k = SVG_KERN_K_DEFAULT_VALUE;
058:                }
059:
060:                // get the kern float value
061:                float kernValue = Float.parseFloat(k);
062:
063:                // set up the first and second glyph sets and unicode ranges
064:                int firstGlyphLen = 0, secondGlyphLen = 0;
065:                int[] firstGlyphSet = null;
066:                int[] secondGlyphSet = null;
067:                List firstUnicodeRanges = new ArrayList();
068:                List secondUnicodeRanges = new ArrayList();
069:
070:                // process the u1 attribute
071:                StringTokenizer st = new StringTokenizer(u1, ",");
072:                while (st.hasMoreTokens()) {
073:                    String token = st.nextToken();
074:                    if (token.startsWith("U+")) { // its a unicode range
075:                        firstUnicodeRanges.add(new UnicodeRange(token));
076:                    } else {
077:                        int[] glyphCodes = font.getGlyphCodesForUnicode(token);
078:                        if (firstGlyphSet == null) {
079:                            firstGlyphSet = glyphCodes;
080:                            firstGlyphLen = glyphCodes.length;
081:                        } else {
082:                            if ((firstGlyphLen + glyphCodes.length) > firstGlyphSet.length) {
083:                                int sz = firstGlyphSet.length * 2;
084:                                if (sz < firstGlyphLen + glyphCodes.length)
085:                                    sz = firstGlyphLen + glyphCodes.length;
086:                                int[] tmp = new int[sz];
087:                                System.arraycopy(firstGlyphSet, 0, tmp, 0,
088:                                        firstGlyphLen);
089:                                firstGlyphSet = tmp;
090:                            }
091:                            for (int i = 0; i < glyphCodes.length; i++)
092:                                firstGlyphSet[firstGlyphLen++] = glyphCodes[i];
093:                        }
094:                    }
095:                }
096:
097:                // process the u2 attrbute
098:                st = new StringTokenizer(u2, ",");
099:                while (st.hasMoreTokens()) {
100:                    String token = st.nextToken();
101:                    if (token.startsWith("U+")) { // its a unicode range
102:                        secondUnicodeRanges.add(new UnicodeRange(token));
103:                    } else {
104:                        int[] glyphCodes = font.getGlyphCodesForUnicode(token);
105:                        if (secondGlyphSet == null) {
106:                            secondGlyphSet = glyphCodes;
107:                            secondGlyphLen = glyphCodes.length;
108:                        } else {
109:                            if ((secondGlyphLen + glyphCodes.length) > secondGlyphSet.length) {
110:                                int sz = secondGlyphSet.length * 2;
111:                                if (sz < secondGlyphLen + glyphCodes.length)
112:                                    sz = secondGlyphLen + glyphCodes.length;
113:                                int[] tmp = new int[sz];
114:                                System.arraycopy(secondGlyphSet, 0, tmp, 0,
115:                                        secondGlyphLen);
116:                                secondGlyphSet = tmp;
117:                            }
118:                            for (int i = 0; i < glyphCodes.length; i++)
119:                                secondGlyphSet[secondGlyphLen++] = glyphCodes[i];
120:                        }
121:                    }
122:                }
123:
124:                // process the g1 attribute
125:                st = new StringTokenizer(g1, ",");
126:                while (st.hasMoreTokens()) {
127:                    String token = st.nextToken();
128:                    int[] glyphCodes = font.getGlyphCodesForName(token);
129:                    if (firstGlyphSet == null) {
130:                        firstGlyphSet = glyphCodes;
131:                        firstGlyphLen = glyphCodes.length;
132:                    } else {
133:                        if ((firstGlyphLen + glyphCodes.length) > firstGlyphSet.length) {
134:                            int sz = firstGlyphSet.length * 2;
135:                            if (sz < firstGlyphLen + glyphCodes.length)
136:                                sz = firstGlyphLen + glyphCodes.length;
137:                            int[] tmp = new int[sz];
138:                            System.arraycopy(firstGlyphSet, 0, tmp, 0,
139:                                    firstGlyphLen);
140:                            firstGlyphSet = tmp;
141:                        }
142:                        for (int i = 0; i < glyphCodes.length; i++)
143:                            firstGlyphSet[firstGlyphLen++] = glyphCodes[i];
144:                    }
145:                }
146:
147:                // process the g2 attribute
148:                st = new StringTokenizer(g2, ",");
149:                while (st.hasMoreTokens()) {
150:                    String token = st.nextToken();
151:                    int[] glyphCodes = font.getGlyphCodesForName(token);
152:                    if (secondGlyphSet == null) {
153:                        secondGlyphSet = glyphCodes;
154:                        secondGlyphLen = glyphCodes.length;
155:                    } else {
156:                        if ((secondGlyphLen + glyphCodes.length) > secondGlyphSet.length) {
157:                            int sz = secondGlyphSet.length * 2;
158:                            if (sz < secondGlyphLen + glyphCodes.length)
159:                                sz = secondGlyphLen + glyphCodes.length;
160:                            int[] tmp = new int[sz];
161:                            System.arraycopy(secondGlyphSet, 0, tmp, 0,
162:                                    secondGlyphLen);
163:                            secondGlyphSet = tmp;
164:                        }
165:                        for (int i = 0; i < glyphCodes.length; i++)
166:                            secondGlyphSet[secondGlyphLen++] = glyphCodes[i];
167:                    }
168:                }
169:
170:                // construct the arrays
171:                int[] firstGlyphs;
172:                if ((firstGlyphLen == 0)
173:                        || (firstGlyphLen == firstGlyphSet.length)) {
174:                    firstGlyphs = firstGlyphSet;
175:                } else {
176:                    firstGlyphs = new int[firstGlyphLen];
177:                    System.arraycopy(firstGlyphSet, 0, firstGlyphs, 0,
178:                            firstGlyphLen);
179:                }
180:                int[] secondGlyphs;
181:                if ((secondGlyphLen == 0)
182:                        || (secondGlyphLen == secondGlyphSet.length)) {
183:                    secondGlyphs = secondGlyphSet;
184:                } else {
185:                    secondGlyphs = new int[secondGlyphLen];
186:                    System.arraycopy(secondGlyphSet, 0, secondGlyphs, 0,
187:                            secondGlyphLen);
188:                }
189:
190:                UnicodeRange[] firstRanges;
191:                firstRanges = new UnicodeRange[firstUnicodeRanges.size()];
192:                firstUnicodeRanges.toArray(firstRanges);
193:
194:                UnicodeRange[] secondRanges;
195:                secondRanges = new UnicodeRange[secondUnicodeRanges.size()];
196:                secondUnicodeRanges.toArray(secondRanges);
197:
198:                // return the new Kern object
199:                return new Kern(firstGlyphs, secondGlyphs, firstRanges,
200:                        secondRanges, kernValue);
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.