Source Code Cross Referenced for UnitProcessor.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 org.apache.batik.css.engine.SVGCSSEngine;
022:        import org.apache.batik.parser.ParseException;
023:        import org.w3c.dom.Element;
024:
025:        /**
026:         * This class provides methods to convert SVG length and coordinate to
027:         * float in user units.
028:         *
029:         * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
030:         * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
031:         * @version $Id: UnitProcessor.java 501922 2007-01-31 17:47:47Z dvholten $
032:         */
033:        public abstract class UnitProcessor extends
034:                org.apache.batik.parser.UnitProcessor {
035:
036:            /**
037:             * Creates a context for the specified element.
038:             *
039:             * @param ctx the bridge context that contains the user agent and
040:             * viewport definition
041:             * @param e the element interested in its context
042:             */
043:            public static Context createContext(BridgeContext ctx, Element e) {
044:                return new DefaultContext(ctx, e);
045:            }
046:
047:            /////////////////////////////////////////////////////////////////////////
048:            // SVG methods - objectBoundingBox
049:            /////////////////////////////////////////////////////////////////////////
050:
051:            /**
052:             * Returns the specified horizontal coordinate in object bounding box
053:             * coordinate system.
054:             *
055:             * @param s the horizontal coordinate
056:             * @param attr the attribute name that represents the coordinate
057:             * @param ctx the context used to resolve relative value
058:             */
059:            public static float svgHorizontalCoordinateToObjectBoundingBox(
060:                    String s, String attr, Context ctx) {
061:                return svgToObjectBoundingBox(s, attr, HORIZONTAL_LENGTH, ctx);
062:            }
063:
064:            /**
065:             * Returns the specified vertical coordinate in object bounding box
066:             * coordinate system.
067:             *
068:             * @param s the vertical coordinate
069:             * @param attr the attribute name that represents the coordinate
070:             * @param ctx the context used to resolve relative value
071:             */
072:            public static float svgVerticalCoordinateToObjectBoundingBox(
073:                    String s, String attr, Context ctx) {
074:                return svgToObjectBoundingBox(s, attr, VERTICAL_LENGTH, ctx);
075:            }
076:
077:            /**
078:             * Returns the specified 'other' coordinate in object bounding box
079:             * coordinate system.
080:             *
081:             * @param s the 'other' coordinate
082:             * @param attr the attribute name that represents the coordinate
083:             * @param ctx the context used to resolve relative value
084:             */
085:            public static float svgOtherCoordinateToObjectBoundingBox(String s,
086:                    String attr, Context ctx) {
087:                return svgToObjectBoundingBox(s, attr, OTHER_LENGTH, ctx);
088:            }
089:
090:            /**
091:             * Returns the specified horizontal length in object bounding box
092:             * coordinate system. A length must be greater than 0.
093:             *
094:             * @param s the 'other' length
095:             * @param attr the attribute name that represents the length
096:             * @param ctx the context used to resolve relative value
097:             */
098:            public static float svgHorizontalLengthToObjectBoundingBox(
099:                    String s, String attr, Context ctx) {
100:                return svgLengthToObjectBoundingBox(s, attr, HORIZONTAL_LENGTH,
101:                        ctx);
102:            }
103:
104:            /**
105:             * Returns the specified vertical length in object bounding box
106:             * coordinate system. A length must be greater than 0.
107:             *
108:             * @param s the vertical length
109:             * @param attr the attribute name that represents the length
110:             * @param ctx the context used to resolve relative value
111:             */
112:            public static float svgVerticalLengthToObjectBoundingBox(String s,
113:                    String attr, Context ctx) {
114:                return svgLengthToObjectBoundingBox(s, attr, VERTICAL_LENGTH,
115:                        ctx);
116:            }
117:
118:            /**
119:             * Returns the specified 'other' length in object bounding box
120:             * coordinate system. A length must be greater than 0.
121:             *
122:             * @param s the 'other' length
123:             * @param attr the attribute name that represents the length
124:             * @param ctx the context used to resolve relative value
125:             */
126:            public static float svgOtherLengthToObjectBoundingBox(String s,
127:                    String attr, Context ctx) {
128:                return svgLengthToObjectBoundingBox(s, attr, OTHER_LENGTH, ctx);
129:            }
130:
131:            /**
132:             * Returns the specified length with the specified direction in
133:             * user units. A length must be greater than 0.
134:             *
135:             * @param s the length
136:             * @param attr the attribute name that represents the length
137:             * @param d the direction of the length
138:             * @param ctx the context used to resolve relative value
139:             */
140:            public static float svgLengthToObjectBoundingBox(String s,
141:                    String attr, short d, Context ctx) {
142:                float v = svgToObjectBoundingBox(s, attr, d, ctx);
143:                if (v < 0) {
144:                    throw new BridgeException(getBridgeContext(ctx), ctx
145:                            .getElement(), ErrorConstants.ERR_LENGTH_NEGATIVE,
146:                            new Object[] { attr, s });
147:                }
148:                return v;
149:            }
150:
151:            /**
152:             * Returns the specified value with the specified direction in
153:             * objectBoundingBox units.
154:             *
155:             * @param s the value
156:             * @param attr the attribute name that represents the value
157:             * @param d the direction of the value
158:             * @param ctx the context used to resolve relative value
159:             */
160:            public static float svgToObjectBoundingBox(String s, String attr,
161:                    short d, Context ctx) {
162:                try {
163:                    return org.apache.batik.parser.UnitProcessor
164:                            .svgToObjectBoundingBox(s, attr, d, ctx);
165:                } catch (ParseException pEx) {
166:                    throw new BridgeException(getBridgeContext(ctx), ctx
167:                            .getElement(), pEx,
168:                            ErrorConstants.ERR_ATTRIBUTE_VALUE_MALFORMED,
169:                            new Object[] { attr, s, pEx });
170:                }
171:            }
172:
173:            /////////////////////////////////////////////////////////////////////////
174:            // SVG methods - userSpace
175:            /////////////////////////////////////////////////////////////////////////
176:
177:            /**
178:             * Returns the specified horizontal length in user units. A length
179:             * must be greater than 0.
180:             *
181:             * @param s the horizontal length
182:             * @param attr the attribute name that represents the length
183:             * @param ctx the context used to resolve relative value
184:             */
185:            public static float svgHorizontalLengthToUserSpace(String s,
186:                    String attr, Context ctx) {
187:                return svgLengthToUserSpace(s, attr, HORIZONTAL_LENGTH, ctx);
188:            }
189:
190:            /**
191:             * Returns the specified vertical length in user units. A length
192:             * must be greater than 0.
193:             *
194:             * @param s the vertical length
195:             * @param attr the attribute name that represents the length
196:             * @param ctx the context used to resolve relative value
197:             */
198:            public static float svgVerticalLengthToUserSpace(String s,
199:                    String attr, Context ctx) {
200:                return svgLengthToUserSpace(s, attr, VERTICAL_LENGTH, ctx);
201:            }
202:
203:            /**
204:             * Returns the specified 'other' length in user units. A length
205:             * must be greater than 0.
206:             *
207:             * @param s the 'other' length
208:             * @param attr the attribute name that represents the length
209:             * @param ctx the context used to resolve relative value
210:             */
211:            public static float svgOtherLengthToUserSpace(String s,
212:                    String attr, Context ctx) {
213:                return svgLengthToUserSpace(s, attr, OTHER_LENGTH, ctx);
214:            }
215:
216:            /**
217:             * Returns the specified horizontal coordinate in user units.
218:             *
219:             * @param s the horizontal coordinate
220:             * @param attr the attribute name that represents the length
221:             * @param ctx the context used to resolve relative value
222:             */
223:            public static float svgHorizontalCoordinateToUserSpace(String s,
224:                    String attr, Context ctx) {
225:                return svgToUserSpace(s, attr, HORIZONTAL_LENGTH, ctx);
226:            }
227:
228:            /**
229:             * Returns the specified vertical coordinate in user units.
230:             *
231:             * @param s the vertical coordinate
232:             * @param attr the attribute name that represents the length
233:             * @param ctx the context used to resolve relative value
234:             */
235:            public static float svgVerticalCoordinateToUserSpace(String s,
236:                    String attr, Context ctx) {
237:                return svgToUserSpace(s, attr, VERTICAL_LENGTH, ctx);
238:            }
239:
240:            /**
241:             * Returns the specified 'other' coordinate in user units.
242:             *
243:             * @param s the 'other' coordinate
244:             * @param attr the attribute name that represents the length
245:             * @param ctx the context used to resolve relative value
246:             */
247:            public static float svgOtherCoordinateToUserSpace(String s,
248:                    String attr, Context ctx) {
249:                return svgToUserSpace(s, attr, OTHER_LENGTH, ctx);
250:            }
251:
252:            /**
253:             * Returns the specified length with the specified direction in
254:             * user units. A length must be greater than 0.
255:             *
256:             * @param s the 'other' coordinate
257:             * @param attr the attribute name that represents the length
258:             * @param d the direction of the length
259:             * @param ctx the context used to resolve relative value
260:             */
261:            public static float svgLengthToUserSpace(String s, String attr,
262:                    short d, Context ctx) {
263:                float v = svgToUserSpace(s, attr, d, ctx);
264:                if (v < 0) {
265:                    throw new BridgeException(getBridgeContext(ctx), ctx
266:                            .getElement(), ErrorConstants.ERR_LENGTH_NEGATIVE,
267:                            new Object[] { attr, s });
268:                } else {
269:                    return v;
270:                }
271:            }
272:
273:            /**
274:             * Returns the specified coordinate with the specified direction
275:             * in user units.
276:             *
277:             * @param s the 'other' coordinate
278:             * @param attr the attribute name that represents the length
279:             * @param d the direction of the coordinate
280:             * @param ctx the context used to resolve relative value
281:             */
282:            public static float svgToUserSpace(String s, String attr, short d,
283:                    Context ctx) {
284:                try {
285:                    return org.apache.batik.parser.UnitProcessor
286:                            .svgToUserSpace(s, attr, d, ctx);
287:                } catch (ParseException pEx) {
288:                    throw new BridgeException(getBridgeContext(ctx), ctx
289:                            .getElement(), pEx,
290:                            ErrorConstants.ERR_ATTRIBUTE_VALUE_MALFORMED,
291:                            new Object[] { attr, s, pEx, });
292:                }
293:            }
294:
295:            /**
296:             * Returns the {@link BridgeContext} from the given {@link Context}
297:             * if it is a {@link DefaultContext}, or null otherwise.
298:             */
299:            protected static BridgeContext getBridgeContext(Context ctx) {
300:                if (ctx instanceof  DefaultContext) {
301:                    return ((DefaultContext) ctx).ctx;
302:                }
303:                return null;
304:            }
305:
306:            /**
307:             * This class is the default context for a particular element. Information
308:             * not available on the element are obtained from the bridge context (such
309:             * as the viewport or the pixel to millimeter factor).
310:             */
311:            public static class DefaultContext implements  Context {
312:
313:                /**
314:                 * The element.
315:                 */
316:                protected Element e;
317:
318:                /**
319:                 * The bridge context.
320:                 */
321:                protected BridgeContext ctx;
322:
323:                /**
324:                 * Creates a new DefaultContext.
325:                 */
326:                public DefaultContext(BridgeContext ctx, Element e) {
327:                    this .ctx = ctx;
328:                    this .e = e;
329:                }
330:
331:                /**
332:                 * Returns the element.
333:                 */
334:                public Element getElement() {
335:                    return e;
336:                }
337:
338:                /**
339:                 * Returns the size of a px CSS unit in millimeters.
340:                 */
341:                public float getPixelUnitToMillimeter() {
342:                    return ctx.getUserAgent().getPixelUnitToMillimeter();
343:                }
344:
345:                /**
346:                 * Returns the size of a px CSS unit in millimeters.
347:                 * This will be removed after next release.
348:                 * @see #getPixelUnitToMillimeter()
349:                 */
350:                public float getPixelToMM() {
351:                    return getPixelUnitToMillimeter();
352:
353:                }
354:
355:                /**
356:                 * Returns the font-size value.
357:                 */
358:                public float getFontSize() {
359:                    return CSSUtilities.getComputedStyle(e,
360:                            SVGCSSEngine.FONT_SIZE_INDEX).getFloatValue();
361:                }
362:
363:                /**
364:                 * Returns the x-height value.
365:                 */
366:                public float getXHeight() {
367:                    return 0.5f;
368:                }
369:
370:                /**
371:                 * Returns the viewport width used to compute units.
372:                 */
373:                public float getViewportWidth() {
374:                    return ctx.getViewport(e).getWidth();
375:                }
376:
377:                /**
378:                 * Returns the viewport height used to compute units.
379:                 */
380:                public float getViewportHeight() {
381:                    return ctx.getViewport(e).getHeight();
382:                }
383:            }
384:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.