summaryrefslogtreecommitdiff
diff options
authorTorsten Werner <twerner@debian.org>2011-09-12 07:38:57 +0200
committergit-ubuntu importer <ubuntu-devel-discuss@lists.ubuntu.com>2011-09-12 15:24:00 +0000
commit720b7a1e1164266eda92bfc41c676565a64a265e (patch)
treedbc3cfe80657ddb400913e4e020863eaf3f43ca8
parent4d9da2fbb65169fac872f3319a2d387380733488 (diff)
parente52172316060afef6f5e06cc10d3ae6a0cb93fe3 (diff)
Imported using git-ubuntu import.
-rw-r--r--debian/changelog9
-rw-r--r--debian/control5
-rwxr-xr-xdebian/rules2
-rw-r--r--debian/watch2
-rw-r--r--doc/3rd_party_licenses/FTL.txt174
-rw-r--r--doc/3rd_party_licenses/freetype_license.txt28
-rw-r--r--resource/META-INF/services/de.intarsys.nativec.api.INativeInterface1
-rw-r--r--src/com/sun/jna/FastMemory.java21
-rw-r--r--src/com/sun/jna/JNATools.java11
-rw-r--r--src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsContext.java245
-rw-r--r--src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsEnvironment.java46
-rw-r--r--src/de/intarsys/cwt/awt/image/CwtAwtImageTools.java86
-rw-r--r--src/de/intarsys/cwt/common/BlendMode.java55
-rw-r--r--src/de/intarsys/cwt/common/ShapeWrapper.java108
-rw-r--r--src/de/intarsys/cwt/environment/IGraphicsContext.java240
-rw-r--r--src/de/intarsys/cwt/environment/package.html8
-rw-r--r--src/de/intarsys/cwt/font/CommonFont.java48
-rw-r--r--src/de/intarsys/cwt/font/CommonFontProgram.java52
-rw-r--r--src/de/intarsys/cwt/font/FontEnvironment.java331
-rw-r--r--src/de/intarsys/cwt/font/FontFamily.java119
-rw-r--r--src/de/intarsys/cwt/font/FontQuery.java92
-rw-r--r--src/de/intarsys/cwt/font/FontRegistry.java42
-rw-r--r--src/de/intarsys/cwt/font/FontStyle.java119
-rw-r--r--src/de/intarsys/cwt/font/FontTools.java96
-rw-r--r--src/de/intarsys/cwt/font/GenericFont.java155
-rw-r--r--src/de/intarsys/cwt/font/GenericFontProgram.java40
-rw-r--r--src/de/intarsys/cwt/font/IFontQuery.java45
-rw-r--r--src/de/intarsys/cwt/font/IFontRegistry.java84
-rw-r--r--src/de/intarsys/cwt/font/PACKAGE.java45
-rw-r--r--src/de/intarsys/cwt/font/StandardFontRegistry.java265
-rw-r--r--src/de/intarsys/cwt/font/afm/AFM.java161
-rw-r--r--src/de/intarsys/cwt/font/afm/AFMChar.java185
-rw-r--r--src/de/intarsys/cwt/font/afm/AFMParser.java351
-rw-r--r--src/de/intarsys/cwt/font/afm/package.html9
-rw-r--r--src/de/intarsys/cwt/font/truetype/CreateSubset.java215
-rw-r--r--src/de/intarsys/cwt/font/truetype/ITTNamingIDs.java135
-rw-r--r--src/de/intarsys/cwt/font/truetype/PACKAGE.java45
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTFont.java444
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTFontHeader.java129
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTFontParser.java731
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTFontSerializer.java200
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTHorizontalHeader.java135
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTMetrics.java338
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTMetricsPanose.java75
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTPostScriptInformation.java101
-rw-r--r--src/de/intarsys/cwt/font/truetype/TTTable.java137
-rw-r--r--src/de/intarsys/cwt/font/type1/Type1Font.java112
-rw-r--r--src/de/intarsys/cwt/hybrid/image/CwtHybridImage.java133
-rw-r--r--src/de/intarsys/cwt/hybrid/image/ImageIOImageContainer.java210
-rw-r--r--src/de/intarsys/cwt/hybrid/image/ImageIOImageEntry.java106
-rw-r--r--src/de/intarsys/cwt/image/IImage.java42
-rw-r--r--src/de/intarsys/cwt/image/IImageContainer.java49
-rw-r--r--src/de/intarsys/cwt/image/ImageEntry.java94
-rw-r--r--src/de/intarsys/cwt/image/ImageMetadata.java105
-rw-r--r--src/de/intarsys/cwt/image/ImageTools.java109
-rw-r--r--src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsContext.java910
-rw-r--r--src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsEnvironment.java42
-rw-r--r--src/de/intarsys/cwt/swt/image/CwtSwtImage.java156
-rw-r--r--src/de/intarsys/cwt/swt/image/CwtSwtImageTools.java71
-rw-r--r--src/de/intarsys/cwt/swt/image/ISwtImage.java43
-rw-r--r--src/de/intarsys/cwt/swt/image/ISwtPaint.java40
-rw-r--r--src/de/intarsys/cwt/swt/image/ImageConverterAwt2Swt.java333
-rw-r--r--src/de/intarsys/cwt/swt/image/ImageConverterSwt2Awt.java72
-rw-r--r--src/de/intarsys/cwt/swt/image/SwtCompatibleRaster.java1336
-rw-r--r--src/de/intarsys/nativec/api/CLong.java82
-rw-r--r--src/de/intarsys/nativec/api/CWideString.java (renamed from src/de/intarsys/cwt/font/truetype/TrueTypeException.java)25
-rw-r--r--src/de/intarsys/nativec/api/ICallback.java (renamed from src/de/intarsys/cwt/image/IImageEntry.java)10
-rw-r--r--src/de/intarsys/nativec/api/INativeCallback.java (renamed from src/de/intarsys/cwt/common/IShape.java)8
-rw-r--r--src/de/intarsys/nativec/api/INativeFunction.java (renamed from src/de/intarsys/cwt/font/IFontProgram.java)19
-rw-r--r--src/de/intarsys/nativec/api/INativeHandle.java271
-rw-r--r--src/de/intarsys/nativec/api/INativeInterface.java109
-rw-r--r--src/de/intarsys/nativec/api/INativeLibrary.java (renamed from src/de/intarsys/cwt/awt/image/IAwtImage.java)27
-rw-r--r--src/de/intarsys/nativec/api/NativeInterface.java118
-rw-r--r--src/de/intarsys/nativec/api/NativeTools.java204
-rw-r--r--src/de/intarsys/nativec/api/package.html35
-rw-r--r--src/de/intarsys/nativec/jna/JnaNativeCallback.java126
-rw-r--r--src/de/intarsys/nativec/jna/JnaNativeFunction.java114
-rw-r--r--src/de/intarsys/nativec/jna/JnaNativeHandle.java187
-rw-r--r--src/de/intarsys/nativec/jna/JnaNativeInterface.java126
-rw-r--r--src/de/intarsys/nativec/jna/JnaNativeLibrary.java (renamed from src/de/intarsys/cwt/font/FontMapper.java)73
-rw-r--r--src/de/intarsys/nativec/type/INativeObject.java (renamed from src/de/intarsys/cwt/common/IPaint.java)49
-rw-r--r--src/de/intarsys/nativec/type/INativeType.java (renamed from src/de/intarsys/cwt/font/IFontFamily.java)61
-rw-r--r--src/de/intarsys/nativec/type/NativeAbstractStringType.java (renamed from src/de/intarsys/cwt/font/truetype/TTNaming.java)57
-rw-r--r--src/de/intarsys/nativec/type/NativeArray.java178
-rw-r--r--src/de/intarsys/nativec/type/NativeArrayType.java (renamed from src/de/intarsys/cwt/font/truetype/TTNameRecord.java)106
-rw-r--r--src/de/intarsys/nativec/type/NativeBuffer.java116
-rw-r--r--src/de/intarsys/nativec/type/NativeBufferType.java79
-rw-r--r--src/de/intarsys/nativec/type/NativeByte.java146
-rw-r--r--src/de/intarsys/nativec/type/NativeByteType.java (renamed from src/de/intarsys/cwt/font/FontMap.java)38
-rw-r--r--src/de/intarsys/nativec/type/NativeGenericStruct.java68
-rw-r--r--src/de/intarsys/nativec/type/NativeInt.java116
-rw-r--r--src/de/intarsys/nativec/type/NativeIntType.java (renamed from src/de/intarsys/cwt/image/ImageException.java)42
-rw-r--r--src/de/intarsys/nativec/type/NativeLong.java116
-rw-r--r--src/de/intarsys/nativec/type/NativeLongLP64.java125
-rw-r--r--src/de/intarsys/nativec/type/NativeLongLP64Type.java (renamed from src/de/intarsys/cwt/image/ImageContainer.java)55
-rw-r--r--src/de/intarsys/nativec/type/NativeLongType.java57
-rw-r--r--src/de/intarsys/nativec/type/NativeNumber.java (renamed from src/de/intarsys/cwt/font/IFont.java)58
-rw-r--r--src/de/intarsys/nativec/type/NativeNumberType.java (renamed from src/de/intarsys/cwt/environment/IGraphicsEnvironment.java)12
-rw-r--r--src/de/intarsys/nativec/type/NativeObject.java290
-rw-r--r--src/de/intarsys/nativec/type/NativeReference.java118
-rw-r--r--src/de/intarsys/nativec/type/NativeReferenceType.java78
-rw-r--r--src/de/intarsys/nativec/type/NativeShort.java146
-rw-r--r--src/de/intarsys/nativec/type/NativeShortType.java57
-rw-r--r--src/de/intarsys/nativec/type/NativeSimple.java64
-rw-r--r--src/de/intarsys/nativec/type/NativeSimpleType.java (renamed from src/de/intarsys/cwt/common/IGraphicsObject.java)18
-rw-r--r--src/de/intarsys/nativec/type/NativeStaticStruct.java (renamed from src/de/intarsys/cwt/font/FontFontMap.java)21
-rw-r--r--src/de/intarsys/nativec/type/NativeString.java115
-rw-r--r--src/de/intarsys/nativec/type/NativeStringType.java65
-rw-r--r--src/de/intarsys/nativec/type/NativeStruct.java133
-rw-r--r--src/de/intarsys/nativec/type/NativeStructType.java171
-rw-r--r--src/de/intarsys/nativec/type/NativeType.java107
-rw-r--r--src/de/intarsys/nativec/type/NativeVoid.java (renamed from src/de/intarsys/cwt/awt/image/CwtAwtImage.java)73
-rw-r--r--src/de/intarsys/nativec/type/NativeVoidType.java (renamed from src/de/intarsys/cwt/font/FontAliasMap.java)30
-rw-r--r--src/de/intarsys/nativec/type/NativeWideString.java117
-rw-r--r--src/de/intarsys/nativec/type/NativeWideStringType.java65
-rw-r--r--src/de/intarsys/nativec/type/StructMember.java365
-rw-r--r--src/de/intarsys/nativec/type/package.html5
-rw-r--r--src/overview.html360
118 files changed, 5062 insertions, 10277 deletions
diff --git a/debian/changelog b/debian/changelog
index 1cf6273..8143058 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+libisnativec-java (5.3.20100629+fix-1) unstable; urgency=low
+
+ * Team upload.
+ * Fix debian/watch and recreate the orig tarball. Update Build-Depends.
+ (Closes: #640354)
+ * Fix Homepage field.
+
+ -- Torsten Werner <twerner@debian.org> Mon, 12 Sep 2011 07:38:57 +0200
+
libisnativec-java (5.3.20100629-3) unstable; urgency=low
* Team upload.
diff --git a/debian/control b/debian/control
index 2057754..d3d7417 100644
--- a/debian/control
+++ b/debian/control
@@ -3,10 +3,9 @@ Section: java
Priority: extra
Maintainer: Steffen Moeller <moeller@debian.org>
Build-Depends: debhelper (>= 7), default-jdk, libjna-java,
- libisrt-java, libisfreetype-java, libswt-gtk-3-java,
- javahelper (>= 0.37)
+ libisrt-java, javahelper (>= 0.37)
Standards-Version: 3.9.2
-Homepage: http://opensource.intarsys.de/home/en/index.php?n=OpenSource.IsCWT
+Homepage: http://opensource.intarsys.de/home/en/index.php?n=IsNativeC.HomePage
Vcs-Git: git://anonscm.debian.org/pkg-java/libisnativec-java.git
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-java/libisnativec-java.git
diff --git a/debian/rules b/debian/rules
index 922409e..42de872 100755
--- a/debian/rules
+++ b/debian/rules
@@ -2,7 +2,7 @@
export JAVA_HOME := /usr/lib/jvm/default-java
-export CLASSPATH := /usr/share/java/jna.jar:/usr/share/java/isrt.jar:/usr/share/java/isfreetype.jar:/usr/share/java/swt-gtk-3.7.jar
+export CLASSPATH := /usr/share/java/jna.jar:/usr/share/java/isrt.jar
%:
dh --with javahelper $@
diff --git a/debian/watch b/debian/watch
index 49c8838..3a08b48 100644
--- a/debian/watch
+++ b/debian/watch
@@ -1,3 +1,3 @@
version=3
-http://sf.net/jpodlib/isCWT\.(.*)\.zip debian debian/orig-tar.sh
+http://sf.net/jpodrenderer/isNative\.(.*)\.zip debian debian/orig-tar.sh
diff --git a/doc/3rd_party_licenses/FTL.txt b/doc/3rd_party_licenses/FTL.txt
deleted file mode 100644
index b645d67..0000000
--- a/doc/3rd_party_licenses/FTL.txt
+++ /dev/null
@@ -1,174 +0,0 @@
- The FreeType Project LICENSE
- ----------------------------
-
- 2002-Apr-11
-
- Copyright 1996-2002 by
- David Turner, Robert Wilhelm, and Werner Lemberg
-
-
-
-Introduction
-============
-
- The FreeType Project is distributed in several archive packages;
- some of them may contain, in addition to the FreeType font engine,
- various tools and contributions which rely on, or relate to, the
- FreeType Project.
-
- This license applies to all files found in such packages, and
- which do not fall under their own explicit license. The license
- affects thus the FreeType font engine, the test programs,
- documentation and makefiles, at the very least.
-
- This license was inspired by the BSD, Artistic, and IJG
- (Independent JPEG Group) licenses, which all encourage inclusion
- and use of free software in commercial and freeware products
- alike. As a consequence, its main points are that:
-
- o We don't promise that this software works. However, we will be
- interested in any kind of bug reports. (`as is' distribution)
-
- o You can use this software for whatever you want, in parts or
- full form, without having to pay us. (`royalty-free' usage)
-
- o You may not pretend that you wrote this software. If you use
- it, or only parts of it, in a program, you must acknowledge
- somewhere in your documentation that you have used the
- FreeType code. (`credits')
-
- We specifically permit and encourage the inclusion of this
- software, with or without modifications, in commercial products.
- We disclaim all warranties covering The FreeType Project and
- assume no liability related to The FreeType Project.
-
-
- Finally, many people asked us for a preferred form for a
- credit/disclaimer to use in compliance with this license. We thus
- encourage you to use the following text:
-
- """
- Portions of this software are copyright � 1996-2002 The FreeType
- Project (www.freetype.org). All rights reserved.
- """
-
-
-Legal Terms
-===========
-
-0. Definitions
---------------
-
- Throughout this license, the terms `package', `FreeType Project',
- and `FreeType archive' refer to the set of files originally
- distributed by the authors (David Turner, Robert Wilhelm, and
- Werner Lemberg) as the `FreeType Project', be they named as alpha,
- beta or final release.
-
- `You' refers to the licensee, or person using the project, where
- `using' is a generic term including compiling the project's source
- code as well as linking it to form a `program' or `executable'.
- This program is referred to as `a program using the FreeType
- engine'.
-
- This license applies to all files distributed in the original
- FreeType Project, including all source code, binaries and
- documentation, unless otherwise stated in the file in its
- original, unmodified form as distributed in the original archive.
- If you are unsure whether or not a particular file is covered by
- this license, you must contact us to verify this.
-
- The FreeType Project is copyright (C) 1996-2000 by David Turner,
- Robert Wilhelm, and Werner Lemberg. All rights reserved except as
- specified below.
-
-1. No Warranty
---------------
-
- THE FREETYPE PROJECT IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS
- BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO
- USE, OF THE FREETYPE PROJECT.
-
-2. Redistribution
------------------
-
- This license grants a worldwide, royalty-free, perpetual and
- irrevocable right and license to use, execute, perform, compile,
- display, copy, create derivative works of, distribute and
- sublicense the FreeType Project (in both source and object code
- forms) and derivative works thereof for any purpose; and to
- authorize others to exercise some or all of the rights granted
- herein, subject to the following conditions:
-
- o Redistribution of source code must retain this license file
- (`FTL.TXT') unaltered; any additions, deletions or changes to
- the original files must be clearly indicated in accompanying
- documentation. The copyright notices of the unaltered,
- original files must be preserved in all copies of source
- files.
-
- o Redistribution in binary form must provide a disclaimer that
- states that the software is based in part of the work of the
- FreeType Team, in the distribution documentation. We also
- encourage you to put an URL to the FreeType web page in your
- documentation, though this isn't mandatory.
-
- These conditions apply to any software derived from or based on
- the FreeType Project, not just the unmodified files. If you use
- our work, you must acknowledge us. However, no fee need be paid
- to us.
-
-3. Advertising
---------------
-
- Neither the FreeType authors and contributors nor you shall use
- the name of the other for commercial, advertising, or promotional
- purposes without specific prior written permission.
-
- We suggest, but do not require, that you use one or more of the
- following phrases to refer to this software in your documentation
- or advertising materials: `FreeType Project', `FreeType Engine',
- `FreeType library', or `FreeType Distribution'.
-
- As you have not signed this license, you are not required to
- accept it. However, as the FreeType Project is copyrighted
- material, only this license, or another one contracted with the
- authors, grants you the right to use, distribute, and modify it.
- Therefore, by using, distributing, or modifying the FreeType
- Project, you indicate that you understand and accept all the terms
- of this license.
-
-4. Contacts
------------
-
- There are two mailing lists related to FreeType:
-
- o freetype@freetype.org
-
- Discusses general use and applications of FreeType, as well as
- future and wanted additions to the library and distribution.
- If you are looking for support, start in this list if you
- haven't found anything to help you in the documentation.
-
- o devel@freetype.org
-
- Discusses bugs, as well as engine internals, design issues,
- specific licenses, porting, etc.
-
- o http://www.freetype.org
-
- Holds the current FreeType web page, which will allow you to
- download our latest development version and read online
- documentation.
-
- You can also contact us individually at:
-
- David Turner <david.turner@freetype.org>
- Robert Wilhelm <robert.wilhelm@freetype.org>
- Werner Lemberg <werner.lemberg@freetype.org>
-
-
---- end of LICENSE.TXT ---
diff --git a/doc/3rd_party_licenses/freetype_license.txt b/doc/3rd_party_licenses/freetype_license.txt
deleted file mode 100644
index f92c00d..0000000
--- a/doc/3rd_party_licenses/freetype_license.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-
-The FreeType 2 font engine is copyrighted work and cannot be used
-legally without a software license. In order to make this project
-usable to a vast majority of developers, we distribute it under two
-mutually exclusive open-source licenses.
-
-This means that *you* must choose *one* of the two licenses described
-below, then obey all its terms and conditions when using FreeType 2 in
-any of your projects or products.
-
- - The FreeType License, found in the file `FTL.TXT', which is similar
- to the original BSD license *with* an advertising clause that forces
- you to explicitly cite the FreeType project in your product's
- documentation. All details are in the license file. This license
- is suited to products which don't use the GNU General Public
- License.
-
- - The GNU General Public License version 2, found in `GPL.TXT' (any
- later version can be used also), for programs which already use the
- GPL. Note that the FTL is incompatible with the GPL due to its
- advertisement clause.
-
-The contributed PCF driver comes with a license similar to that of the X
-Window System. It is compatible to the above two licenses (see file
-src/pcf/readme).
-
-
---- end of licence.txt ---
diff --git a/resource/META-INF/services/de.intarsys.nativec.api.INativeInterface b/resource/META-INF/services/de.intarsys.nativec.api.INativeInterface
new file mode 100644
index 0000000..ba31608
--- /dev/null
+++ b/resource/META-INF/services/de.intarsys.nativec.api.INativeInterface
@@ -0,0 +1 @@
+de.intarsys.nativec.jna.JnaNativeInterface # The JNA based native interface implementation \ No newline at end of file
diff --git a/src/com/sun/jna/FastMemory.java b/src/com/sun/jna/FastMemory.java
new file mode 100644
index 0000000..17657ed
--- /dev/null
+++ b/src/com/sun/jna/FastMemory.java
@@ -0,0 +1,21 @@
+package com.sun.jna;
+
+public class FastMemory extends Pointer {
+
+ protected long size; // Size of the malloc'ed space
+
+ public FastMemory() {
+ super();
+ }
+
+ public FastMemory(int size) {
+ super(Memory.malloc(size));
+ }
+
+ @Override
+ protected void finalize() {
+ Memory.free(peer);
+ peer = 0;
+ }
+
+}
diff --git a/src/com/sun/jna/JNATools.java b/src/com/sun/jna/JNATools.java
new file mode 100644
index 0000000..61f4a8d
--- /dev/null
+++ b/src/com/sun/jna/JNATools.java
@@ -0,0 +1,11 @@
+package com.sun.jna;
+
+public class JNATools {
+
+ public static long getPeer(Pointer p) {
+ if (p == null) {
+ return 0;
+ }
+ return p.peer;
+ }
+}
diff --git a/src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsContext.java b/src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsContext.java
deleted file mode 100644
index 5442979..0000000
--- a/src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsContext.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.awt.environment;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.RenderingHints.Key;
-import java.awt.font.FontRenderContext;
-import java.awt.geom.AffineTransform;
-import java.util.Map;
-
-import de.intarsys.cwt.common.BlendMode;
-import de.intarsys.cwt.common.IPaint;
-import de.intarsys.cwt.environment.IGraphicsContext;
-import de.intarsys.cwt.environment.IGraphicsEnvironment;
-import de.intarsys.cwt.image.IImage;
-
-/**
- * The AWT implementation of {@link IGraphicsContext}
- *
- */
-public class CwtAwtGraphicsContext implements IGraphicsContext {
-
- private BlendMode blendMode = BlendMode.META.getDefault();
-
- private Graphics2D graphics;
-
- private Paint paintActive;
-
- private Paint paintBackground;
-
- private Paint paintForeground;
-
- public CwtAwtGraphicsContext(Graphics2D paramGraphics) {
- graphics = paramGraphics;
- }
-
- public void clip(Shape shape) {
- if (shape == null) {
- return;
- }
- if (shape.getPathIterator(null).isDone()) {
- return;
- }
- graphics.clip(shape);
- }
-
- public void dispose() {
- graphics.dispose();
- }
-
- public void disposeClip(Object clip) {
- // nothing to do for awt
- }
-
- public void draw(Shape s) {
- if (paintActive != paintForeground) {
- graphics.setPaint(paintForeground);
- paintActive = paintForeground;
- }
- graphics.draw(s);
- }
-
- public void drawImage(IImage image, float x, float y) {
- image.drawFromGraphicsContext(this, x, y);
- }
-
- public void drawString(String s, float x, float y) {
- if (paintActive != paintForeground) {
- graphics.setPaint(paintForeground);
- paintActive = paintForeground;
- }
- graphics.drawString(s, x, y);
- }
-
- public void fill(Shape s) {
- if (paintActive != paintBackground) {
- graphics.setPaint(paintBackground);
- paintActive = paintBackground;
- }
- graphics.fill(s);
- }
-
- public Color getBackgroundColor() {
- if (paintBackground instanceof Color) {
- return (Color) paintBackground;
- }
- return graphics.getBackground();
- }
-
- public BlendMode getBlendMode() {
- return blendMode;
- }
-
- public Shape getClip() {
- return graphics.getClip();
- }
-
- public Font getFont() {
- return graphics.getFont();
- }
-
- public FontRenderContext getFontRenderContext() {
- return graphics.getFontRenderContext();
- }
-
- public Color getForegroundColor() {
- if (paintForeground instanceof Color) {
- return (Color) paintForeground;
- }
- return graphics.getColor();
- }
-
- public Graphics2D getGraphics() {
- return graphics;
- }
-
- public IGraphicsEnvironment getGraphicsEnvironment() {
- return CwtAwtGraphicsEnvironment.get();
- }
-
- public RenderingHints getRenderingHints() {
- return graphics.getRenderingHints();
- }
-
- public AffineTransform getTransform() {
- return graphics.getTransform();
- }
-
- public void resetAdvanced() {
- //
- }
-
- public void rotate(float theta) {
- graphics.rotate(theta);
- }
-
- public void scale(float x, float y) {
- graphics.scale(x, y);
- }
-
- public void setBackgroundColor(Color color) {
- graphics.setBackground(color);
- paintBackground = color;
- }
-
- public void setBackgroundPaint(IPaint paint) {
- paint.setBackgroundPaintFromGraphicsContext(this);
- }
-
- public void setBackgroundPaint(Paint paint) {
- paintBackground = paint;
- }
-
- public void setBlendMode(BlendMode blendMode) {
- this.blendMode = blendMode;
- }
-
- public void setClip(Shape shape) {
- if (shape == null) {
- graphics.setClip(null);
- return;
- }
- if (shape.getPathIterator(null).isDone()) {
- // empty clipping path, might result from intersection; will result
- // in no clipping at all
- graphics.setClip(0, 0, 0, 0);
- return;
- }
- graphics.setClip(shape);
- }
-
- public void setFont(Font font) {
- graphics.setFont(font);
- }
-
- public void setForegroundColor(Color c) {
- paintForeground = c;
- }
-
- public void setForegroundPaint(IPaint paint) {
- paint.setForegroundPaintFromGraphicsContext(this);
- }
-
- public void setForegroundPaint(Paint paint) {
- paintForeground = paint;
- }
-
- public void setRenderingHint(Key hintKey, Object hintValue) {
- graphics.setRenderingHint(hintKey, hintValue);
- }
-
- public void setRenderingHints(Map hints) {
- graphics.setRenderingHints(hints);
- }
-
- public void setStroke(Stroke s) {
- graphics.setStroke(s);
- }
-
- public void setTransform(AffineTransform Tx) {
- graphics.setTransform(Tx);
- }
-
- public void transform(AffineTransform Tx) {
- graphics.transform(Tx);
- }
-
- public void translate(float x, float y) {
- graphics.translate(x, y);
- }
-
-}
diff --git a/src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsEnvironment.java b/src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsEnvironment.java
deleted file mode 100644
index 1fea4a8..0000000
--- a/src/de/intarsys/cwt/awt/environment/CwtAwtGraphicsEnvironment.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.awt.environment;
-
-import de.intarsys.cwt.environment.IGraphicsEnvironment;
-
-/**
- * The AWT implementation of {@link IGraphicsEnvironment}
- *
- */
-public class CwtAwtGraphicsEnvironment implements IGraphicsEnvironment {
-
- final private static CwtAwtGraphicsEnvironment ACTIVE = new CwtAwtGraphicsEnvironment();
-
- static public CwtAwtGraphicsEnvironment get() {
- return ACTIVE;
- }
-
-}
diff --git a/src/de/intarsys/cwt/awt/image/CwtAwtImageTools.java b/src/de/intarsys/cwt/awt/image/CwtAwtImageTools.java
deleted file mode 100644
index 9705a1f..0000000
--- a/src/de/intarsys/cwt/awt/image/CwtAwtImageTools.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.awt.image;
-
-import java.awt.Transparency;
-import java.awt.color.ColorSpace;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
-
-/**
- * Tool methods for the AWT CWT image implementation
- */
-public class CwtAwtImageTools {
-
- private static ComponentColorModel GrayColorModel;
-
- private static ComponentColorModel GrayTransparentColorModel;
-
- public static ComponentColorModel RgbColorModel;
-
- public static ComponentColorModel RgbTransparentColorModel;
-
- public static ComponentColorModel getGrayColorModel() {
- if (CwtAwtImageTools.GrayColorModel == null) {
- CwtAwtImageTools.GrayColorModel = new ComponentColorModel(
- ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false,
- Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
- }
- return CwtAwtImageTools.GrayColorModel;
- }
-
- public static ComponentColorModel getGrayTransparentColorModel() {
- if (CwtAwtImageTools.GrayTransparentColorModel == null) {
- CwtAwtImageTools.GrayTransparentColorModel = new ComponentColorModel(
- ColorSpace.getInstance(ColorSpace.CS_GRAY), true, false,
- Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
- }
- return CwtAwtImageTools.GrayTransparentColorModel;
- }
-
- public static ComponentColorModel getRgbColorModel() {
- if (CwtAwtImageTools.RgbColorModel == null) {
- CwtAwtImageTools.RgbColorModel = new ComponentColorModel(ColorSpace
- .getInstance(ColorSpace.CS_sRGB), false, false,
- Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
- }
- return CwtAwtImageTools.RgbColorModel;
- }
-
- public static ComponentColorModel getRgbTransparentColorModel() {
- if (CwtAwtImageTools.RgbTransparentColorModel == null) {
- CwtAwtImageTools.RgbTransparentColorModel = new ComponentColorModel(
- ColorSpace.getInstance(ColorSpace.CS_sRGB), true, false,
- Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
- }
- return CwtAwtImageTools.RgbTransparentColorModel;
- }
-
-}
diff --git a/src/de/intarsys/cwt/common/BlendMode.java b/src/de/intarsys/cwt/common/BlendMode.java
deleted file mode 100644
index d48c3d0..0000000
--- a/src/de/intarsys/cwt/common/BlendMode.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.common;
-
-import de.intarsys.tools.enumeration.EnumItem;
-import de.intarsys.tools.enumeration.EnumMeta;
-
-/**
- * The available rendering modes.
- */
-public class BlendMode extends EnumItem {
-
- public static final BlendMode NORMAL = new BlendMode("normal");
-
- public static final BlendMode MULTIPLY = new BlendMode("multiply");
-
- /** The meta data for the enumeration. */
- public static final EnumMeta<BlendMode> META = getMeta(BlendMode.class);
-
- static {
- NORMAL.setDefault();
- }
-
- public BlendMode(String id) {
- super(id);
- }
-
-}
diff --git a/src/de/intarsys/cwt/common/ShapeWrapper.java b/src/de/intarsys/cwt/common/ShapeWrapper.java
deleted file mode 100644
index 7f332a1..0000000
--- a/src/de/intarsys/cwt/common/ShapeWrapper.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.common;
-
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-
-import de.intarsys.tools.geometry.IShapeWrapper;
-
-public class ShapeWrapper implements IShape, IShapeWrapper {
-
- private Object data;
-
- private Shape shape;
-
- public ShapeWrapper(Shape shape) {
- super();
- this.shape = shape;
- }
-
- public boolean contains(double x, double y) {
- return shape.contains(x, y);
- }
-
- public boolean contains(double x, double y, double w, double h) {
- return shape.contains(x, y, w, h);
- }
-
- public boolean contains(Point2D p) {
- return shape.contains(p);
- }
-
- public boolean contains(Rectangle2D r) {
- return shape.contains(r);
- }
-
- public Shape getBaseShape() {
- return shape;
- }
-
- public Rectangle getBounds() {
- return shape.getBounds();
- }
-
- public Rectangle2D getBounds2D() {
- return shape.getBounds2D();
- }
-
- public Object getData() {
- return data;
- }
-
- public PathIterator getPathIterator(AffineTransform at) {
- return shape.getPathIterator(at);
- }
-
- public PathIterator getPathIterator(AffineTransform at, double flatness) {
- return shape.getPathIterator(at, flatness);
- }
-
- public Shape getShape() {
- return shape;
- }
-
- public boolean intersects(double x, double y, double w, double h) {
- return shape.intersects(x, y, w, h);
- }
-
- public boolean intersects(Rectangle2D r) {
- return shape.intersects(r);
- }
-
- public void setData(Object pData) {
- data = pData;
- }
-
-}
diff --git a/src/de/intarsys/cwt/environment/IGraphicsContext.java b/src/de/intarsys/cwt/environment/IGraphicsContext.java
deleted file mode 100644
index 165e3c3..0000000
--- a/src/de/intarsys/cwt/environment/IGraphicsContext.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.environment;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.RenderingHints.Key;
-import java.awt.geom.AffineTransform;
-import java.util.Map;
-
-import de.intarsys.cwt.common.IPaint;
-import de.intarsys.cwt.image.IImage;
-
-/**
- * A platform independent (SWT, AWT) description of a graphics context.
- * <p>
- * The primary goal of this one is derived from the requirements enforced by
- * processing a PDF context stream.
- */
-public interface IGraphicsContext {
-
- /**
- * Clip the subsequent drawing operations to the shape. This adds the new
- * clip shape to the existing one.
- *
- * @param shape
- */
- public void clip(Shape shape);
-
- /**
- * Dispose the current context and all its resources.
- */
- public void dispose();
-
- /**
- * Draw <code>s</code> using the current graphics context state.
- *
- * @param s
- */
- public void draw(Shape s);
-
- /**
- * Draw image <code>image</code> at coordinates <code>x</code>,
- * <code>y</code>.
- *
- * @param image
- * @param x
- * @param y
- */
- public void drawImage(IImage image, float x, float y);
-
- /**
- * Draw a plain text string in the graphics.
- *
- * @param text
- * @param x
- * @param y
- */
- public void drawString(String text, float x, float y);
-
- /**
- * Fill <code>s</code> using the current graphics context state.
- *
- * @param s
- */
- public void fill(Shape s);
-
- /**
- * The current background color.
- *
- * @return
- */
- public Color getBackgroundColor();
-
- /**
- * The current clip.
- *
- * @return
- */
- public Shape getClip();
-
- /**
- * The current foregroumd color.
- *
- * @return
- */
- public Color getForegroundColor();
-
- /**
- * The associated {@link IGraphicsEnvironment}
- *
- * @return
- */
- public IGraphicsEnvironment getGraphicsEnvironment();
-
- /**
- * The current {@link RenderingHints}
- *
- * @return
- */
- public RenderingHints getRenderingHints();
-
- /**
- * The transformatiom currentlz active.
- *
- * @return
- */
- public AffineTransform getTransform();
-
- /**
- * Rotate the currently active transformation by <code>theta</code>.
- *
- * @param theta
- */
- public void rotate(float theta);
-
- /**
- * Scale the currently active transformation by <code>x</code>,
- * <code>y</code>
- *
- * @param theta
- */
- public void scale(float x, float y);
-
- /**
- * Assign a new background color.
- *
- * @param color
- */
- public void setBackgroundColor(Color color);
-
- /**
- * Assign a new background {@link IPaint}.
- *
- * @param paint
- */
- public void setBackgroundPaint(IPaint paint);
-
- /**
- * Assign the new <code>shape</code> as the clipping shape.
- *
- * @param shape
- */
- public void setClip(Shape shape);
-
- /**
- * Set the current font for writing plain text in the graphics.
- *
- * @param font
- */
- public void setFont(Font font);
-
- /**
- * Assign a new foreground color.
- *
- * @param c
- */
- public void setForegroundColor(Color c);
-
- /**
- * Assign a new foreground {@link IPaint}
- *
- * @param paint
- */
- public void setForegroundPaint(IPaint paint);
-
- /**
- * Set a specific rendering hint.
- *
- * @param hintKey
- * @param hintValue
- */
- public void setRenderingHint(Key hintKey, Object hintValue);
-
- /**
- * Assign the currently active rendering hints.
- *
- * @param hints
- */
- public void setRenderingHints(Map hints);
-
- /**
- * Assign the currently active {@link Stroke}
- *
- * @param s
- */
- public void setStroke(Stroke s);
-
- /**
- * Set the currently active {@link AffineTransform}
- *
- * @param Tx
- */
- public void setTransform(AffineTransform Tx);
-
- /**
- * Transform the {@link IGraphicsEnvironment} by <code>transform</code>
- *
- * @param transform
- */
- public void transform(AffineTransform transform);
-
- /**
- * translate the currently active transformation by <code>x</code>,
- * <code>y</code>
- *
- * @param theta
- */
- public void translate(float x, float y);
-}
diff --git a/src/de/intarsys/cwt/environment/package.html b/src/de/intarsys/cwt/environment/package.html
deleted file mode 100644
index 29e50a8..0000000
--- a/src/de/intarsys/cwt/environment/package.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<html>
-<body>
-An abstract graphics platform implementation.
-<p>
-The main intention is to abstract from AWT and SWT and provide
-a suitable virtual environment for rendering PDF primitives.
-</body>
-</html> \ No newline at end of file
diff --git a/src/de/intarsys/cwt/font/CommonFont.java b/src/de/intarsys/cwt/font/CommonFont.java
deleted file mode 100644
index 562fa99..0000000
--- a/src/de/intarsys/cwt/font/CommonFont.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-abstract public class CommonFont implements IFont {
-
- private IFontProgram fontProgram;
-
- public CommonFont() {
- //
- }
-
- public IFontProgram getFontProgram() {
- return fontProgram;
- }
-
- protected void setFontProgram(IFontProgram fontProgram) {
- this.fontProgram = fontProgram;
- }
-
-}
diff --git a/src/de/intarsys/cwt/font/CommonFontProgram.java b/src/de/intarsys/cwt/font/CommonFontProgram.java
deleted file mode 100644
index 3a8335a..0000000
--- a/src/de/intarsys/cwt/font/CommonFontProgram.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-import de.intarsys.tools.locator.ILocator;
-
-abstract public class CommonFontProgram implements IFontProgram {
-
- final private ILocator locator;
-
- final private IFont font;
-
- public CommonFontProgram(IFont font, ILocator locator) {
- this.font = font;
- this.locator = locator;
- }
-
- public IFont getFont() {
- return font;
- }
-
- public ILocator getLocator() {
- return locator;
- }
-}
diff --git a/src/de/intarsys/cwt/font/FontEnvironment.java b/src/de/intarsys/cwt/font/FontEnvironment.java
deleted file mode 100644
index 1ed31ed..0000000
--- a/src/de/intarsys/cwt/font/FontEnvironment.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-import java.awt.Font;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import sun.font.FontManager;
-import de.intarsys.cwt.freetype.Face;
-import de.intarsys.cwt.freetype.Freetype;
-import de.intarsys.cwt.freetype.Library;
-import de.intarsys.tools.installresource.InstallFileList;
-import de.intarsys.tools.locator.FileLocator;
-import de.intarsys.tools.stream.StreamTools;
-
-/**
- *
- */
-public class FontEnvironment {
-
- private static final Logger Log = PACKAGE.Log;
-
- private static FontEnvironment Unique = new FontEnvironment();
-
- static public FontEnvironment get() {
- return Unique;
- }
-
- static public void set(FontEnvironment environment) {
- Unique = environment;
- }
-
- private List<ClassLoader> fontClassLoaders = new ArrayList<ClassLoader>();
-
- private List<File> fontDirectories = new ArrayList<File>();
-
- private List<File> fontFiles = new ArrayList<File>();
-
- private boolean registeredSystem = false;
-
- private boolean registeredUser = false;
-
- public FontEnvironment() {
- registerFontClassLoader(getClass().getClassLoader());
- }
-
- synchronized public ClassLoader[] getFontClassLoaders() {
- return fontClassLoaders
- .toArray(new ClassLoader[fontClassLoaders.size()]);
- }
-
- synchronized public File[] getFontDirectories() {
- return fontDirectories.toArray(new File[fontDirectories.size()]);
- }
-
- synchronized public File[] getFontFiles() {
- return fontFiles.toArray(new File[fontFiles.size()]);
- }
-
- /**
- * This method determines the system's font directories.
- *
- * @return an array containing the font directory paths found on the local
- * system
- */
- synchronized public File[] getSystemFontDirectories() {
- String definition = null;
- // force FontManager initialization
- Font.decode("dummy").getFamily(); //$NON-NLS-1$
- definition = FontManager.getFontPath(true);
- if (definition == null) {
- return new File[0];
- }
- String[] names = definition.split(System.getProperty("path.separator")); //$NON-NLS-1$
- File[] files = new File[names.length];
- for (int i = 0; i < names.length; i++) {
- files[i] = new File(names[i]);
- }
- return files;
- }
-
- protected void loadFontClassLoader(Library library, ClassLoader loader) {
- try {
- InstallFileList installer = new InstallFileList("fonts",
- "fonts.list", false);
- installer.loadAll();
- File[] roots = installer.getFiles();
- for (int i = 0; i < roots.length; i++) {
- File root = roots[i];
- File[] fontFiles = root.listFiles();
- for (int j = 0; j < fontFiles.length; j++) {
- File file = fontFiles[j];
- try {
- processFontFile(library, file);
- } catch (IOException e) {
- Log.log(Level.WARNING, "error loading font '"
- + file.getName() + "'", e);
- } finally {
- }
- }
- }
- } catch (IOException e) {
- Log.log(Level.WARNING,
- "error looking up 'font/fonts.list' resources", e);
- }
- }
-
- protected void loadFontDirectory(Library library, File directory) {
- if (!directory.exists()) {
- return;
- }
- if (!directory.isDirectory()) {
- return;
- }
- File[] files = directory.listFiles();
- if (files == null) {
- return;
- }
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
- loadFontFile(library, file);
- }
- }
-
- protected void loadFontFile(Library library, File file) {
- if (!file.isFile()) {
- return;
- }
- String filepath = file.getAbsolutePath();
- try {
- /*
- * the absolute path/canonical path check is used to find out if the
- * file path contains a symbolic link. if so we can ignore the file
- * because it will also show up in another directory as a "real"
- * file.
- */
- if (!filepath.equals(file.getCanonicalPath())) {
- return;
- }
- } catch (IOException ex) {
- return;
- }
- loadFontUnchecked(library, filepath);
- }
-
- protected void loadFontMapClassLoader(Library library, ClassLoader loader) {
- try {
- Enumeration<URL> urls = loader.getResources("fonts/fonts.maps");
- while (urls.hasMoreElements()) {
- URL url = urls.nextElement();
- InputStream is = null;
- try {
- is = url.openStream();
- parseMaps(library, loader, is);
- } catch (IOException e) {
- Log.log(Level.WARNING,
- "error loading 'fonts/fonts.maps' from '" + url
- + "'", e);
- } finally {
- StreamTools.close(is);
- }
- }
- } catch (IOException e) {
- Log.log(Level.WARNING,
- "error looking up 'font/fonts.maps' resources", e);
- }
- }
-
- protected IFont loadFontUnchecked(Library library, String filepath) {
- FileLocator locator = new FileLocator(filepath);
- Face face = library.newFace(filepath, 0);
- if (face != null) {
- IFont font = null;
- try {
- font = GenericFont.createNew(locator, face);
- FontRegistry.get().registerFont(font);
- } finally {
- face.doneFace();
- }
- return font;
- } else {
- // Log.log(Level.WARNING, "can't register font for " + filepath);
- return null;
- }
- }
-
- protected void loadSystemFonts(Library library) {
- File[] files;
- files = getSystemFontDirectories();
- for (int i = 0; i < files.length; i++) {
- File directory = files[i];
- loadFontDirectory(library, directory);
- }
- }
-
- protected void loadUserFonts(Library library) {
- File[] files;
- files = getFontDirectories();
- for (int i = 0; i < files.length; i++) {
- File directory = files[i];
- loadFontDirectory(library, directory);
- }
- files = getFontFiles();
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
- loadFontFile(library, file);
- }
- ClassLoader[] loaders = getFontClassLoaders();
- for (int i = 0; i < loaders.length; i++) {
- ClassLoader loader = loaders[i];
- loadFontClassLoader(library, loader);
- loadFontMapClassLoader(library, loader);
- }
- }
-
- protected void parseMaps(Library library, ClassLoader loader, InputStream is)
- throws IOException {
- StringBuilder sb = new StringBuilder();
- int i = is.read();
- while (i != -1) {
- if (i == '\n') {
- String map = sb.toString().trim();
- processFontMap(library, loader, map);
- sb.setLength(0);
- i = is.read();
- continue;
- }
- sb.append((char) i);
- i = is.read();
- }
- String map = sb.toString().trim();
- processFontMap(library, loader, map);
- }
-
- protected void processFontFile(Library library, File file)
- throws IOException {
- IFont font = loadFontUnchecked(library, file.getAbsolutePath());
- if (font == null) {
- return;
- }
- FontTools.mapFont(font.getFontName(), font);
- }
-
- protected void processFontMap(Library library, ClassLoader loader,
- String map) throws IOException {
- if (map.length() == 0 || map.startsWith("#")) {
- return;
- }
- String[] split = map.split("\\=");
- if (split.length < 2) {
- return;
- }
- FontTools.mapAlias(split[0], split[1]);
- }
-
- public synchronized void registerFontClassLoader(ClassLoader loader) {
- fontClassLoaders.add(loader);
- }
-
- public synchronized void registerFontDirectory(File directory) {
- fontDirectories.add(directory);
- }
-
- synchronized public void registerFontFile(File file) {
- fontFiles.add(file);
- }
-
- synchronized public boolean registerSystemFonts() {
- if (registeredSystem) {
- return false;
- }
- registeredSystem = true;
- Library library = Freetype.initFreeType();
- try {
- loadSystemFonts(library);
- } finally {
- library.doneFreeType();
- }
- return true;
- }
-
- synchronized public boolean registerUserFonts() {
- if (registeredUser) {
- return false;
- }
- registeredUser = true;
- Library library = Freetype.initFreeType();
- try {
- loadUserFonts(library);
- } finally {
- library.doneFreeType();
- }
- return true;
- }
-
-}
diff --git a/src/de/intarsys/cwt/font/FontFamily.java b/src/de/intarsys/cwt/font/FontFamily.java
deleted file mode 100644
index 99c624b..0000000
--- a/src/de/intarsys/cwt/font/FontFamily.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * An abstraction of a fonts family.
- */
-public class FontFamily implements IFontFamily {
-
- private final IFont[] fonts;
-
- private String name = "";
-
- private String type = "";
-
- public FontFamily(String name) {
- fonts = new IFont[FontStyle.COUNT];
- this.name = name;
- }
-
- public String getFamilyName() {
- return name;
- }
-
- public IFont getFont(FontStyle style) {
- return fonts[style.getIndex()];
- }
-
- public Iterator<IFont> getFontIterator() {
- return new Iterator<IFont>() {
- int index = 0;
-
- public boolean hasNext() {
- while (index < fonts.length) {
- if (fonts[index] != null) {
- return true;
- }
- index++;
- }
- return false;
- }
-
- public IFont next() {
- while (index < fonts.length) {
- if (fonts[index] != null) {
- return fonts[index++];
- }
- index++;
- }
- throw new NoSuchElementException("no more fonts"); //$NON-NLS-1$
- }
-
- public void remove() {
- throw new UnsupportedOperationException("can not remove font"); //$NON-NLS-1$
- }
- };
- }
-
- public IFont[] getFonts() {
- List<IFont> result = new ArrayList<IFont>();
- for (int i = 0; i < fonts.length; i++) {
- if (fonts[i] != null) {
- result.add(fonts[i]);
- }
- }
- return result.toArray(new IFont[result.size()]);
- }
-
- public FontStyle[] getFontStyles() {
- List<FontStyle> result = new ArrayList<FontStyle>();
- for (int i = 0; i < fonts.length; i++) {
- if (fonts[i] != null) {
- result.add(fonts[i].getFontStyle());
- }
- }
- return result.toArray(new FontStyle[result.size()]);
- }
-
- public String getFontType() {
- return type;
- }
-
- public void registerFont(IFont font) {
- fonts[font.getFontStyle().getIndex()] = font;
- type = font.getFontType();
- }
-}
diff --git a/src/de/intarsys/cwt/font/FontQuery.java b/src/de/intarsys/cwt/font/FontQuery.java
deleted file mode 100644
index 462990c..0000000
--- a/src/de/intarsys/cwt/font/FontQuery.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package de.intarsys.cwt.font;
-
-public class FontQuery implements IFontQuery {
-
- /**
- * The font type requested
- */
- private String fontType = null;
-
- /**
- * The font family requested
- */
- private String fontFamilyName;
-
- /**
- * The font name requested
- */
- private String fontName;
-
- /**
- * The font style required
- */
- private FontStyle fontStyle;
-
- public FontQuery() {
- super();
- }
-
- public FontQuery(String fontName) {
- super();
- setFontName(fontName);
- }
-
- public FontQuery(String family, FontStyle style) {
- super();
- setFontFamilyName(family);
- setFontStyle(style);
- }
-
- public FontQuery(String family, String style) {
- super();
- setFontFamilyName(family);
- setFontStyle(FontStyle.getFontStyle(style));
- }
-
- public String getFontFamilyName() {
- if (fontFamilyName == null) {
- return FontTools.getFontFamilyName(fontName);
- } else {
- return fontFamilyName;
- }
- }
-
- public String getFontName() {
- return fontName;
- }
-
- public Object getFontNameCanonical() {
- String tempFamilyName = getFontFamilyName();
- FontStyle tempStyle = null;
- if (getFontStyle() == null) {
- tempStyle = FontTools.getFontStyle(fontName);
- } else {
- tempStyle = getFontStyle();
- }
- return FontTools.createCanonicalName(tempFamilyName, tempStyle.getId());
- }
-
- public FontStyle getFontStyle() {
- return fontStyle;
- }
-
- public String getFontType() {
- return fontType;
- }
-
- public void setFontFamilyName(String fontFamilyName) {
- this.fontFamilyName = fontFamilyName;
- }
-
- public void setFontName(String fontName) {
- this.fontName = fontName;
- }
-
- public void setFontStyle(FontStyle fontStyle) {
- this.fontStyle = fontStyle;
- }
-
- public void setFontType(String fontType) {
- this.fontType = fontType;
- }
-}
diff --git a/src/de/intarsys/cwt/font/FontRegistry.java b/src/de/intarsys/cwt/font/FontRegistry.java
deleted file mode 100644
index 04cbd32..0000000
--- a/src/de/intarsys/cwt/font/FontRegistry.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-public class FontRegistry {
- private static IFontRegistry ACTIVE = new StandardFontRegistry();
-
- static public IFontRegistry get() {
- return ACTIVE;
- }
-
- static public void set(IFontRegistry active) {
- ACTIVE = active;
- }
-}
diff --git a/src/de/intarsys/cwt/font/FontStyle.java b/src/de/intarsys/cwt/font/FontStyle.java
deleted file mode 100644
index 2cdaca3..0000000
--- a/src/de/intarsys/cwt/font/FontStyle.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-/**
- *
- */
-public class FontStyle {
- /** The number of font styles */
- public static final int COUNT = 4;
-
- /** The enumeration of supported font styles */
- public static final FontStyle UNDEFINED = new FontStyle("?", -1); //$NON-NLS-1$
-
- public static final FontStyle REGULAR = new FontStyle("Regular", 0); //$NON-NLS-1$
-
- public static final FontStyle ITALIC = new FontStyle("Italic", 1); //$NON-NLS-1$
-
- public static final FontStyle BOLD = new FontStyle("Bold", 2); //$NON-NLS-1$
-
- public static final FontStyle BOLD_ITALIC = new FontStyle("BoldItalic", 3); //$NON-NLS-1$
-
- public static FontStyle getFontStyle(String name) {
- if (name == null) {
- return REGULAR;
- }
- name = name.trim().toLowerCase();
- boolean bold = false;
- boolean italic = false;
- if (name.indexOf("bold") >= 0) { //$NON-NLS-1$
- bold = true;
- }
- if (name.indexOf("italic") >= 0) { //$NON-NLS-1$
- italic = true;
- }
- if (name.indexOf("oblique") >= 0) { //$NON-NLS-1$
- italic = true;
- }
- if (bold) {
- if (italic) {
- return BOLD_ITALIC;
- } else {
- return BOLD;
- }
- } else {
- if (italic) {
- return ITALIC;
- } else {
- return REGULAR;
- }
- }
- }
-
- /** The external representation of the font style */
- private final String id;
-
- private final int index;
-
- private FontStyle(String label, int index) {
- this.id = label;
- this.index = index;
- }
-
- public FontStyle getBoldFlavor() {
- if (this == FontStyle.ITALIC) {
- return FontStyle.BOLD_ITALIC;
- } else {
- return FontStyle.BOLD;
- }
- }
-
- public String getId() {
- return id;
- }
-
- protected int getIndex() {
- return index;
- }
-
- public FontStyle getItalicFlavor() {
- if (this == FontStyle.BOLD) {
- return FontStyle.BOLD_ITALIC;
- } else {
- return FontStyle.ITALIC;
- }
- }
-
- @Override
- public String toString() {
- return getId();
- }
-}
diff --git a/src/de/intarsys/cwt/font/FontTools.java b/src/de/intarsys/cwt/font/FontTools.java
deleted file mode 100644
index 628fef2..0000000
--- a/src/de/intarsys/cwt/font/FontTools.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-public class FontTools {
-
- static public String createCanonicalName(IFont font) {
- return createCanonicalName(font.getFontFamilyName(), font
- .getFontStyle().getId());
- }
-
- static public String createCanonicalName(String fontFamilyName,
- String styleName) {
- return fontFamilyName.replaceAll("\\s", "") + "," + styleName;
- }
-
- public static String getFontFamilyName(String fontName) {
- if (fontName == null) {
- return null;
- }
- int posMinus = fontName.indexOf('-');
- if (posMinus > 0) {
- fontName = fontName.substring(0, posMinus);
- }
- return fontName;
- }
-
- public static FontStyle getFontStyle(String fontName) {
- if (fontName == null) {
- return FontStyle.REGULAR;
- }
- int posMinus = fontName.indexOf('-');
- if (posMinus > 0) {
- fontName = fontName.substring(posMinus + 1);
- }
- return FontStyle.getFontStyle(fontName);
- }
-
- static public IFont lookupFont(IFontQuery query) {
- IFont result = lookupFontOrMap(query);
- if (result == null && FontEnvironment.get().registerUserFonts()) {
- result = lookupFontOrMap(query);
- }
- // do not nest in the condition above!
- if (result == null && FontEnvironment.get().registerSystemFonts()) {
- result = lookupFontOrMap(query);
- }
- return result;
- }
-
- static protected IFont lookupFontOrMap(IFontQuery query) {
- IFont result = FontRegistry.get().lookupFont(query);
- if (result == null) {
- result = FontMapper.get().lookupFont(query.getFontName());
- }
- return result;
- }
-
- static public void mapAlias(String name, String alias) {
- FontAliasMap map = new FontAliasMap(FontMapper.get(), name, alias);
- FontMapper.get().registerFontMap(map);
- }
-
- static public void mapFont(String name, IFont font) {
- FontFontMap map = new FontFontMap(FontMapper.get(), name, font);
- FontMapper.get().registerFontMap(map);
- }
-
-}
diff --git a/src/de/intarsys/cwt/font/GenericFont.java b/src/de/intarsys/cwt/font/GenericFont.java
deleted file mode 100644
index 53f604f..0000000
--- a/src/de/intarsys/cwt/font/GenericFont.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-import de.intarsys.cwt.freetype.Face;
-import de.intarsys.cwt.freetype.SfntName;
-import de.intarsys.tools.locator.ILocator;
-
-public class GenericFont extends CommonFont {
-
- public static GenericFont createNew(ILocator locator, Face face) {
- String fontPSName = face.getPostscriptName();
- String familyName = face.getFamilyName();
- String styleName = face.getStyleName();
- String fontName = null;
- // look up font name for TrueType
- int sfntCount = face.getSfntNameCount();
- for (int i = 0; i < sfntCount; i++) {
- SfntName sfntName = face.getSfntName(i);
- if (sfntName.getNameId() == 4) {
- // full font name
- fontName = sfntName.getName();
- if (sfntName.getPlatformId() == 3) {
- // try to use the microsoft platform name
- break;
- }
- }
- }
- if (fontPSName == null) {
- fontPSName = familyName;
- }
- if (fontName == null) {
- fontName = fontPSName;
- }
- FontStyle style = FontStyle.getFontStyle(styleName);
- // ...little bit ugly, but clean up someday
- GenericFont font = new GenericFont();
- GenericFontProgram fontProgram = new GenericFontProgram(font, locator);
- font.setFontProgram(fontProgram);
- font.setFontFamilyName(familyName);
- font.setFontNamePostScript(fontPSName);
- font.setFontName(fontName);
- font.setFontStyle(style);
- String type = locator.getType();
- if (type != null) {
- type = type.toLowerCase();
- }
- if ("ttf".equals(type) || "ttc".equals(type) || "otf".equals(type)
- || "otc".equals(type)) {
- font.setFontType("TrueType");
- } else if ("pfb".equals(type)) {
- font.setFontType("Type1");
- } else {
- font.setFontType("Unknown");
- }
- return font;
- }
-
- private String fontType;
-
- private String fontName;
-
- private String fontNamePostScript;
-
- private String fontFamilyName;
-
- private FontStyle fontStyle;
-
- protected GenericFont() {
- super();
- }
-
- public String getFontFamilyName() {
- return fontFamilyName;
- }
-
- public String getFontName() {
- return fontName;
- }
-
- public String getFontNameCanonical() {
- String tempFamilyName = null;
- FontStyle tempStyle = null;
- if (getFontFamilyName() == null) {
- tempFamilyName = FontTools.getFontFamilyName(getFontName());
- } else {
- tempFamilyName = getFontFamilyName();
- }
- if (getFontStyle() == null) {
- tempStyle = FontTools.getFontStyle(getFontName());
- } else {
- tempStyle = getFontStyle();
- }
- return FontTools.createCanonicalName(tempFamilyName, tempStyle.getId());
- }
-
- public String getFontNamePostScript() {
- return fontNamePostScript;
- }
-
- public FontStyle getFontStyle() {
- return fontStyle;
- }
-
- public String getFontType() {
- return fontType;
- }
-
- protected void setFontFamilyName(String familyName) {
- this.fontFamilyName = familyName;
- }
-
- protected void setFontName(String fontName) {
- this.fontName = fontName;
- }
-
- protected void setFontNamePostScript(String fontPSName) {
- this.fontNamePostScript = fontPSName;
- }
-
- protected void setFontStyle(FontStyle style) {
- this.fontStyle = style;
- }
-
- protected void setFontType(String fontType) {
- this.fontType = fontType;
- }
-}
diff --git a/src/de/intarsys/cwt/font/GenericFontProgram.java b/src/de/intarsys/cwt/font/GenericFontProgram.java
deleted file mode 100644
index 70a5b81..0000000
--- a/src/de/intarsys/cwt/font/GenericFontProgram.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-import de.intarsys.tools.locator.ILocator;
-
-public class GenericFontProgram extends CommonFontProgram {
-
- protected GenericFontProgram(IFont font, ILocator locator) {
- super(font, locator);
- }
-
-}
diff --git a/src/de/intarsys/cwt/font/IFontQuery.java b/src/de/intarsys/cwt/font/IFontQuery.java
deleted file mode 100644
index d43f216..0000000
--- a/src/de/intarsys/cwt/font/IFontQuery.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package de.intarsys.cwt.font;
-
-/**
- * An object that can select {@link IFont} instances within a collection.
- *
- */
-public interface IFontQuery {
-
- /**
- * The desired font family for the {@link IFont}.
- *
- * @return The desired font family for the {@link IFont}.
- */
- public String getFontFamilyName();
-
- /**
- * The desired font name for the {@link IFont}.
- *
- * @return The desired font name for the {@link IFont}.
- */
- public String getFontName();
-
- /**
- * The desired font name for the {@link IFont}.
- *
- * @return The desired font name for the {@link IFont}.
- */
- public Object getFontNameCanonical();
-
- /**
- * The desired font style for the {@link IFont}.
- *
- * @return The desired font style for the {@link IFont}.
- */
- public FontStyle getFontStyle();
-
- /**
- * The desired font type for the {@link IFont} (such as "Type1" or
- * "TrueType"). <code>null</code>indicates a font of any type.
- *
- * @return The desired font type for the {@link IFont}.
- */
- public String getFontType();
-
-}
diff --git a/src/de/intarsys/cwt/font/IFontRegistry.java b/src/de/intarsys/cwt/font/IFontRegistry.java
deleted file mode 100644
index e9ed0e8..0000000
--- a/src/de/intarsys/cwt/font/IFontRegistry.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-/**
- * A registry of {@link IFont} instances.
- *
- */
-public interface IFontRegistry {
-
- /**
- * The {@link IFontFamily} instances formed by the {@link IFont} instances
- * in this {@link IFontRegistry}.
- *
- * @return The {@link IFontFamily} instances formed by the {@link IFont}
- * instances in this {@link IFontRegistry}.
- */
- public IFontFamily[] getFontFamilies();
-
- /**
- * The {@link IFont} instances in this {@link IFontRegistry}.
- *
- * @return The {@link IFont} instances in this {@link IFontRegistry}.
- *
- */
- public IFont[] getFonts();
-
- /**
- * The {@link IFont} selected by the {@link IFontQuery}.
- *
- * @param query
- * A {@link IFontQuery} describing a single {@link IFont}.
- *
- * @return The {@link IFont} selected by the {@link IFontQuery}.
- *
- */
- public IFont lookupFont(IFontQuery query);
-
- /**
- * The {@link IFontFamily} selected by the {@link IFontQuery}.
- *
- * @param query
- * A {@link IFontQuery} describing a single {@link IFontFamily}.
- *
- * @return The {@link IFontFamily} selected by the {@link IFontQuery}.
- *
- */
- public IFontFamily lookupFontFamily(IFontQuery query);
-
- /**
- * Add a new {@link IFont} to the {@link IFontRegistry}.
- *
- * @param font
- * The new {@link IFont}
- */
- public void registerFont(IFont font);
-}
diff --git a/src/de/intarsys/cwt/font/PACKAGE.java b/src/de/intarsys/cwt/font/PACKAGE.java
deleted file mode 100644
index 0fccabb..0000000
--- a/src/de/intarsys/cwt/font/PACKAGE.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-import java.util.logging.Logger;
-
-import de.intarsys.tools.logging.LogTools;
-import de.intarsys.tools.message.MessageBundle;
-import de.intarsys.tools.message.MessageBundleTools;
-
-public class PACKAGE {
-
- public final static MessageBundle Messages = MessageBundleTools
- .getMessageBundle(PACKAGE.class);
-
- public final static Logger Log = LogTools.getLogger(PACKAGE.class);
-
-}
diff --git a/src/de/intarsys/cwt/font/StandardFontRegistry.java b/src/de/intarsys/cwt/font/StandardFontRegistry.java
deleted file mode 100644
index 0d322d8..0000000
--- a/src/de/intarsys/cwt/font/StandardFontRegistry.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import de.intarsys.tools.collection.ListTools;
-
-/**
- *
- */
-public class StandardFontRegistry implements IFontRegistry {
-
- private final Map<String, IFontFamily> fontFamilyMap = new HashMap<String, IFontFamily>();
-
- private final List<IFontFamily> fontFamilies = new ArrayList<IFontFamily>();
-
- private final Map<String, Object> fontMap = new HashMap<String, Object>();
-
- private final List<IFont> fonts = new ArrayList<IFont>();
-
- public StandardFontRegistry() {
- //
- }
-
- protected IFont basicLookup(String key, IFontQuery query) {
- if (key == null) {
- return null;
- }
- Object result = fontMap.get(key);
- if (result == null) {
- return null;
- } else if (result instanceof IFont) {
- return (IFont) result;
- } else {
- // collision
- // there are a number of ill declared fonts around....
- for (Iterator it = ((List) result).iterator(); it.hasNext();) {
- IFont font = (IFont) it.next();
- if (basicMatchFamilyStyle(query, font)) {
- return font;
- }
- }
- for (Iterator it = ((List) result).iterator(); it.hasNext();) {
- IFont font = (IFont) it.next();
- if (basicMatchFamily(query, font)) {
- return font;
- }
- }
- return null;
- }
- }
-
- protected boolean basicMatchFamily(IFontQuery query, IFont font) {
- return query.getFontFamilyName().indexOf(font.getFontFamilyName()) >= 0;
- }
-
- protected boolean basicMatchFamilyStyle(IFontQuery query, IFont font) {
- return query.getFontNameCanonical().equals(font.getFontNameCanonical());
- }
-
- protected void basicRegister(String key, IFont value) {
- // overwrite - this is the most obvious case
- Object previous = fontMap.put(key, value);
- if (previous == null) {
- return;
- }
- if (previous instanceof List) {
- ((List) previous).add(value);
- // reset, was overwritten
- fontMap.put(key, previous);
- } else {
- // new entry
- fontMap.put(key, ListTools.with(previous, value));
- }
- }
-
- synchronized public IFontFamily[] getFontFamilies() {
- FontEnvironment.get().registerUserFonts();
- FontEnvironment.get().registerSystemFonts();
- return fontFamilies.toArray(new IFontFamily[fontFamilies.size()]);
- }
-
- synchronized public IFont[] getFonts() {
- FontEnvironment.get().registerUserFonts();
- FontEnvironment.get().registerSystemFonts();
- return fonts.toArray(new IFont[fonts.size()]);
- }
-
- protected Object getLookupKeyFontFamily(IFontQuery query) {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- if (query.getFontType() == null) {
- sb.append("Any");
- } else {
- sb.append(query.getFontType());
- }
- sb.append("]");
- sb.append(query.getFontFamilyName());
- return sb.toString();
- }
-
- protected String getLookupKeyFontName(IFontQuery query) {
- if (query.getFontName() == null) {
- return null;
- }
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- if (query.getFontType() == null) {
- sb.append("Any");
- } else {
- sb.append(query.getFontType());
- }
- sb.append("]");
- sb.append(query.getFontName());
- return sb.toString();
- }
-
- protected String getLookupKeyFontNameAsCanonical(IFontQuery query) {
- if (query.getFontName() == null) {
- return null;
- }
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- if (query.getFontType() == null) {
- sb.append("Any");
- } else {
- sb.append(query.getFontType());
- }
- sb.append("-canonical]");
- sb.append(query.getFontName());
- return sb.toString();
- }
-
- protected String getLookupKeyFontNameCanonical(IFontQuery query) {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- if (query.getFontType() == null) {
- sb.append("Any");
- } else {
- sb.append(query.getFontType());
- }
- sb.append("-canonical]");
- sb.append(query.getFontNameCanonical());
- return sb.toString();
- }
-
- protected String getLookupKeyFontNamePostScript(IFontQuery query) {
- if (query.getFontName() == null) {
- return null;
- }
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- if (query.getFontType() == null) {
- sb.append("Any");
- } else {
- sb.append(query.getFontType());
- }
- sb.append("-postscript]");
- sb.append(query.getFontName());
- return sb.toString();
- }
-
- public IFont lookupFont(IFontQuery query) {
- // best fallbacks ever
- IFont result = basicLookup(getLookupKeyFontName(query), query);
- if (result == null) {
- result = basicLookup(getLookupKeyFontNamePostScript(query), query);
- if (result == null) {
- result = basicLookup(getLookupKeyFontNameCanonical(query),
- query);
- if (result == null) {
- result = basicLookup(
- getLookupKeyFontNameAsCanonical(query), query);
- }
- }
- }
- return result;
- }
-
- public IFontFamily lookupFontFamily(IFontQuery query) {
- return fontFamilyMap.get(getLookupKeyFontFamily(query));
- }
-
- public void registerFont(IFont font) {
- String type = font.getFontType();
- String familyName = font.getFontFamilyName();
- if (familyName != null) {
- String familyKey = "[" + type + "]" + familyName;
- IFontFamily fontFamily = fontFamilyMap.get(familyKey);
- if (fontFamily == null) {
- fontFamily = new FontFamily(familyName);
- fontFamilyMap.put(familyKey, fontFamily);
- fontFamilies.add(fontFamily);
- }
- fontFamily.registerFont(font);
- //
- familyKey = "[Any]" + familyName;
- fontFamily = fontFamilyMap.get(familyKey);
- if (fontFamily == null) {
- fontFamily = new FontFamily(familyName);
- fontFamilyMap.put(familyKey, fontFamily);
- }
- fontFamily.registerFont(font);
- }
- String fontName = font.getFontName();
- String fontNamePostScript = font.getFontNamePostScript();
- String fontNameCanonical = font.getFontNameCanonical();
- String fontKey;
- fontKey = "[" + type + "]" + fontName;
- basicRegister(fontKey, font);
- fontKey = "[" + type + "-postscript]" + fontNamePostScript;
- basicRegister(fontKey, font);
- fontKey = "[" + type + "-canonical]" + fontNameCanonical;
- basicRegister(fontKey, font);
- fontKey = "[Any]" + fontName;
- basicRegister(fontKey, font);
- fontKey = "[Any-postscript]" + fontNamePostScript;
- basicRegister(fontKey, font);
- fontKey = "[Any-canonical]" + fontNameCanonical;
- basicRegister(fontKey, font);
- //
- fonts.add(font);
- }
-
- protected String removeSpaces(String name) {
- int pos = 0;
- while ((pos = name.indexOf(' ')) != -1) {
- name = name.substring(0, pos) + name.substring(pos + 1);
- }
- return name;
- }
-
-}
diff --git a/src/de/intarsys/cwt/font/afm/AFM.java b/src/de/intarsys/cwt/font/afm/AFM.java
deleted file mode 100644
index 2f85dfa..0000000
--- a/src/de/intarsys/cwt/font/afm/AFM.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.afm;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import de.intarsys.tools.locator.ILocator;
-import de.intarsys.tools.randomaccess.IRandomAccess;
-import de.intarsys.tools.stream.StreamTools;
-
-/**
- * A simple implementation for an adobe font metric object.
- *
- * <p>
- * This implementation will hold all afm attributes in a generic collection. The
- * char metrics are read explicitly and held in a list of AFMChar's. No other
- * information (like kerning) is extracted.
- * </p>
- *
- * <p>
- * See the "Adobe Font Metrics File Format Specification"
- * </p>
- */
-public class AFM {
-
- public static final String ATTR_FontName = "FontName"; //$NON-NLS-1$
-
- public static AFM createFromLocator(ILocator locator) throws IOException {
- AFM result = new AFM();
- result.setLocator(locator);
- result.initializeFromLocator();
- return result;
- }
-
- public static AFM createNew() {
- return new AFM();
- }
-
- private ILocator locator;
-
- // the chars described in the font metric file
- // ... organized by codePoint
- private Map<Integer, AFMChar> charsByCode = new HashMap<Integer, AFMChar>();
-
- // ... organized by name
- private Map<String, AFMChar> charsByName = new HashMap<String, AFMChar>();
-
- // attribute name/value pairs parsed form the font metric file
- private Map<String, String> attributes = new HashMap<String, String>();
-
- protected AFM() {
- super();
- }
-
- protected void addChar(AFMChar c) {
- if (c.getCode() != -1) {
- charsByCode.put(new Integer(c.getCode()), c);
- }
-
- if (c.getName() != null) {
- charsByName.put(c.getName(), c);
- }
- }
-
- /**
- * The string value for a generic attribute designated by <code>name</code>.
- *
- * @param name
- * The name of the attribute to lookup.
- *
- * @return The string value for a generic attribute designated by
- * <code>name</code>.
- */
- public String getAttribute(String name) {
- return attributes.get(name);
- }
-
- /**
- * The character representation for a byte code point given in
- * <code>codePoint</code>.
- *
- * @param codePoint
- * The byte code point.
- *
- * @return The character representation for a byte code point given in
- * <code>codePoint</code>.
- */
- public AFMChar getCharByCode(int codePoint) {
- return charsByCode.get(new Integer(codePoint));
- }
-
- /**
- * The character representation for an adobe glyph name given in
- * <code>name</code>.
- *
- * @param name
- * The adobe glyph name.
- *
- * @return The character representation for an adobe glyph name given in
- * <code>name</code>.
- */
- public AFMChar getCharByName(String name) {
- return charsByName.get(name);
- }
-
- public String getFontName() {
- return getAttribute(ATTR_FontName);
- }
-
- public ILocator getLocator() {
- return locator;
- }
-
- protected void initializeFromLocator() throws IOException {
- IRandomAccess random = null;
- try {
- random = getLocator().getRandomAccess();
- AFMParser parser = new AFMParser(this);
- parser.parse(random);
- } finally {
- StreamTools.close(random);
- }
- }
-
- protected void setAttribute(String name, String value) {
- attributes.put(name, value);
- }
-
- protected void setLocator(ILocator locator) {
- this.locator = locator;
- }
-}
diff --git a/src/de/intarsys/cwt/font/afm/AFMChar.java b/src/de/intarsys/cwt/font/afm/AFMChar.java
deleted file mode 100644
index 3320628..0000000
--- a/src/de/intarsys/cwt/font/afm/AFMChar.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.afm;
-
-import java.util.StringTokenizer;
-
-import de.intarsys.tools.string.StringTools;
-
-/**
- * A simple implementation for an AFM char metric object
- *
- * <p>
- * This implementation will hold the information needed for implementing a
- * simple pdf field layout mechanism. All attributes but name, code, and with
- * are ignored.
- * </p>
- *
- * <p>
- * See the "Adobe Font Metrics File Format Specification"
- * </p>
- */
-public class AFMChar {
- /*
- * todo under construction
- */
-
- //
- public static String AFM_TOKEN_WX = "WX"; //$NON-NLS-1$
-
- public static String AFM_TOKEN_W = "W"; //$NON-NLS-1$
-
- public static String AFM_TOKEN_W0X = "W0X"; //$NON-NLS-1$
-
- public static String AFM_TOKEN_W0 = "W0"; //$NON-NLS-1$
-
- public static String AFM_TOKEN_N = "N"; //$NON-NLS-1$
-
- public static String AFM_TOKEN_CH = "CH"; //$NON-NLS-1$
-
- public static String AFM_TOKEN_C = "C"; //$NON-NLS-1$
-
- /**
- * Create a new glyph representation from the definition parsed from
- * <code>glyph</code>.
- *
- * @param glyph
- * A string containing a definition for the glyph.
- *
- * @return The new glyph representation.
- */
- public static AFMChar create(String glyph) {
- int code = -1;
- int width = -1;
- String name = StringTools.EMPTY;
- StringTokenizer to = new StringTokenizer(glyph, ";"); //$NON-NLS-1$
- while (to.hasMoreTokens()) {
- StringTokenizer tf = new StringTokenizer(to.nextToken());
- if (!tf.hasMoreTokens()) {
- continue;
- }
-
- String field = tf.nextToken();
- if (field.equals(AFM_TOKEN_C)) {
- code = Integer.parseInt(tf.nextToken());
- } else if (field.equals(AFM_TOKEN_CH)) {
- String value = tf.nextToken();
- code = Integer.parseInt(value.substring(1, value.length() - 1),
- 16);
- } else if (field.equals(AFM_TOKEN_WX)) {
- width = Integer.parseInt(tf.nextToken());
- } else if (field.equals(AFM_TOKEN_W0X)) {
- width = Integer.parseInt(tf.nextToken());
- } else if (field.equals(AFM_TOKEN_W)) {
- width = Integer.parseInt(tf.nextToken());
- } else if (field.equals(AFM_TOKEN_W0)) {
- width = Integer.parseInt(tf.nextToken());
- } else if (field.equals(AFM_TOKEN_N)) {
- name = tf.nextToken();
- }
- }
- return new AFMChar(code, width, name);
- }
-
- // the char name
- private String name;
-
- // the char code or -1
- private int code;
-
- // the char width or 0
- private int width;
-
- /**
- * AFMChar constructor comment.
- *
- * @param code
- * docme
- * @param width
- * docme
- * @param name
- * docme
- */
- protected AFMChar(int code, int width, String name) {
- super();
- setCode(code);
- setWidth(width);
- setName(name);
- }
-
- /**
- * The glyphs code.
- *
- * @return The glyphs code.
- */
- public int getCode() {
- return code;
- }
-
- /**
- * The glyphs name.
- *
- * @return The glyphs name.
- */
- public java.lang.String getName() {
- return name;
- }
-
- /**
- * The glyphs width.
- *
- * @return The glyphs width.
- */
- public int getWidth() {
- return width;
- }
-
- private void setCode(int newCode) {
- code = newCode;
- }
-
- private void setName(java.lang.String newName) {
- name = newName;
- }
-
- private void setWidth(int newWidth) {
- width = newWidth;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "<" + getCode() + ", " + getWidth() + ", " + getName() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-}
diff --git a/src/de/intarsys/cwt/font/afm/AFMParser.java b/src/de/intarsys/cwt/font/afm/AFMParser.java
deleted file mode 100644
index 88f439b..0000000
--- a/src/de/intarsys/cwt/font/afm/AFMParser.java
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.afm;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-import de.intarsys.tools.collection.ByteArrayTools;
-import de.intarsys.tools.randomaccess.IRandomAccess;
-import de.intarsys.tools.stream.FastByteArrayOutputStream;
-
-/**
- * A simple parser for AFM type definition files.
- *
- * <p>
- * See the "Adobe Font Metrics File Format Specification"
- * </p>
- */
-public class AFMParser {
- protected static final byte[] characterClass = new byte[256];
-
- protected static final byte CHARCLASS_ANY = 0;
-
- protected static final byte CHARCLASS_DELIMITER = 1;
-
- protected static final byte CHARCLASS_DIGIT = 4;
-
- protected static final byte CHARCLASS_NUMBERSPECIAL = 5;
-
- protected static final byte CHARCLASS_TOKEN = 3;
-
- protected static final byte CHARCLASS_WHITESPACE = 2;
-
- private static final byte[] TOKEN_Comment = "Comment".getBytes(); //$NON-NLS-1$
-
- private static final byte[] TOKEN_EndCharMetrics = "EndCharMetrics".getBytes(); //$NON-NLS-1$
-
- private static final byte[] TOKEN_EndFlag = "End".getBytes(); //$NON-NLS-1$
-
- private static final byte[] TOKEN_EndFontMetrics = "EndFontMetrics".getBytes(); //$NON-NLS-1$
-
- private static final byte[] TOKEN_StartCharMetrics = "StartCharMetrics".getBytes(); //$NON-NLS-1$
-
- private static final byte[] TOKEN_StartFlag = "Start".getBytes(); //$NON-NLS-1$
-
- private static final byte[] TOKEN_StartFontMetrics = "StartFontMetrics".getBytes(); //$NON-NLS-1$
-
- public static char CHAR_BS = '\b';
-
- public static char CHAR_CR = '\r';
-
- public static char CHAR_FF = '\f';
-
- public static char CHAR_HT = '\t';
-
- public static char CHAR_LF = '\n';
-
- static {
- for (int i = 0; i < 256; i++) {
- characterClass[i] = CHARCLASS_ANY;
- }
- // delimiters
- characterClass['('] = CHARCLASS_DELIMITER;
- characterClass[')'] = CHARCLASS_DELIMITER;
- characterClass['<'] = CHARCLASS_DELIMITER;
- characterClass['>'] = CHARCLASS_DELIMITER;
- characterClass['['] = CHARCLASS_DELIMITER;
- characterClass[']'] = CHARCLASS_DELIMITER;
- characterClass['{'] = CHARCLASS_DELIMITER;
- characterClass['}'] = CHARCLASS_DELIMITER;
- characterClass['/'] = CHARCLASS_DELIMITER;
- characterClass['%'] = CHARCLASS_DELIMITER;
-
- // whitespace
- characterClass[' '] = CHARCLASS_WHITESPACE;
- characterClass['\t'] = CHARCLASS_WHITESPACE;
- characterClass['\r'] = CHARCLASS_WHITESPACE;
- characterClass['\n'] = CHARCLASS_WHITESPACE;
- characterClass[12] = CHARCLASS_WHITESPACE;
- characterClass[0] = CHARCLASS_WHITESPACE;
-
- // digits
- characterClass['0'] = CHARCLASS_DIGIT;
- characterClass['1'] = CHARCLASS_DIGIT;
- characterClass['2'] = CHARCLASS_DIGIT;
- characterClass['3'] = CHARCLASS_DIGIT;
- characterClass['4'] = CHARCLASS_DIGIT;
- characterClass['5'] = CHARCLASS_DIGIT;
- characterClass['6'] = CHARCLASS_DIGIT;
- characterClass['7'] = CHARCLASS_DIGIT;
- characterClass['8'] = CHARCLASS_DIGIT;
- characterClass['9'] = CHARCLASS_DIGIT;
-
- // number special
- characterClass['.'] = CHARCLASS_NUMBERSPECIAL;
- characterClass['-'] = CHARCLASS_NUMBERSPECIAL;
- characterClass['+'] = CHARCLASS_NUMBERSPECIAL;
-
- // alpha
- for (int i = 'a'; i <= 'z'; i++) {
- characterClass[i] = CHARCLASS_TOKEN;
- }
- for (int i = 'A'; i <= 'Z'; i++) {
- characterClass[i] = CHARCLASS_TOKEN;
- }
- }
-
- /**
- * evaluate to true if i is a valid line terminator.
- *
- * @param i
- * i a byte representation
- *
- * @return true if i is a valid line terminator
- */
- public static final boolean isEOL(int i) {
- return (i == CHAR_CR) || (i == CHAR_LF) || (i == 12);
- }
-
- /**
- * evaluate to true if i is a valid whitespace.
- *
- * @param i
- * i a byte representation
- *
- * @return true if i is a valid whitespace
- */
- public static final boolean isWhitespace(int i) {
- return characterClass[i] == CHARCLASS_WHITESPACE;
- }
-
- private AFM afm;
-
- private FastByteArrayOutputStream localStream = new FastByteArrayOutputStream();
-
- /**
- * AFMParser constructor comment.
- */
- public AFMParser(AFM afm) {
- super();
- this.afm = afm;
- }
-
- /**
- * Parse a {@link AFM} object from the input stream <code>is</code>.
- *
- * @param is
- * The input stream containing the definition.
- *
- * @return The {@link AFM } parsed.
- *
- * @throws IOException
- */
- public AFM parse(IRandomAccess random) throws IOException {
- read(random);
- return afm;
- }
-
- protected void read(IRandomAccess random) throws IOException {
- byte[] token = readToken(random);
- if (!Arrays.equals(token, TOKEN_StartFontMetrics)) {
- throw new IOException("afm stream does not start with " //$NON-NLS-1$
- + new String(TOKEN_StartFontMetrics));
- }
- readToken(random);
- token = readFontMetrics(random);
- if (token == null || !Arrays.equals(token, TOKEN_EndFontMetrics)) {
- throw new IOException("afm stream does not end with " //$NON-NLS-1$
- + new String(TOKEN_EndFontMetrics));
- }
- }
-
- /**
- * ignore this and any nested Start/End pair
- */
- protected byte[] readBlock(IRandomAccess random) throws IOException {
- byte[] line = readLine(random);
- while (!ByteArrayTools.startsWith(line, TOKEN_EndFlag)) {
- if (ByteArrayTools.startsWith(line, TOKEN_Comment)) {
- // ignore
- } else {
- if (ByteArrayTools.startsWith(line, TOKEN_StartFlag)) {
- line = readBlock(random);
- }
- }
- line = readLine(random);
- }
- return line;
- }
-
- protected byte[] readCharMetrics(IRandomAccess random) throws IOException {
- // read count
- readToken(random);
- byte[] line = readLine(random);
- while (!ByteArrayTools.startsWith(line, TOKEN_EndCharMetrics)) {
- afm.addChar(AFMChar.create(new String(line)));
- line = readLine(random);
- }
- return line;
- }
-
- protected byte[] readFontMetrics(IRandomAccess random) throws IOException {
- byte[] token = readToken(random);
- while ((token != null) && !Arrays.equals(token, TOKEN_EndFontMetrics)) {
- if (Arrays.equals(token, TOKEN_Comment)) {
- // ignore line?
- } else {
- if (Arrays.equals(token, TOKEN_StartCharMetrics)) {
- token = readCharMetrics(random);
- } else {
- if (ByteArrayTools.startsWith(token, TOKEN_StartFlag)) {
- token = readBlock(random);
- } else {
- String value = new String(readLine(random));
- afm.setAttribute(new String(token), value);
- }
- }
- }
- token = readToken(random);
- }
- return token;
- }
-
- /**
- * read a single line.
- *
- * @return the array of characters belonging to the line
- *
- * @throws IOException
- */
- public byte[] readLine(IRandomAccess input) throws IOException {
- int next;
- while (true) {
- next = input.read();
- if (next == -1) {
- return null;
- } else if ((next == ' ') || isWhitespace(next)) {
- continue;
- } else {
- break;
- }
- }
- return readLineElement(input, next);
- }
-
- protected byte[] readLineElement(IRandomAccess input, int next)
- throws IOException {
- localStream.reset();
- localStream.write(next);
- do {
- next = input.read();
- if (next == -1) {
- break;
- } else if (isEOL(next)) { // performance
- // shortcut
- break;
- }
- localStream.write(next);
- } while (true);
- return localStream.toByteArray();
- }
-
- /**
- * read all characters until EOF or non space char appears. the first non
- * space char is pushed back so the next char read is the first non space
- * char.
- *
- * @throws IOException
- */
- public void readSpaces(IRandomAccess input) throws IOException {
- int next = 0;
- while (true) {
- next = input.read();
- if (next == -1) {
- break;
- }
- // performance shortcut for simple space
- if ((next == ' ') || isWhitespace(next)) {
- continue;
- }
- input.seekBy(-1);
- break;
- }
- }
-
- /**
- * read a single token.
- *
- * @return the array of characters belonging to the token
- *
- * @throws IOException
- */
- public byte[] readToken(IRandomAccess input) throws IOException {
- int next;
- while (true) {
- next = input.read();
- if (next == -1) {
- return null;
- } else if ((next == ' ') || isWhitespace(next)) {
- continue;
- } else {
- break;
- }
- }
- return readTokenElement(input, next);
- }
-
- protected byte[] readTokenElement(IRandomAccess input, int next)
- throws IOException {
- localStream.reset();
- localStream.write(next);
- do {
- next = input.read();
- if (next == -1) {
- break;
- } else if ((next == ' ') || isWhitespace(next)) { // performance
- // shortcut
- break;
- }
- localStream.write(next);
- } while (true);
- return localStream.toByteArray();
- }
-}
diff --git a/src/de/intarsys/cwt/font/afm/package.html b/src/de/intarsys/cwt/font/afm/package.html
deleted file mode 100644
index 0f3e0df..0000000
--- a/src/de/intarsys/cwt/font/afm/package.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<html>
-<body>
-The afm parsing and model component.
-<p>
-This is separated from the other font related stuff, as there are no real
-dependencies into them and as such can be deployed standalone, for example
-with jPod.
-</body>
-</html> \ No newline at end of file
diff --git a/src/de/intarsys/cwt/font/truetype/CreateSubset.java b/src/de/intarsys/cwt/font/truetype/CreateSubset.java
deleted file mode 100644
index 6c22979..0000000
--- a/src/de/intarsys/cwt/font/truetype/CreateSubset.java
+++ /dev/null
@@ -1,215 +0,0 @@
-package de.intarsys.cwt.font.truetype;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import de.intarsys.tools.randomaccess.IRandomAccess;
-import de.intarsys.tools.randomaccess.RandomAccessByteArray;
-import de.intarsys.tools.stream.StreamTools;
-
-public class CreateSubset {
-
- public static byte[][] SubsetTables;
-
- static {
- // !!keep sorted!!
- SubsetTables = new byte[][] { //
- //
- TTFont.TABLE_CMAP, //
- TTFont.TABLE_CVT, //
- TTFont.TABLE_FGPM, //
- TTFont.TABLE_GLYF, //
- TTFont.TABLE_HEAD, //
- TTFont.TABLE_HHEA, //
- TTFont.TABLE_HMTX, //
- TTFont.TABLE_LOCA, //
- TTFont.TABLE_MAXP, //
- TTFont.TABLE_NAME, //
- TTFont.TABLE_OS2, //
- TTFont.TABLE_PREP //
- };
- }
-
- final private TTFont font;
-
- final private Set glyphIndices;
-
- private TTFont result;
-
- public CreateSubset(TTFont font, Set glyphIndices) {
- super();
- this.font = font;
- this.glyphIndices = glyphIndices;
- }
-
- /**
- * Add all dependent glyphs not yet included for any composite glyphs in the
- * set of glyphs.
- *
- * @param glyfRandom
- * @param locations
- * @param glyphs
- * @return
- * @throws IOException
- * @throws TrueTypeException
- */
- protected Set addCompositeGlyphs(IRandomAccess glyfRandom, int[] locations,
- Set glyphs) throws IOException, TrueTypeException {
- Set allGlyphs = new HashSet();
- allGlyphs.addAll(glyphs);
- for (Iterator i = glyphs.iterator(); i.hasNext();) {
- int codePoint = ((Integer) i.next()).intValue();
- addCompositeGlyphs(glyfRandom, locations, allGlyphs, codePoint);
- }
- return allGlyphs;
- }
-
- /**
- * Add dependent glyphs not yet included for composite glyphs.
- *
- * @param glyfRandom
- * @param locations
- * @param glyphs
- * @param codePoint
- * @throws IOException
- * @throws TrueTypeException
- */
- protected void addCompositeGlyphs(IRandomAccess glyfRandom,
- int[] locations, Set glyphs, int codePoint) throws IOException,
- TrueTypeException {
- if (locations[codePoint] == locations[codePoint + 1]) {
- return;
- }
- glyfRandom.seek(locations[codePoint]);
- TTFontParser parser = new TTFontParser();
- int numContours = parser.readShort(glyfRandom);
- if (numContours >= 0) {
- return;
- }
- glyfRandom.seekBy(8);
-
- for (;;) {
- int flags = parser.readUShort(glyfRandom);
- int codePointRef = parser.readUShort(glyfRandom);
- glyphs.add(new Integer(codePointRef));
-
- if ((flags & TTFont.MORE_COMPONENTS) == 0) {
- return;
- }
-
- int skip;
-
- if ((flags & TTFont.ARG_1_AND_2_ARE_WORDS) != 0) {
- skip = 4;
- } else {
- skip = 2;
- }
-
- if ((flags & TTFont.WE_HAVE_A_SCALE) != 0) {
- skip += 2;
- } else if ((flags & TTFont.WE_HAVE_AN_X_AND_Y_SCALE) != 0) {
- skip += 4;
- }
-
- if ((flags & TTFont.WE_HAVE_A_TWO_BY_TWO) != 0) {
- skip += 8;
- }
- glyfRandom.seekBy(skip);
- }
- }
-
- public TTFont compute() throws IOException, TrueTypeException {
- TTTable loca = getFont().getTable(TTFont.TABLE_LOCA);
- int[] locations = new TTFontParser().parseTable_loca(loca, getFont()
- .getFontHeader().isShortLocationFormat());
- TTTable glyf = getFont().getTable(TTFont.TABLE_GLYF);
- IRandomAccess glyfRandom = glyf.getRandomAccess();
- try {
- result = copySubset();
- // always include glyph 0
- getGlyphIndices().add(new Integer(0));
- Set compositeGlyphs = addCompositeGlyphs(glyfRandom, locations,
- getGlyphIndices());
- createGlyphTable(loca, glyf, glyfRandom, locations,
- compositeGlyphs, getFont().getFontHeader()
- .isShortLocationFormat());
- return result;
- } finally {
- StreamTools.close(glyfRandom);
- }
- }
-
- protected TTFont copySubset() {
- TTFont resultFont = new TTFont();
- List newTables = new ArrayList();
-
- for (int i = 0; i < SubsetTables.length; i++) {
- TTTable table = getFont().getTable(SubsetTables[i]);
-
- if (table != null) {
- newTables.add(table);
- }
- }
-
- resultFont.setTables((TTTable[]) newTables.toArray(new TTTable[0]));
-
- return resultFont;
- }
-
- protected void createGlyphTable(TTTable loca, TTTable glyf,
- IRandomAccess glyfRandom, int[] oldLocations, Set glyphs,
- boolean shortFormat) throws IOException, TrueTypeException {
- // compute the total length for the new glyf table
- int newLength = 0;
- for (Iterator i = glyphs.iterator(); i.hasNext();) {
- int codePoint = ((Integer) i.next()).intValue();
- if ((codePoint + 1) >= oldLocations.length) {
- continue;
- }
- newLength += (oldLocations[codePoint + 1] - oldLocations[codePoint]);
- }
- newLength = TTFont.align(newLength);
-
- // rebuild new glyf table
- int[] newLocations = new int[oldLocations.length];
- byte[] newGlyfData = new byte[newLength];
- int ptr = 0;
- for (int i = 0; i < oldLocations.length; i++) {
- newLocations[i] = ptr;
- if (glyphs.contains(new Integer(i))) {
- int glyfstart = oldLocations[i];
- int glyflength = oldLocations[i + 1] - glyfstart;
-
- if (glyflength > 0) {
- glyfRandom.seek(glyfstart);
- glyfRandom.read(newGlyfData, ptr, glyflength);
- ptr += glyflength;
- }
- }
- }
-
- // store new loca table
- RandomAccessByteArray random = new RandomAccessByteArray(null);
- TTFontSerializer serializer = new TTFontSerializer();
- serializer.write_loca(random, newLocations, shortFormat);
- loca.setBytes(random.toByteArray());
- // store new glyf table
- glyf.setBytes(newGlyfData);
- }
-
- public TTFont getFont() {
- return font;
- }
-
- public Set getGlyphIndices() {
- return glyphIndices;
- }
-
- public TTFont getResult() {
- return result;
- }
-}
diff --git a/src/de/intarsys/cwt/font/truetype/ITTNamingIDs.java b/src/de/intarsys/cwt/font/truetype/ITTNamingIDs.java
deleted file mode 100644
index 63c59e7..0000000
--- a/src/de/intarsys/cwt/font/truetype/ITTNamingIDs.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-/**
- *
- */
-public interface ITTNamingIDs {
- // Code Meaning
- // 0 Copyright notice.
- public static final int Copyright = 0;
-
- // 1 Font Family name. Up to four fonts can share the Font Family name,
- // forming a font style linking group (regular, italic, bold, bold italic -
- // as defined by OS/2.fsSelection bit settings).
- public static final int FontFamilyName = 1;
-
- // 2 Font Subfamily name. The Font Subfamily name distiguishes the font in a
- // group with the same Font Family name (name ID 1). This is assumed to
- // address style (italic, oblique) and weight (light, bold, black, etc.). A
- // font with no particular differences in weight or style (e.g. medium
- // weight, not italic and fsSelection bit 6 set) should have the string
- // "Regular" stored in this position.
- public static final int FontSubfamilyName = 2;
-
- // 3 Unique font identifier
- public static final int FontId = 3;
-
- // 4 Full font name; this should be a combination of strings 1 and 2.
- // Exception: if the font is "Regular" as indicated in string 2, then use
- // only the family name contained in string 1.
- public static final int FullFontName = 4;
-
- // 5 Version string. Should begin with the syntax 'Version
- // <number>.<number>' (upper case, lower case, or mixed, with a space
- // between "Version" and the number).
- public static final int Version = 5;
-
- // 6 Postscript name for the font; Name ID 6 specifies a string which is
- // used to invoke a PostScript language font that corresponds to this
- // OpenType font. If no name ID 6 is present, then there is no defined
- // method for invoking this font on a PostScript interpreter.
- public static final int PSName = 6;
-
- // 7 Trademark; this is used to save any trademark notice/information for
- // this font. Such information should be based on legal advice. This is
- // distinctly separate from the copyright.
- public static final int Trademark = 7;
-
- // 8 Manufacturer Name.
- public static final int ManufacturerName = 8;
-
- // 9 Designer; name of the designer of the typeface.
- public static final int DesignerName = 9;
-
- // 10 Description; description of the typeface. Can contain revision
- // information, usage recommendations, history, features, etc.
- public static final int Description = 10;
-
- // 11 URL Vendor; URL of font vendor (with protocol, e.g., http://, ftp://).
- // If a unique serial number is embedded in the URL, it can be used to
- // register the font.
- public static final int URLVendor = 11;
-
- // 12 URL Designer; URL of typeface designer (with protocol, e.g., http://,
- // ftp://).
- public static final int URLDesigner = 12;
-
- // 13 License Description; description of how the font may be legally used,
- // or different example scenarios for licensed use. This field should be
- // written in plain language, not legalese.
- public static final int LicenseDescription = 13;
-
- // 14 License Info URL; URL where additional licensing information can be
- // found.
- public static final int LicenseInfoURL = 14;
-
- // 15 Reserved; Set to zero.
-
- // 16 Preferred Family; For historical reasons, font families have contained
- // a maximum of four styles, but font designers may group more than four
- // fonts to a single family. The Preferred Family allows font designers to
- // include the preferred family grouping which contains more than four
- // fonts. This ID is only present if it is different from ID 1.
- public static final int PreferredFamily = 16;
-
- // 17 Preferred Subfamily; Allows font designers to include the preferred
- // subfamily grouping that is more descriptive than ID 2. This ID is only
- // present if it is different from ID 2 and must be unique for the the
- // Preferred Family.
- public static final int PreferredSubFamily = 17;
-
- // 18 Compatible Full (Macintosh only); On the Macintosh, the menu name is
- // constructed using the FOND resource. This usually matches the Full Name.
- // If you want the name of the font to appear differently than the Full
- // Name, you can insert the Compatible Full Name in ID 18.
- public static final int CompatibleFull = 18;
-
- // 19 Sample text; This can be the font name, or any other text that the
- // designer thinks is the best sample to display the font in.
- public static final int SampleText = 19;
-
- // 20 PostScript CID findfont name; Its presence in a font means that the
- // nameID 6 holds a PostScript font name that is meant to be used with the
- // "composefont" invocation in order to invoke the font in a PostScript
- // interpreter. See the definition of name ID 6.
- public static final int PS_CID = 20;
-}
diff --git a/src/de/intarsys/cwt/font/truetype/PACKAGE.java b/src/de/intarsys/cwt/font/truetype/PACKAGE.java
deleted file mode 100644
index c1ce5fa..0000000
--- a/src/de/intarsys/cwt/font/truetype/PACKAGE.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-import java.util.logging.Logger;
-
-import de.intarsys.tools.logging.LogTools;
-import de.intarsys.tools.message.MessageBundle;
-import de.intarsys.tools.message.MessageBundleTools;
-
-public class PACKAGE {
-
- public final static MessageBundle Messages = MessageBundleTools
- .getMessageBundle(PACKAGE.class);
-
- public final static Logger Log = LogTools.getLogger(PACKAGE.class);
-
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTFont.java b/src/de/intarsys/cwt/font/truetype/TTFont.java
deleted file mode 100644
index b19c83d..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTFont.java
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Map;
-
-import de.intarsys.cwt.font.FontStyle;
-import de.intarsys.tools.locator.ILocator;
-import de.intarsys.tools.randomaccess.IRandomAccess;
-import de.intarsys.tools.stream.StreamTools;
-import de.intarsys.tools.string.StringTools;
-
-/**
- * This class represents a true type font. Currently only single font files are
- * supported.
- * <p>
- * This class is under construction and not meant for a complete TT
- * implementation.
- */
-public class TTFont {
- public static final int ARG_1_AND_2_ARE_WORDS = 1;
-
- public static final int MORE_COMPONENTS = 32;
-
- public static final int SFNT_TRUETYPE = 0x00010000;
-
- public static final byte[] TABLE_CMAP = "cmap".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_CVT = "cvt ".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_FGPM = "fpgm".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_GLYF = "glyf".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_HEAD = "head".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_HHEA = "hhea".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_HMTX = "hmtx".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_LOCA = "loca".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_MAXP = "maxp".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_NAME = "name".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_OS2 = "OS/2".getBytes(); //$NON-NLS-1$
-
- public static final byte[] TABLE_POST = "post".getBytes();//$NON-NLS-1$
-
- public static final byte[] TABLE_PREP = "prep".getBytes(); //$NON-NLS-1$
-
- public static final int WE_HAVE_A_SCALE = 8;
-
- public static final int WE_HAVE_A_TWO_BY_TWO = 128;
-
- public static final int WE_HAVE_AN_X_AND_Y_SCALE = 64;
-
- static public int align(int newLength) {
- return (newLength + 3) & (~3);
- }
-
- public static TTFont createFromLocator(ILocator locator) throws IOException {
- TTFont result = new TTFont();
- result.setLocator(locator);
- result.initializeFromLocator();
- return result;
- }
-
- /** objectified versions of the "cmap" tables and subtables */
- private Map cmaps;
-
- // Font names in Postscript notation
- private String fontFamilyName = null;
-
- /** "objectified" version of the "head" table */
- private TTFontHeader fontHeader;
-
- /** The style of this font */
- private FontStyle fontStyle = FontStyle.REGULAR;
-
- /** objectified version of the "hmtx" table */
- private int[] glyphWidths;
-
- /** objectified version of the "hhea" table */
- private TTHorizontalHeader horizontalHeader;
-
- private ILocator locator;
-
- /** objectified version of the "os/2" table */
- private TTMetrics metrics;
-
- /** objectified version of the "naming" table */
- private TTNaming naming;
-
- /** objectified versions of the "post" table */
- private TTPostScriptInformation postScriptInformation;
-
- private String psName = null;
-
- private int sfntVersion;
-
- /** the parsed table directory information */
- private TTTable[] tables;
-
- /**
- * Create an empty true type font.
- */
- protected TTFont() {
- super();
- }
-
- public Map getCMaps() throws TrueTypeException {
- if (cmaps == null) {
- TTFontParser parser = new TTFontParser();
-
- try {
- cmaps = parser.parseTable_cmap(getTable(TABLE_CMAP));
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
-
- return cmaps;
- }
-
- public Map getCMapsAt(int platformID, int platformSpecificID)
- throws TrueTypeException {
- String key = StringTools.EMPTY + platformID + ":" + platformSpecificID; //$NON-NLS-1$
- Object result = getCMaps().get(key);
-
- if (result instanceof TTTable) {
- // not yet parsed
- TTFontParser parser = new TTFontParser();
-
- try {
- Map submap = parser.parseTable_cmap_subtable((TTTable) result);
- getCMaps().put(key, submap);
- result = submap;
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
-
- return (Map) result;
- }
-
- public String getFontFamilyName() {
- return fontFamilyName;
- }
-
- public TTFontHeader getFontHeader() throws TrueTypeException {
- if (fontHeader == null) {
- TTFontParser parser = new TTFontParser();
-
- try {
- fontHeader = parser.parseTable_head(getTable(TABLE_HEAD));
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
-
- return fontHeader;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.font.IFont#getFontName()
- */
- public String getFontName() {
- return getPsName();
- }
-
- public FontStyle getFontStyle() {
- return fontStyle;
- }
-
- public int getGlyphWidth(int codePoint) throws TrueTypeException {
- if (codePoint < getGlyphWidths().length) {
- return getGlyphWidths()[codePoint];
- }
- return getGlyphWidths()[getGlyphWidths().length - 1];
- }
-
- protected int[] getGlyphWidths() throws TrueTypeException {
- if (glyphWidths == null) {
- TTFontParser parser = new TTFontParser();
-
- try {
- glyphWidths = parser.parseTable_hmtx(getTable(TABLE_HMTX),
- getHorizontalHeader().getNumberOfHMetrics());
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
-
- return glyphWidths;
- }
-
- public TTHorizontalHeader getHorizontalHeader() throws TrueTypeException {
- if (horizontalHeader == null) {
- TTFontParser parser = new TTFontParser();
-
- try {
- horizontalHeader = parser.parseTable_hhea(getTable(TABLE_HHEA));
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
-
- return horizontalHeader;
- }
-
- public ILocator getLocator() {
- return locator;
- }
-
- public TTMetrics getMetrics() throws TrueTypeException {
- if (metrics == null) {
- TTFontParser parser = new TTFontParser();
-
- try {
- metrics = parser.parseTable_os2(getTable(TABLE_OS2));
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
-
- return metrics;
- }
-
- public TTNaming getNaming() throws TrueTypeException {
- if (naming == null) {
- TTFontParser parser = new TTFontParser();
-
- try {
- TTTable table = getTable(TABLE_NAME);
- if (table != null) {
- naming = parser.parseTable_name(table);
- }
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
- return naming;
- }
-
- public TTPostScriptInformation getPostScriptInformation()
- throws TrueTypeException {
- if (postScriptInformation == null) {
- TTFontParser parser = new TTFontParser();
-
- try {
- postScriptInformation = parser
- .parseTable_post(getTable(TABLE_POST));
- } catch (IOException e) {
- throw new TrueTypeException(e.getMessage());
- }
- }
-
- return postScriptInformation;
- }
-
- public String getPsName() {
- return psName;
- }
-
- public int getSfntVersion() {
- return sfntVersion;
- }
-
- public TTTable getTable(byte[] name) {
- for (int i = 0; i < getTables().length; i++) {
- TTTable current = tables[i];
-
- if (Arrays.equals(current.getName(), name)) {
- return current;
- }
- }
-
- return null;
- }
-
- public TTTable[] getTables() {
- return tables;
- }
-
- protected void initializeFromLocator() throws IOException {
- IRandomAccess random = null;
- try {
- random = getLocator().getRandomAccess();
- TTFontParser parser = new TTFontParser();
- parser.parseTables(this);
- try {
- setFontName(this);
- } catch (TrueTypeException e) {
- throw new IOException(e.getMessage());
- }
-
- } finally {
- StreamTools.close(random);
- }
- }
-
- public void removeCMapsAt(int platformID, int platformSpecificID)
- throws TrueTypeException, IOException {
- TTTable data = getTable(TTFont.TABLE_CMAP);
- if (data == null) {
- return;
- }
- IRandomAccess random = data.getRandomAccess();
- TTFontSerializer serializer = new TTFontSerializer();
- TTFontParser parser = new TTFontParser();
- try {
- boolean found = false;
-
- random.seek(0);
- // skip version
- int version = parser.readShort(random);
- int count = parser.readUShort(random);
- int i = 0;
- long readPos = random.getOffset();
- long writePos = random.getOffset();
- while (i < count) {
- random.seek(readPos);
- int tempPlatformID = parser.readUShort(random);
- int tempPlatformSpecificID = parser.readUShort(random);
- int offset = parser.readInt(random);
- if (platformID == tempPlatformID
- && platformSpecificID == tempPlatformSpecificID) {
- found = true;
- } else {
- if (readPos != writePos) {
- random.seek(writePos);
- serializer.writeShort(random, tempPlatformID);
- serializer.writeShort(random, tempPlatformSpecificID);
- serializer.writeInt(random, offset);
- }
- writePos = writePos + 8;
- }
- readPos = readPos + 8;
- i++;
- }
- if (found) {
- // clear removed entry
- random.seek(writePos);
- serializer.writeShort(random, 0);
- serializer.writeShort(random, 0);
- serializer.writeInt(random, 0);
- //
- random.seek(0);
- // skip version
- random.seekBy(2);
- // decrement count
- serializer.writeShort(random, count - 1);
- //
-
- }
- } finally {
- StreamTools.close(random);
- }
- cmaps = null;
- }
-
- protected void setFontFamilyName(String string) {
- fontFamilyName = string;
- }
-
- protected void setFontName(TTFont font) throws TrueTypeException {
- TTNaming tempNaming = font.getNaming();
- if (tempNaming != null) {
- font.setFontFamilyName(tempNaming
- .getValue(ITTNamingIDs.FontFamilyName));
- String styleName = tempNaming
- .getValue(ITTNamingIDs.FontSubfamilyName);
- font.setFontStyle(FontStyle.getFontStyle(styleName));
- font.setPsName(tempNaming.getValue(ITTNamingIDs.PSName));
- if (font.getPsName() == null) {
- // Here we should use operating system specific information
- // which can't be done by Java. So we use our own
- // implementation and hope we it works.
- // todo postscript name
- font.setPsName(font.getFontFamilyName() + "-" //$NON-NLS-1$
- + font.getFontStyle().getId());
- }
- }
- }
-
- protected void setFontStyle(FontStyle fontStyle) {
- this.fontStyle = fontStyle;
- }
-
- protected void setLocator(ILocator locator) {
- this.locator = locator;
- }
-
- public void setPsName(String string) {
- psName = string;
- }
-
- protected void setSfntVersion(int sfntVersion) {
- // this is not true for all valid font files, skip version check
- // if (sfntVersion != SFNT_TRUETYPE) {
- // throw new IOException("not a valid TTF file.");
- // }
-
- this.sfntVersion = sfntVersion;
- }
-
- protected void setTables(TTTable[] tables) {
- this.tables = tables;
- }
-
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTFontHeader.java b/src/de/intarsys/cwt/font/truetype/TTFontHeader.java
deleted file mode 100644
index 6687276..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTFontHeader.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-/**
- *
- */
-public class TTFontHeader {
- public static int MACSTYLE_BOLD = 1 << 0; // Bit 0
-
- public static int MACSTYLE_ITALIC = 1 << 1; // Bit 1
-
- public static int MACSTYLE_UNDERLINE = 1 << 2;
-
- public static int MACSTYLE_OUTLINE = 1 << 3;
-
- public static int MACSTYLE_SHADOW = 1 << 4;
-
- public static int MACSTYLE_CONDENSED = 1 << 5;
-
- public static int MACSTYLE_EXTENDED = 1 << 6;
-
- private int flags;
-
- private int unitsPerEm;
-
- private short xMin;
-
- private short yMin;
-
- private short xMax;
-
- private short yMax;
-
- private int macStyle;
-
- private boolean shortLocationFormat;
-
- public int getFlags() {
- return flags;
- }
-
- public int getMacStyle() {
- return macStyle;
- }
-
- public int getUnitsPerEm() {
- return unitsPerEm;
- }
-
- public short getXMax() {
- return xMax;
- }
-
- public short getXMin() {
- return xMin;
- }
-
- public short getYMax() {
- return yMax;
- }
-
- public short getYMin() {
- return yMin;
- }
-
- public boolean isShortLocationFormat() {
- return shortLocationFormat;
- }
-
- public void setFlags(int i) {
- flags = i;
- }
-
- public void setMacStyle(int i) {
- macStyle = i;
- }
-
- public void setShortLocationFormat(boolean b) {
- shortLocationFormat = b;
- }
-
- public void setUnitsPerEm(int i) {
- unitsPerEm = i;
- }
-
- public void setXMax(short i) {
- xMax = i;
- }
-
- public void setXMin(short i) {
- xMin = i;
- }
-
- public void setYMax(short i) {
- yMax = i;
- }
-
- public void setYMin(short i) {
- yMin = i;
- }
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTFontParser.java b/src/de/intarsys/cwt/font/truetype/TTFontParser.java
deleted file mode 100644
index cfe67ee..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTFontParser.java
+++ /dev/null
@@ -1,731 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import de.intarsys.tools.randomaccess.IRandomAccess;
-import de.intarsys.tools.stream.StreamTools;
-import de.intarsys.tools.string.StringTools;
-
-/**
- * Apple TT specification<br/>
- * http://developer.apple.com/fonts/TTRefMan/RM06/Chap6.html <br/>
- * Microsoft OpenType spec <br/>
- * http://www.microsoft.com/typography/otspec/otff.htm
- */
-public class TTFontParser {
- // todo support indexed fonts
-
- /** the parsed table directory information */
- private TTTable[] tables;
-
- public TTFontParser() {
- }
-
- public Map parseTable_cmap(TTTable data) throws IOException {
- Map result = new HashMap();
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- // skip version
- random.seekBy(2);
- int count = readUShort(random);
- for (int i = 0; i < count; i++) {
- int platformID = readUShort(random);
- int platformSpecificID = readUShort(random);
- int offset = readInt(random);
- TTTable subtable = new TTTable(data.getFont(), data.getOffset()
- + offset, -1);
- String key = StringTools.EMPTY + platformID
- + ":" + platformSpecificID; //$NON-NLS-1$
- result.put(key, subtable);
- }
- return result;
- } finally {
- StreamTools.close(random);
- }
- }
-
- public Map parseTable_cmap_subtable(TTTable data) throws IOException {
- Map result = null;
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- int format = readUShort(random);
- switch (format) {
- case 0:
- result = readCMapFormat0(random);
- break;
- case 4:
- result = readCMapFormat4(random);
- break;
- case 6:
- result = readCMapFormat6(random);
- break;
- }
- return result;
- } finally {
- StreamTools.close(random);
- }
- }
-
- /**
- * This table gives global information about the font.
- *
- * <pre>
- * Type Name Description
- * FIXED Table version number 0x00010000 for version 1.0.
- * FIXED fontRevision Set by font manufacturer.
- * ULONG checkSumAdjustment To compute: set it to 0, sum the entire font as ULONG, then store 0xB1B0AFBA - sum.
- * ULONG magicNumber Set to 0x5F0F3CF5.
- * USHORT flags Bit 0 - baseline for font at y=0;
- * Bit 1 - left sidebearing at x=0;
- * Bit 2 - instructions may depend on point size;
- * Bit 3 - force ppem to integer values for all internal scaler math; may use fractional ppem sizes if this bit is clear;
- * Bit 4 - instructions may alter advance width (the advance widths might not scale linearly);
- * Note: All other bits must be zero.
- * USHORT unitsPerEm Valid range is from 16 to 16384
- * longDateTime created International date (8-byte field).
- * longDateTime modified International date (8-byte field).
- * FWORD xMin For all glyph bounding boxes.
- * FWORD yMin For all glyph bounding boxes.
- * FWORD xMax For all glyph bounding boxes.
- * FWORD yMax For all glyph bounding boxes.
- * USHORT macStyle Bit 0 bold (if set to 1); Bit 1 italic (if set to 1)Bits 2-15 reserved (set to 0).
- * USHORT lowestRecPPEM Smallest readable size in pixels.
- * SHORT fontDirectionHint 0 Fully mixed directional glyphs; 1 Only strongly left to right; 2 Like 1 but also contains neutrals ;-1 Only strongly right to left;-2 Like -1 but also contains neutrals.
- * SHORT indexToLocFormat 0 for short offsets, 1 for long.
- * SHORT glyphDataFormat 0 for current format.
- * </pre>
- *
- * @param data
- * docme
- *
- * @return docme
- *
- * @throws IOException
- * docme
- */
- public TTFontHeader parseTable_head(TTTable data) throws IOException {
- TTFontHeader result = new TTFontHeader();
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- // skip version
- // skip font Revision
- // skip checksum
- // skip magic number
- random.seekBy(16);
- result.setFlags(readUShort(random));
- result.setUnitsPerEm(readUShort(random));
- // skip created
- // skip modified
- random.seekBy(16);
- result.setXMin(readShort(random));
- result.setYMin(readShort(random));
- result.setXMax(readShort(random));
- result.setYMax(readShort(random));
- result.setMacStyle(readUShort(random));
- // skip smallest size in pixels
- // skip font direction hint
- random.seekBy(4);
- result.setShortLocationFormat(readShort(random) == 0);
- return result;
- } finally {
- StreamTools.close(random);
- }
- }
-
- /**
- * <pre>
- * FIXED Table version number 0x00010000 for version 1.0.
- * FWORD Ascender Typographic ascent.
- * FWORD Descender Typographic descent.
- * FWORD LineGap Typographic line gap. Negative LineGap values are treated as zero in Windows 3.1, System 6, and System 7.
- * UFWORD advanceWidthMax Maximum advance width value in �hmtx� table.
- * FWORD minLeftSideBearing Minimum left sidebearing value in �hmtx� table.
- * FWORD minRightSideBearing Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
- * FWORD xMaxExtent Max(lsb + (xMax - xMin)).
- * SHORT caretSlopeRise Used to calculate the slope of the cursor (rise/run); 1 for vertical.
- * SHORT caretSlopeRun 0 for vertical.
- * SHORT (reserved) set to 0
- * SHORT (reserved) set to 0
- * SHORT (reserved) set to 0
- * SHORT (reserved) set to 0
- * SHORT (reserved) set to 0
- * SHORT metricDataFormat 0 for current format.
- * USHORT numberOfHMetrics Number of hMetric entries in �hmtx� table; may be smaller than the total number of glyphs in the font.
- * </pre>
- *
- * @param data
- * docme
- *
- * @return docme
- *
- * @throws IOException
- * docme
- */
- public TTHorizontalHeader parseTable_hhea(TTTable data) throws IOException {
- TTHorizontalHeader result = new TTHorizontalHeader();
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- // skip version
- random.seekBy(4);
- result.setAscender(readShort(random));
- result.setDescender(readShort(random));
- result.setLineGap(readShort(random));
- result.setAdvanceWidthMax(readUShort(random));
- result.setMinLeftSideBearing(readShort(random));
- result.setMinRightSideBearing(readShort(random));
- result.setXMaxExtent(readShort(random));
- result.setCaretSlopeRise(readShort(random));
- result.setCaretSlopeRun(readShort(random));
- // skip
- random.seekBy(12);
- result.setNumberOfHMetrics(readUShort(random));
- // skip rest
- return result;
- } finally {
- StreamTools.close(random);
- }
- }
-
- /**
- * <pre>
- * The type longHorMetric is defined as an array where each element has
- * two parts: the advance width, which is of type USHORT, and the left side
- * bearing, which is of type SHORT. These fields are in font design units.
- * typedef struct _longHorMetric {
- * USHORT advanceWidth;
- * SHORT lsb;
- * } longHorMetric;
- *
- * Field Type Description
- * hMetrics longHorMetric [numberOfHMetrics] Paired advance width and
- * left side bearing values for each glyph. The value
- * numOfHMetrics comes from the 'hhea' table. If the font is
- * monospaced, only one entry need be in the array, but that
- * entry is required. The last entry applies to all subsequent
- * glyphs.
- * leftSideBearing SHORT[ ] Here the advanceWidth is assumed to be the
- * same as the advanceWidth for the last entry above. The
- * number of entries in this array is derived from numGlyphs
- * (from 'maxp' table) minus numberOfHMetrics. This generally
- * is used with a run of monospaced glyphs (e.g., Kanji fonts
- * or Courier fonts). Only one run is allowed and it must be
- * at the end. This allows a monospaced font to vary the left
- * side bearing values for each glyph.
- * </pre>
- *
- * @param data
- * docme
- * @param count
- * docme
- *
- * @return docme
- *
- * @throws IOException
- * docme
- */
- public int[] parseTable_hmtx(TTTable data, int count) throws IOException {
- int[] widths = new int[count];
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- for (int i = 0; i < count; i++) {
- widths[i] = readUShort(random);
- readShort(random);
- }
- return widths;
- } finally {
- StreamTools.close(random);
- }
- }
-
- public int[] parseTable_loca(TTTable data, boolean shortLocationFormat)
- throws IOException {
- int count = 0;
- int[] locations;
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- if (shortLocationFormat) {
- count = (int) random.getLength() / 2;
- locations = new int[count];
-
- for (int i = 0; i < count; i++) {
- locations[i] = readUShort(random) << 1;
- }
- } else {
- count = (int) random.getLength() / 4;
- locations = new int[count];
-
- for (int i = 0; i < count; i++) {
- locations[i] = readInt(random);
- }
- }
- return locations;
- } finally {
- StreamTools.close(random);
- }
- }
-
- public TTNaming parseTable_name(TTTable data) throws IOException {
- TTNaming result = new TTNaming();
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- // skip format
- random.seekBy(2);
- // USHORT count Number of name records.
- int count = readUShort(random);
- // USHORT stringOffset Offset to start of string storage (from start
- // of
- // table).
- int stringTableOffset = readUShort(random);
- // Namerecords follow
- for (int i = 0; i < count; i++) {
- TTNameRecord record = readNameRecord(random, stringTableOffset);
- // filter for Microsoft-Plattform and Language=American
- if ((record.getPlatformID() == 3)
- && (record.getLanguageID() == 1033)) {
- result.add(record.getNameID(), record);
- }
- }
- return result;
- } finally {
- StreamTools.close(random);
- }
- }
-
- /**
- * <pre>
- * USHORT version 0x0001
- * SHORT xAvgCharWidth;
- * USHORT usWeightClass;
- * USHORT usWidthClass;
- * SHORT fsType;
- * SHORT ySubscriptXSize;
- * SHORT ySubscriptYSize;
- * SHORT ySubscriptXOffset;
- * SHORT ySubscriptYOffset;
- * SHORT ySuperscriptXSize;
- * SHORT ySuperscriptYSize;
- * SHORT ySuperscriptXOffset;
- * SHORT ySuperscriptYOffset;
- * SHORT yStrikeoutSize;
- * SHORT yStrikeoutPosition;
- * SHORT sFamilyClass;
- * PANOSE panose;
- * ULONG ulUnicodeRange1 Bits 0�31
- * ULONG ulUnicodeRange2 Bits 32�63
- * ULONG ulUnicodeRange3 Bits 64�95
- * ULONG ulUnicodeRange4 Bits 96�127
- * CHAR achVendID[4];
- * USHORT fsSelection;
- * USHORT usFirstCharIndex
- * USHORT usLastCharIndex
- * USHORT sTypoAscender
- * USHORT sTypoDescender
- * USHORT sTypoLineGap
- * USHORT usWinAscent
- * USHORT usWinDescent
- * ULONG ulCodePageRange1 Bits 0-31
- * ULONG ulCodePageRange2 Bits 32-63
- * SHORT sxHeight
- * SHORT sCapHeight
- * USHORT usDefaultChar
- * USHORT usBreakChar
- * USHORT usMaxContext
- * </pre>
- *
- * @param data
- * docme
- *
- * @return docme
- *
- * @throws IOException
- * docme
- */
- public TTMetrics parseTable_os2(TTTable data) throws IOException {
- TTMetrics result = new TTMetrics();
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- // skip version
- random.seekBy(2);
- result.setXAvgCharWidth(readShort(random));
- result.setUsWeightClass(readUShort(random));
- result.setUsWidthClass(readUShort(random));
- result.setFsType(readUShort(random));
- result.setYSubscriptXSize(readShort(random));
- result.setYSubscriptYSize(readShort(random));
- result.setYSubscriptXOffset(readShort(random));
- result.setYSubscriptYOffset(readShort(random));
- result.setYSuperscriptXSize(readShort(random));
- result.setYSuperscriptYSize(readShort(random));
- result.setYSuperscriptXOffset(readShort(random));
- result.setYSuperscriptYOffset(readShort(random));
- result.setYStrikeoutSize(readShort(random));
- result.setYStrikeoutPosition(readShort(random));
- result.setSFamilyClass(readShort(random));
- result.setPanose(readBytes(random, 10));
- // skip unicode ranges
- // skip vendor id
- random.seekBy(20);
- result.setFsSelection(readUShort(random));
- result.setUsFirstCharIndex(readUShort(random));
- result.setUsLastCharIndex(readUShort(random));
- result.setSTypoAscender(readShort(random));
- result.setSTypoDescender(readShort(random));
- result.setSTypoLineGap(readShort(random));
- result.setUsWinAscent(readUShort(random));
- result.setUsWinDescent(readUShort(random));
- result.setSxHeight(readShort(random));
- result.setSCapHeight(readShort(random));
- result.setUsDefaultChar(readUShort(random));
- result.setUsMaxContext(readUShort(random));
- // skip rest
- return result;
- } finally {
- StreamTools.close(random);
- }
- }
-
- /**
- * <pre>
- * Type Name Description
- * Fixed Version 0x00010000 for version 1.0
- * 0x00020000 for version 2.0
- * 0x00025000 for version 2.5 (deprecated)
- * 0x00030000 for version 3.0
- * Fixed italicAngle Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
- * FWord underlinePosition This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
- * The PostScript definition of this FontInfo dictionary key (the y coordinate of the center of the stroke) is not used for historical reasons. The value of the PostScript key may be calculated by subtracting half the underlineThickness from the value of this field.
- * FWord underlineThickness Suggested values for the underline thickness.
- * ULONG isFixedPitch Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced).
- * ULONG minMemType42 Minimum memory usage when an OpenType font is downloaded.
- * ULONG maxMemType42 Maximum memory usage when an OpenType font is downloaded.
- * ULONG minMemType1 Minimum memory usage when an OpenType font is downloaded as a Type 1 font.
- * ULONG maxMemType1 Maximum memory usage when an OpenType font is downloaded as a Type 1 font.
- * </pre>
- *
- * @param data
- * docme
- *
- * @return docme
- *
- * @throws IOException
- * docme
- */
- public TTPostScriptInformation parseTable_post(TTTable data)
- throws IOException {
- TTPostScriptInformation result = new TTPostScriptInformation();
- IRandomAccess random = data.getRandomAccess();
- try {
- random.seek(0);
- result.setVersion(readFixed(random));
- result.setItalicAngle(readFixed(random));
- result.setUnderlinePosition(readShort(random));
- result.setUnderlineThickness(readShort(random));
- return result;
- } finally {
- StreamTools.close(random);
- }
- }
-
- public TTTable[] parseTables(TTFont font) throws IOException {
- IRandomAccess random = null;
- try {
- random = font.getLocator().getRandomAccess();
- readTables(font, random);
- font.setTables(tables);
- } finally {
- StreamTools.close(random);
- }
- return tables;
- }
-
- public byte[] readBytes(IRandomAccess random, int count) throws IOException {
- byte[] bytes = new byte[count];
- int bytesRead = random.read(bytes);
- if (bytesRead < bytes.length) {
- return null;
- }
- return bytes;
- }
-
- protected Map readCMapFormat0(IRandomAccess random) throws IOException {
- Map result = new HashMap();
-
- // skip length
- // skip language
- random.seekBy(4);
-
- for (int i = 0; i < 256; i++) {
- int glyphCode = random.read();
- result.put(new Integer(i), new Integer(glyphCode));
- }
-
- return result;
- }
-
- protected Map readCMapFormat4(IRandomAccess random) throws IOException {
- Map result = new HashMap();
- int length = readUShort(random);
-
- // skip language
- random.seekBy(2);
-
- int segCount = readUShort(random) / 2;
-
- // skip hints
- random.seekBy(6);
-
- int[] endIndices = new int[segCount];
-
- for (int i = 0; i < segCount; i++) {
- endIndices[i] = readUShort(random);
- }
-
- // skip reserved
- random.seekBy(2);
-
- int[] startIndices = new int[segCount];
-
- for (int i = 0; i < segCount; i++) {
- startIndices[i] = readUShort(random);
- }
-
- int[] deltas = new int[segCount];
-
- for (int i = 0; i < segCount; i++) {
- deltas[i] = readUShort(random);
- }
-
- int[] rangeOffsets = new int[segCount];
-
- for (int i = 0; i < segCount; i++) {
- rangeOffsets[i] = readUShort(random);
- }
-
- int glyphIndexCount = (length / 2) - 8 - (segCount * 4);
- int[] glyphIndices = new int[glyphIndexCount];
-
- for (int i = 0; i < glyphIndexCount; i++) {
- glyphIndices[i] = readUShort(random);
- }
-
- // now construct map
- int glyphCode;
-
- for (int i = 0; i < segCount; i++) {
- for (int charCode = startIndices[i]; (charCode <= endIndices[i])
- && (charCode != 0xffff); charCode++) {
- if (rangeOffsets[i] == 0) {
- glyphCode = (deltas[i] + charCode) & 0xffff;
- } else {
- // index as described in open font specification
- int index = (charCode - startIndices[i])
- + (rangeOffsets[i] / 2);
-
- // try emulate c pointer arithmetic..
- index = index - segCount + i;
- glyphCode = glyphIndices[index];
-
- if (glyphCode != 0) {
- glyphCode = (deltas[i] + glyphCode) & 0xffff;
- }
- }
-
- result.put(new Integer(charCode), new Integer(glyphCode));
- }
- }
-
- return result;
- }
-
- protected Map readCMapFormat6(IRandomAccess random) throws IOException {
- Map result = new HashMap();
-
- // skip length
- // skip language
- random.seekBy(4);
-
- int firstIndex = readUShort(random);
- int count = readUShort(random);
- int lastIndex = firstIndex + count;
-
- for (int i = firstIndex; i < lastIndex; i++) {
- int glyphCode = readUShort(random);
- result.put(new Integer(i), new Integer(glyphCode));
- }
-
- return result;
- }
-
- public float readFixed(IRandomAccess random) throws IOException {
- int i = readInt(random);
- boolean negative = false;
-
- if (i < 0) {
- negative = true;
- i *= -1;
- }
-
- float hi = (i >> 16);
- float low = (i & 0x0000FFFF);
-
- while (low >= 1) {
- low = low / 10;
- }
-
- if (negative) {
- return -1 * (hi + low);
- }
-
- return hi + low;
- }
-
- public int readInt(IRandomAccess random) throws IOException {
- int b1 = random.read();
- int b2 = random.read();
- int b3 = random.read();
- int b4 = random.read();
-
- if ((b1 | b2 | b3 | b4) < 0) {
- throw new IOException("unexpected end of stream"); //$NON-NLS-1$
- }
-
- return ((b1 << 24) + (b2 << 16) + (b3 << 8) + b4);
- }
-
- protected TTNameRecord readNameRecord(IRandomAccess random,
- int stringTableOffset) throws IOException {
- TTNameRecord record = new TTNameRecord();
-
- // USHORT platformID Platform ID.
- record.setPlatformID(readUShort(random));
-
- // USHORT encodingID Platform-specific encoding ID.
- record.setEncodingID(readUShort(random));
-
- // USHORT languageID Language ID.
- record.setLanguageID(readUShort(random));
-
- // USHORT nameID Name ID.
- record.setNameID(readUShort(random));
-
- // USHORT length String length (in bytes).
- record.setLength(readUShort(random));
-
- // USHORT offset String offset from start of storage area (in bytes).
- int nameOffset = readUShort(random);
- byte[] value = new byte[record.getLength()];
-
- random.mark();
- random.seek(stringTableOffset + nameOffset);
- random.read(value, 0, record.getLength());
- record.setValue(new String(value, "UTF-16BE")); //$NON-NLS-1$
- random.reset();
-
- return record;
- }
-
- public short readShort(IRandomAccess random) throws IOException {
- int b1 = random.read();
- int b2 = random.read();
-
- if ((b1 | b2) < 0) {
- throw new IOException("unexpected end of stream"); //$NON-NLS-1$
- }
-
- return (short) ((b1 << 8) + b2);
- }
-
- public TTTable readTable(TTFont font, IRandomAccess random)
- throws IOException {
- byte[] name = readBytes(random, 4);
- int checksum = readInt(random);
- int offset = readInt(random);
- int length = readInt(random);
-
- TTTable result = new TTTable(font, offset, length);
- result.setName(name);
- result.setChecksum(checksum);
- return result;
- }
-
- public void readTables(TTFont font, IRandomAccess random)
- throws IOException {
- font.setSfntVersion(readInt(random));
-
- int tableCount = readUShort(random);
-
- // skip search range
- // skip entry selector
- // skip range shift
- random.seekBy(6);
- tables = new TTTable[tableCount];
-
- for (int i = 0; i < tableCount; i++) {
- tables[i] = readTable(font, random);
- }
- }
-
- public long readUInt(IRandomAccess random) throws IOException {
- int b1 = random.read();
- int b2 = random.read();
- int b3 = random.read();
- int b4 = random.read();
-
- if ((b1 | b2 | b3 | b4) < 0) {
- throw new IOException("unexpected end of stream"); //$NON-NLS-1$
- }
-
- return (((long) b1 << 24) + (b2 << 16) + (b3 << 8) + b4);
- }
-
- public int readUShort(IRandomAccess random) throws IOException {
- int b1 = random.read();
- int b2 = random.read();
-
- if ((b1 | b2) < 0) {
- throw new IOException("unexpected end of stream"); //$NON-NLS-1$
- }
-
- return (b1 << 8) + b2;
- }
-
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTFontSerializer.java b/src/de/intarsys/cwt/font/truetype/TTFontSerializer.java
deleted file mode 100644
index 6c38802..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTFontSerializer.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-import java.io.IOException;
-
-import de.intarsys.tools.randomaccess.IRandomAccess;
-import de.intarsys.tools.stream.StreamTools;
-
-/**
- *
- */
-public class TTFontSerializer {
-
- private TTFont font;
-
- private int tableOffset = 0;
-
- public TTFontSerializer() {
- super();
- }
-
- public TTFont getFont() {
- return font;
- }
-
- public void write(IRandomAccess random, TTFont pFont) throws IOException {
- this.font = pFont;
- writeFontHeader(random);
- writeTableDirectory(random);
- writeTables(random);
- }
-
- public void write_loca(IRandomAccess random, int[] locations,
- boolean shortFormat) throws IOException {
- for (int i = 0; i < locations.length; i++) {
- if (shortFormat) {
- writeShort(random, locations[i] >> 1);
- } else {
- writeInt(random, locations[i]);
- }
- }
- }
-
- public void write_name(IRandomAccess random, TTNameRecord[] names)
- throws IOException {
- int offset = 6 + (names.length * 12);
- writeShort(random, 0);
- writeShort(random, names.length);
- writeShort(random, offset);
- int nameOffset = 0;
- for (int i = 0; i < names.length; i++) {
- writeShort(random, names[i].getPlatformID());
- writeShort(random, names[i].getEncodingID());
- writeShort(random, names[i].getLanguageID());
- writeShort(random, names[i].getNameID());
- writeShort(random, names[i].getLength());
- writeShort(random, nameOffset);
- nameOffset += names[i].getLength();
- }
- for (int i = 0; i < names.length; i++) {
- writeBytes(
- random,
- names[i].getValue().getBytes("UTF-16BE"), 0, names[i].getLength()); //$NON-NLS-1$
- }
- }
-
- public void writeByte(IRandomAccess random, int value) throws IOException {
- random.write(value);
- }
-
- public void writeBytes(IRandomAccess random, byte[] value, int off, int len)
- throws IOException {
- random.write(value, off, len);
- }
-
- /**
- * <pre>
- * Fixed sfnt version 0x00010000 for version 1.0.
- * USHORT numTables Number of tables.
- * USHORT searchRange (Maximum power of 2 &lt;= numTables) x 16.
- * USHORT entrySelector Log2(maximum power of 2 &lt;= numTables).
- * USHORT rangeShift NumTables x 16-searchRange.
- * </pre>
- *
- * @throws IOException
- */
- protected void writeFontHeader(IRandomAccess random) throws IOException {
- int numTables = getFont().getTables().length;
- int maxPower = 1;
- int log2MaxPower = 0;
- while (maxPower <= numTables) {
- maxPower = maxPower << 1;
- log2MaxPower += 1;
- }
- if (log2MaxPower > 0) {
- // we are 1 step to far...
- maxPower = maxPower >> 1;
- log2MaxPower--;
- }
- writeInt(random, 0x00010000);
- writeShort(random, numTables);
- writeShort(random, maxPower << 4);
- writeShort(random, log2MaxPower);
- writeShort(random, (numTables - maxPower) << 4);
- }
-
- public void writeInt(IRandomAccess random, int value) throws IOException {
- random.write((byte) (value >> 24));
- random.write((byte) (value >> 16));
- random.write((byte) (value >> 8));
- random.write((byte) (value));
- }
-
- public void writeShort(IRandomAccess random, int value) throws IOException {
- random.write((byte) (value >> 8));
- random.write((byte) (value));
- }
-
- protected void writeTableDirectory(IRandomAccess random) throws IOException {
- // todo recompute table directory information
- int tableCount = getFont().getTables().length;
- tableOffset = (tableCount * 16) + 12;
- for (int i = 0; i < tableCount; i++) {
- TTTable table = getFont().getTables()[i];
- writeTableDirectoryTable(random, table);
- }
- }
-
- protected void writeTableDirectoryTable(IRandomAccess random, TTTable table)
- throws IOException {
- int length = (int) table.getLength();
- writeBytes(random, table.getName(), 0, table.getName().length);
- writeInt(random, table.getChecksum());
- writeInt(random, tableOffset);
- writeInt(random, length);
- // table.setOffset(tableOffset);
- tableOffset = (tableOffset + length + 3) & (~3);
- }
-
- protected void writeTables(IRandomAccess random) throws IOException {
- int tableCount = getFont().getTables().length;
-
- /**
- * java.util.Arrays.sort(getFont().getTables(), new Comparator() {
- * public int compare(Object o1, Object o2) { return (int) (((TTTable)
- * o1).getOffset() - ((TTTable) o2).getOffset()); }});
- */
- for (int i = 0; i < tableCount; i++) {
- TTTable table = getFont().getTables()[i];
- writeTablesTable(random, table);
- }
- }
-
- protected void writeTablesTable(IRandomAccess random, TTTable table)
- throws IOException {
- IRandomAccess tableRandom = table.getRandomAccess();
- try {
- tableRandom.seek(0);
- int length = (int) table.getLength();
- for (int i = 0; i < length; i++) {
- writeByte(random, tableRandom.read());
- }
- // pad with zeros
- // todo make faster
- for (int i = length; i < ((length + 3) & (~3)); i++) {
- writeByte(random, (byte) 0);
- }
- } finally {
- StreamTools.close(tableRandom);
- }
- }
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTHorizontalHeader.java b/src/de/intarsys/cwt/font/truetype/TTHorizontalHeader.java
deleted file mode 100644
index f073bc9..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTHorizontalHeader.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-/**
- *
- */
-public class TTHorizontalHeader {
- private short ascender;
-
- private short descender;
-
- private short lineGap;
-
- private int advanceWidthMax;
-
- private short minLeftSideBearing;
-
- private short minRightSideBearing;
-
- private short xMaxExtent;
-
- private short caretSlopeRise;
-
- private short caretSlopeRun;
-
- private int numberOfHMetrics;
-
- public int getAdvanceWidthMax() {
- return advanceWidthMax;
- }
-
- public short getAscender() {
- return ascender;
- }
-
- public short getCaretSlopeRise() {
- return caretSlopeRise;
- }
-
- public short getCaretSlopeRun() {
- return caretSlopeRun;
- }
-
- public short getDescender() {
- return descender;
- }
-
- public short getLineGap() {
- return lineGap;
- }
-
- public short getMinLeftSideBearing() {
- return minLeftSideBearing;
- }
-
- public short getMinRightSideBearing() {
- return minRightSideBearing;
- }
-
- public int getNumberOfHMetrics() {
- return numberOfHMetrics;
- }
-
- public short getXMaxExtent() {
- return xMaxExtent;
- }
-
- public void setAdvanceWidthMax(int i) {
- advanceWidthMax = i;
- }
-
- public void setAscender(short s) {
- ascender = s;
- }
-
- public void setCaretSlopeRise(short s) {
- caretSlopeRise = s;
- }
-
- public void setCaretSlopeRun(short s) {
- caretSlopeRun = s;
- }
-
- public void setDescender(short s) {
- descender = s;
- }
-
- public void setLineGap(short s) {
- lineGap = s;
- }
-
- public void setMinLeftSideBearing(short s) {
- minLeftSideBearing = s;
- }
-
- public void setMinRightSideBearing(short s) {
- minRightSideBearing = s;
- }
-
- public void setNumberOfHMetrics(int i) {
- numberOfHMetrics = i;
- }
-
- public void setXMaxExtent(short s) {
- xMaxExtent = s;
- }
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTMetrics.java b/src/de/intarsys/cwt/font/truetype/TTMetrics.java
deleted file mode 100644
index 4120845..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTMetrics.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-/**
- *
- */
-public class TTMetrics {
- private short xAvgCharWidth;
-
- private int usWeightClass;
-
- private int usWidthClass;
-
- private int fsType;
-
- private short ySubscriptXSize;
-
- private short ySubscriptYSize;
-
- private short ySubscriptXOffset;
-
- private short ySubscriptYOffset;
-
- private short ySuperscriptXSize;
-
- private short ySuperscriptYSize;
-
- private short ySuperscriptXOffset;
-
- private short ySuperscriptYOffset;
-
- private short yStrikeoutSize;
-
- private short yStrikeoutPosition;
-
- private short sFamilyClass;
-
- private TTMetricsPanose panose;
-
- private byte[] achVendID = new byte[4];
-
- private int fsSelection;
-
- private int usFirstCharIndex;
-
- private int usLastCharIndex;
-
- private short sTypoAscender;
-
- private short sTypoDescender;
-
- private short sTypoLineGap;
-
- private int usWinAscent;
-
- private int usWinDescent;
-
- private short sxHeight;
-
- private short sCapHeight;
-
- private int usDefaultChar;
-
- private int usBreakChar;
-
- private int usMaxContext;
-
- public byte[] getAchVendID() {
- return achVendID;
- }
-
- public int getFsSelection() {
- return fsSelection;
- }
-
- public int getFsType() {
- return fsType;
- }
-
- public TTMetricsPanose getPanose() {
- return panose;
- }
-
- public short getSCapHeight() {
- return sCapHeight;
- }
-
- public short getSFamilyClass() {
- return sFamilyClass;
- }
-
- public short getSTypoAscender() {
- return sTypoAscender;
- }
-
- public short getSTypoDescender() {
- return sTypoDescender;
- }
-
- public short getSTypoLineGap() {
- return sTypoLineGap;
- }
-
- public short getSxHeight() {
- return sxHeight;
- }
-
- public int getUsBreakChar() {
- return usBreakChar;
- }
-
- public int getUsDefaultChar() {
- return usDefaultChar;
- }
-
- public int getUsFirstCharIndex() {
- return usFirstCharIndex;
- }
-
- public int getUsLastCharIndex() {
- return usLastCharIndex;
- }
-
- public int getUsMaxContext() {
- return usMaxContext;
- }
-
- public int getUsWeightClass() {
- return usWeightClass;
- }
-
- public int getUsWidthClass() {
- return usWidthClass;
- }
-
- public int getUsWinAscent() {
- return usWinAscent;
- }
-
- public int getUsWinDescent() {
- return usWinDescent;
- }
-
- public short getXAvgCharWidth() {
- return xAvgCharWidth;
- }
-
- public short getYStrikeoutPosition() {
- return yStrikeoutPosition;
- }
-
- public short getYStrikeoutSize() {
- return yStrikeoutSize;
- }
-
- public short getYSubscriptXOffset() {
- return ySubscriptXOffset;
- }
-
- public short getYSubscriptXSize() {
- return ySubscriptXSize;
- }
-
- public short getYSubscriptYOffset() {
- return ySubscriptYOffset;
- }
-
- public short getYSubscriptYSize() {
- return ySubscriptYSize;
- }
-
- public short getYSuperscriptXOffset() {
- return ySuperscriptXOffset;
- }
-
- public short getYSuperscriptXSize() {
- return ySuperscriptXSize;
- }
-
- public short getYSuperscriptYOffset() {
- return ySuperscriptYOffset;
- }
-
- public short getYSuperscriptYSize() {
- return ySuperscriptYSize;
- }
-
- public void setAchVendID(byte[] bs) {
- achVendID = bs;
- }
-
- public void setFsSelection(int i) {
- fsSelection = i;
- }
-
- public void setFsType(int s) {
- fsType = s;
- }
-
- public void setPanose(byte[] bs) {
- if ((bs != null) && (bs.length == 10)) {
- panose = new TTMetricsPanose(bs);
- }
- }
-
- public void setSCapHeight(short capHeight) {
- sCapHeight = capHeight;
- }
-
- public void setSFamilyClass(short s) {
- sFamilyClass = s;
- }
-
- public void setSTypoAscender(short s) {
- sTypoAscender = s;
- }
-
- public void setSTypoDescender(short s) {
- sTypoDescender = s;
- }
-
- public void setSTypoLineGap(short s) {
-
- sTypoLineGap = s;
- }
-
- public void setSxHeight(short sxHeight) {
- this.sxHeight = sxHeight;
- }
-
- public void setUsBreakChar(int usBreakChar) {
- this.usBreakChar = usBreakChar;
- }
-
- public void setUsDefaultChar(int usDefaultChar) {
- this.usDefaultChar = usDefaultChar;
- }
-
- public void setUsFirstCharIndex(int i) {
- usFirstCharIndex = i;
- }
-
- public void setUsLastCharIndex(int i) {
- usLastCharIndex = i;
- }
-
- public void setUsMaxContext(int usMaxContext) {
- this.usMaxContext = usMaxContext;
- }
-
- public void setUsWeightClass(int i) {
- usWeightClass = i;
- }
-
- public void setUsWidthClass(int i) {
- usWidthClass = i;
- }
-
- public void setUsWinAscent(int i) {
- usWinAscent = i;
- }
-
- public void setUsWinDescent(int i) {
- usWinDescent = i;
- }
-
- public void setXAvgCharWidth(short s) {
- xAvgCharWidth = s;
- }
-
- public void setYStrikeoutPosition(short s) {
- yStrikeoutPosition = s;
- }
-
- public void setYStrikeoutSize(short s) {
- yStrikeoutSize = s;
- }
-
- public void setYSubscriptXOffset(short s) {
- ySubscriptXOffset = s;
- }
-
- public void setYSubscriptXSize(short s) {
- ySubscriptXSize = s;
- }
-
- public void setYSubscriptYOffset(short s) {
- ySubscriptYOffset = s;
- }
-
- public void setYSubscriptYSize(short s) {
- ySubscriptYSize = s;
- }
-
- public void setYSuperscriptXOffset(short s) {
- ySuperscriptXOffset = s;
- }
-
- public void setYSuperscriptXSize(short s) {
- ySuperscriptXSize = s;
- }
-
- public void setYSuperscriptYOffset(short s) {
- ySuperscriptYOffset = s;
- }
-
- public void setYSuperscriptYSize(short s) {
- ySuperscriptYSize = s;
- }
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTMetricsPanose.java b/src/de/intarsys/cwt/font/truetype/TTMetricsPanose.java
deleted file mode 100644
index 58fe9f4..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTMetricsPanose.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-/**
- *
- */
-public class TTMetricsPanose {
- public static int bFamilyType = 0;
-
- public static int bSerifStyle = 1;
-
- public static int bWeight = 2;
-
- public static int bProportion = 3;
-
- public static int bContrast = 4;
-
- public static int bStrokeVariation = 5;
-
- public static int bArmStyle = 6;
-
- public static int bLetterform = 7;
-
- public static int bMidline = 8;
-
- public static int bXHeight = 9;
-
- public static int cProportionMonospaced = 9;
-
- private byte[] panose;
-
- public TTMetricsPanose(byte[] panoseBytes) {
- if ((panoseBytes == null) || (panoseBytes.length != 10)) {
- throw new IllegalArgumentException(
- "TrueType table OS/2: panose bytes must not be null and exactly 10 bytes long"); //$NON-NLS-1$
- }
- this.panose = panoseBytes;
- }
-
- public byte[] getPanose() {
- return panose;
- }
-
- public boolean isProportionMonospaced() {
- return getPanose()[bProportion] == cProportionMonospaced;
- }
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTPostScriptInformation.java b/src/de/intarsys/cwt/font/truetype/TTPostScriptInformation.java
deleted file mode 100644
index 0cef553..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTPostScriptInformation.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-/**
- *
- */
-public class TTPostScriptInformation {
- private float version = 0; // 0x00010000 for version 1.0
-
- private float italicAngle; // Italic angle in counter-clockwise degrees
-
- // from the vertical. Zero for upright text,
- // negative for text that leans to the right
- // (forward).
-
- private int underlinePosition; // This is the suggested distance of the top
-
- // of the underline from the baseline
- // (negative values indicate below
- // baseline).
-
- private int underlineThickness; // Suggested values for the underline
-
- // thickness.
-
- private long isFixedPitch; // Set to 0 if the font is proportionally
-
- // spaced, non-zero if the font is not
- // proportionally spaced (i.e. monospaced).
-
- public TTPostScriptInformation() {
- }
-
- public long getIsFixedPitch() {
- return isFixedPitch;
- }
-
- public float getItalicAngle() {
- return italicAngle;
- }
-
- public int getUnderlinePosition() {
- return underlinePosition;
- }
-
- public int getUnderlineThickness() {
- return underlineThickness;
- }
-
- public float getVersion() {
- return version;
- }
-
- public void setIsFixedPitch(long l) {
- isFixedPitch = l;
- }
-
- public void setItalicAngle(float f) {
- italicAngle = f;
- }
-
- public void setUnderlinePosition(int i) {
- underlinePosition = i;
- }
-
- public void setUnderlineThickness(int i) {
- underlineThickness = i;
- }
-
- public void setVersion(float f) {
- version = f;
- }
-}
diff --git a/src/de/intarsys/cwt/font/truetype/TTTable.java b/src/de/intarsys/cwt/font/truetype/TTTable.java
deleted file mode 100644
index 68b4d16..0000000
--- a/src/de/intarsys/cwt/font/truetype/TTTable.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.truetype;
-
-import java.io.IOException;
-
-import de.intarsys.tools.randomaccess.IRandomAccess;
-import de.intarsys.tools.randomaccess.RandomAccessByteArray;
-import de.intarsys.tools.randomaccess.RandomAccessViewport;
-import de.intarsys.tools.stream.StreamTools;
-
-/**
- *
- */
-public class TTTable {
- private byte[] bytes;
-
- private int checksum = 0;
-
- private TTFont font;
-
- private long length;
-
- private byte[] name;
-
- private long offset;
-
- protected TTTable(TTFont font, long offset, long length) {
- super();
- this.font = font;
- this.offset = offset;
- this.length = length;
- }
-
- protected int createChecksum() throws IOException {
- IRandomAccess random = getRandomAccess();
- try {
- random.seek(0);
- long len = (random.getLength() + 3) / 4;
- int sum = 0;
- for (int i = 0; i < len; i++) {
- int v = random.read();
- v = (v << 8) + random.read();
- v = (v << 8) + random.read();
- v = (v << 8) + random.read();
- sum += v;
- }
- return sum;
- } finally {
- StreamTools.close(random);
- }
- }
-
- public int getChecksum() {
- if (checksum == 0) {
- try {
- checksum = createChecksum();
- } catch (IOException e) {
- //
- }
- }
- return checksum;
- }
-
- public TTFont getFont() {
- return font;
- }
-
- public long getLength() {
- return length;
- }
-
- public byte[] getName() {
- return name;
- }
-
- public long getOffset() {
- return offset;
- }
-
- public IRandomAccess getRandomAccess() throws IOException {
- if (bytes != null) {
- return new RandomAccessByteArray(bytes);
- }
- IRandomAccess random = getFont().getLocator().getRandomAccess();
- IRandomAccess viewport = new RandomAccessViewport(random, getOffset(),
- getLength());
- return viewport;
- }
-
- protected void setBytes(byte[] pBytes) {
- bytes = pBytes;
- checksum = 0;
- length = pBytes.length;
- offset = 0;
- }
-
- protected void setChecksum(int i) {
- checksum = i;
- }
-
- public void setName(byte[] string) {
- name = string;
- }
-
- @Override
- public String toString() {
- return new String(getName());
- }
-}
diff --git a/src/de/intarsys/cwt/font/type1/Type1Font.java b/src/de/intarsys/cwt/font/type1/Type1Font.java
deleted file mode 100644
index e5e628d..0000000
--- a/src/de/intarsys/cwt/font/type1/Type1Font.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.font.type1;
-
-import java.io.IOException;
-
-import de.intarsys.cwt.font.FontStyle;
-import de.intarsys.cwt.font.FontTools;
-import de.intarsys.cwt.font.afm.AFM;
-import de.intarsys.tools.locator.ILocator;
-
-/**
- * This is the skeleton for a type 1 font implementation. Up to now, we only
- * need the font metrics (.afm) part.
- */
-public class Type1Font {
-
- public static Type1Font createFromLocator(ILocator locator)
- throws IOException {
- Type1Font result = new Type1Font();
- result.setLocator(locator);
- result.initializeFromLocator();
- return result;
- }
-
- private AFM afm;
-
- private ILocator locator;
-
- public Type1Font() {
- }
-
- public Type1Font(AFM afm) {
- this.afm = afm;
- }
-
- public String getFontFamilyName() {
- return FontTools.getFontFamilyName(getFontName());
- }
-
- synchronized public AFM getFontMetrics() {
- return afm;
- }
-
- public String getFontName() {
- return afm.getFontName();
- }
-
- public FontStyle getFontStyle() {
- return FontTools.getFontStyle(getFontName());
- }
-
- public ILocator getLocator() {
- return locator;
- }
-
- protected void initializeAfm() throws IOException {
- ILocator parentLocator = getLocator().getParent();
- if (parentLocator == null) {
- // can't lookup font metrics...
- return;
- }
- String localName = getLocator().getLocalName();
- ILocator afmLocator = parentLocator.getChild(localName + ".afm");
- afm = AFM.createFromLocator(afmLocator);
- }
-
- protected void initializeFromLocator() throws IOException {
- initializePfb();
- initializeAfm();
- }
-
- protected void initializePfb() {
- // currently we do not parse any information from the pfb..
- }
-
- public boolean isSymbolFont() {
- return false;
- }
-
- protected void setLocator(ILocator locator) {
- this.locator = locator;
- }
-
-}
diff --git a/src/de/intarsys/cwt/hybrid/image/CwtHybridImage.java b/src/de/intarsys/cwt/hybrid/image/CwtHybridImage.java
deleted file mode 100644
index 8672cc1..0000000
--- a/src/de/intarsys/cwt/hybrid/image/CwtHybridImage.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package de.intarsys.cwt.hybrid.image;
-
-import java.awt.image.BufferedImage;
-
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-
-import de.intarsys.cwt.awt.environment.CwtAwtGraphicsContext;
-import de.intarsys.cwt.awt.image.CwtAwtImage;
-import de.intarsys.cwt.awt.image.IAwtImage;
-import de.intarsys.cwt.environment.IGraphicsContext;
-import de.intarsys.cwt.swt.environment.CwtSwtGraphicsContext;
-import de.intarsys.cwt.swt.image.CwtSwtImage;
-import de.intarsys.cwt.swt.image.ISwtImage;
-import de.intarsys.cwt.swt.image.ImageConverterAwt2Swt;
-import de.intarsys.cwt.swt.image.ImageConverterSwt2Awt;
-
-public class CwtHybridImage implements IAwtImage, ISwtImage {
-
- private CwtAwtImage awtImage;
-
- private CwtSwtImage swtImage;
-
- public CwtHybridImage(BufferedImage bufferedImage) {
- super();
- this.awtImage = new CwtAwtImage(bufferedImage);
- }
-
- public CwtHybridImage(CwtAwtImage awtImage) {
- super();
- this.awtImage = awtImage;
- }
-
- public CwtHybridImage(CwtSwtImage swtImage) {
- super();
- this.swtImage = swtImage;
- }
-
- public CwtHybridImage(ImageData imageData) {
- super();
- this.swtImage = new CwtSwtImage(imageData);
- }
-
- protected CwtAwtImage createAwtImage() {
- ImageConverterSwt2Awt converter = new ImageConverterSwt2Awt(swtImage
- .getImageData());
- BufferedImage bufferedImage = converter.getBufferedImage();
- return new CwtAwtImage(bufferedImage);
- }
-
- protected CwtSwtImage createSwtImage() {
- ImageConverterAwt2Swt converter = new ImageConverterAwt2Swt(awtImage
- .getBufferedImage());
- ImageData imageData = converter.getImageData();
- return new CwtSwtImage(imageData);
- }
-
- protected void drawFromAwt(CwtAwtGraphicsContext graphicsContext, float x,
- float y) {
- if (awtImage == null) {
- awtImage = createAwtImage();
- }
- graphicsContext.drawImage(awtImage, x, y);
- }
-
- public void drawFromGraphicsContext(IGraphicsContext graphicsContext,
- float x, float y) {
- if (graphicsContext instanceof CwtSwtGraphicsContext) {
- drawFromSwt((CwtSwtGraphicsContext) graphicsContext, x, y);
- } else if (graphicsContext instanceof CwtAwtGraphicsContext) {
- drawFromAwt((CwtAwtGraphicsContext) graphicsContext, x, y);
- } else {
- throw new IllegalArgumentException("graphicsContext not supported");
- }
- }
-
- protected void drawFromSwt(CwtSwtGraphicsContext graphicsContext, float x,
- float y) {
- if (swtImage == null) {
- try {
- swtImage = createSwtImage();
- } catch (RuntimeException e) {
- // todo 0 dummy / error image
- return;
- }
- }
- CwtSwtGraphicsContext gc = graphicsContext;
- graphicsContext.drawImage(swtImage, x, y);
- }
-
- public BufferedImage getBufferedImage() {
- if (awtImage == null) {
- awtImage = createAwtImage();
- }
- return awtImage.getBufferedImage();
- }
-
- public int getHeight() {
- if (swtImage != null) {
- return swtImage.getHeight();
- }
- if (awtImage != null) {
- return awtImage.getHeight();
- }
- return 0;
- }
-
- public Image getImage(Device device) {
- if (swtImage == null) {
- swtImage = createSwtImage();
- }
- return swtImage.getImage(device);
- }
-
- public ImageData getImageData() {
- if (swtImage == null) {
- swtImage = createSwtImage();
- }
- return swtImage.getImageData();
- }
-
- public int getWidth() {
- if (swtImage != null) {
- return swtImage.getWidth();
- }
- if (awtImage != null) {
- return awtImage.getWidth();
- }
- return 0;
- }
-
-}
diff --git a/src/de/intarsys/cwt/hybrid/image/ImageIOImageContainer.java b/src/de/intarsys/cwt/hybrid/image/ImageIOImageContainer.java
deleted file mode 100644
index 9cd5b34..0000000
--- a/src/de/intarsys/cwt/hybrid/image/ImageIOImageContainer.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.hybrid.image;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.spi.IIORegistry;
-import javax.imageio.spi.ImageReaderSpi;
-import javax.imageio.stream.ImageInputStream;
-
-import de.intarsys.cwt.image.IImage;
-import de.intarsys.cwt.image.IImageEntry;
-import de.intarsys.cwt.image.ImageContainer;
-import de.intarsys.cwt.image.ImageMetadata;
-import de.intarsys.tools.locator.ILocator;
-import de.intarsys.tools.stream.StreamTools;
-
-/*
- * DOCME
- */
-public class ImageIOImageContainer extends ImageContainer {
-
- static public ImageIOImageContainer createFromLocator(ILocator locator)
- throws IOException {
- ImageReaderSpi provider = lookupProviderBySuffix(locator.getType());
- if (provider == null) {
- throw new IllegalArgumentException("unknown suffix");
- }
- return createFromLocator(locator, provider);
- }
-
- static public ImageIOImageContainer createFromLocator(ILocator locator,
- ImageReaderSpi provider) throws IOException {
- ImageIOImageContainer container = new ImageIOImageContainer(locator,
- provider);
- container.open();
- return container;
- }
-
- static public ImageIOImageContainer createFromLocator(ILocator locator,
- String formatName) throws IOException {
- ImageReaderSpi provider = lookupProviderByFormatName(formatName);
- if (provider == null) {
- throw new IllegalArgumentException("unknown format name");
- }
- return createFromLocator(locator, provider);
- }
-
- static protected ImageReaderSpi lookupProviderByFormatName(String formatName) {
- if (formatName == null) {
- return null;
- }
- for (Iterator iter = IIORegistry.getDefaultInstance()
- .getServiceProviders(ImageReaderSpi.class, true); iter
- .hasNext();) {
- ImageReaderSpi provider = (ImageReaderSpi) iter.next();
- String[] names = provider.getFormatNames();
- for (int index = 0; index < names.length; index++) {
- String currentName = names[index];
- if (formatName.equalsIgnoreCase(currentName)) {
- return provider;
- }
- }
- }
- return null;
- }
-
- static protected ImageReaderSpi lookupProviderBySuffix(String fileSuffix) {
- if (fileSuffix == null) {
- return null;
- }
- for (Iterator iter = IIORegistry.getDefaultInstance()
- .getServiceProviders(ImageReaderSpi.class, true); iter
- .hasNext();) {
- ImageReaderSpi provider = (ImageReaderSpi) iter.next();
- String[] suffixes = provider.getFileSuffixes();
- for (int index = 0; index < suffixes.length; index++) {
- String currentSuffix = suffixes[index];
- if (fileSuffix.equalsIgnoreCase(currentSuffix)) {
- return provider;
- }
- }
- }
- return null;
- }
-
- private ILocator locator;
-
- private ImageReader imageReader;
-
- private ImageInputStream imageStream;
-
- private ImageReaderSpi provider;
-
- private int count;
-
- private ImageMetadata metadata;
-
- private List imageEntries = new ArrayList();
-
- private InputStream inputStream;
-
- protected ImageIOImageContainer(ILocator locator, ImageReaderSpi provider) {
- super();
- this.locator = locator;
- this.provider = provider;
- }
-
- @Override
- protected void basicClose() throws IOException {
- if (imageReader != null) {
- imageReader.dispose();
- imageReader = null;
- }
- if (imageStream != null) {
- imageStream.close();
- imageStream = null;
- }
- // must close the input stream ourself! imageStream is not required
- // (and FileCacheImapgeInputStream really doesn't) to close!
- StreamTools.close(inputStream);
- }
-
- public IImageEntry getImageAt(int index) {
- if (index >= getImageCount()) {
- throw new IllegalArgumentException("invalid index");
- }
- return (IImageEntry) imageEntries.get(index);
- }
-
- public int getImageCount() {
- return count;
- }
-
- public ILocator getLocator() {
- return locator;
- }
-
- synchronized public ImageMetadata getMetadata() throws IOException {
- if (metadata == null) {
- metadata = ImageMetadata.createFromImageReader(imageReader);
- }
- return metadata;
- }
-
- protected IImage loadImage(int index) throws IOException {
- if (index >= getImageCount()) {
- throw new IllegalArgumentException("invalid index");
- }
- BufferedImage bufferedImage = imageReader.read(index++);
- if (bufferedImage == null) {
- return null;
- }
- return new CwtHybridImage(bufferedImage);
- }
-
- protected void open() throws IOException {
- try {
- inputStream = getLocator().getInputStream();
- imageStream = ImageIO.createImageInputStream(inputStream);
- imageReader = provider.createReaderInstance();
- imageReader.setInput(imageStream);
- count = imageReader.getNumImages(true);
- for (int i = 0; i < count; i++) {
- imageEntries.add(new ImageIOImageEntry(this, i));
- }
- } catch (IOException e) {
- basicClose();
- throw e;
- } catch (Exception e) {
- basicClose();
- throw new IOException("unexpected exception opening file");
- }
- }
-
-}
diff --git a/src/de/intarsys/cwt/hybrid/image/ImageIOImageEntry.java b/src/de/intarsys/cwt/hybrid/image/ImageIOImageEntry.java
deleted file mode 100644
index a05ea45..0000000
--- a/src/de/intarsys/cwt/hybrid/image/ImageIOImageEntry.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.hybrid.image;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-
-import de.intarsys.cwt.awt.image.IAwtImage;
-import de.intarsys.cwt.environment.IGraphicsContext;
-import de.intarsys.cwt.image.IImage;
-import de.intarsys.cwt.image.IImageContainer;
-import de.intarsys.cwt.image.ImageEntry;
-import de.intarsys.cwt.swt.image.ISwtImage;
-
-public class ImageIOImageEntry extends ImageEntry implements IAwtImage,
- ISwtImage {
-
- private static final int width = 400;
-
- private static final int height = 400;
-
- private int index;
-
- public ImageIOImageEntry(IImageContainer container, int index) {
- super(container);
- this.index = index;
- }
-
- public void drawFromGraphicsContext(IGraphicsContext graphicsContext,
- float x, float y) {
- getDelegate().drawFromGraphicsContext(graphicsContext, x, y);
- }
-
- public BufferedImage getBufferedImage() {
- return ((IAwtImage) getDelegate()).getBufferedImage();
- }
-
- @Override
- synchronized protected IImage getErrorImage(Exception e) {
- BufferedImage image = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
- Graphics2D gc = image.createGraphics();
- gc.setBackground(Color.WHITE);
- gc.fillRect(0, 0, width, height);
- gc.setColor(Color.RED);
- gc.drawLine(0, 0, width, height);
- gc.drawLine(0, height, width, 0);
- gc.setColor(Color.BLACK);
- gc.drawString("error loading image (" + e.getMessage() + ")", 10, 20);
- return new CwtHybridImage(image);
- }
-
- public Image getImage(Device device) {
- return ((ISwtImage) getDelegate()).getImage(device);
- }
-
- public ImageData getImageData() {
- return ((ISwtImage) getDelegate()).getImageData();
- }
-
- public int getIndex() {
- return index;
- }
-
- @Override
- protected IImage loadContent() throws IOException {
- return myContainer().loadImage(getIndex());
- }
-
- private ImageIOImageContainer myContainer() {
- return (ImageIOImageContainer) getContainer();
- }
-}
diff --git a/src/de/intarsys/cwt/image/IImage.java b/src/de/intarsys/cwt/image/IImage.java
deleted file mode 100644
index dc8d995..0000000
--- a/src/de/intarsys/cwt/image/IImage.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.image;
-
-import de.intarsys.cwt.environment.IGraphicsContext;
-
-public interface IImage {
-
- public void drawFromGraphicsContext(IGraphicsContext graphicsContext,
- float x, float y);
-
- public int getHeight();
-
- public int getWidth();
-}
diff --git a/src/de/intarsys/cwt/image/IImageContainer.java b/src/de/intarsys/cwt/image/IImageContainer.java
deleted file mode 100644
index b7ca1bf..0000000
--- a/src/de/intarsys/cwt/image/IImageContainer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.image;
-
-import java.io.IOException;
-
-import de.intarsys.tools.attribute.IAttributeSupport;
-import de.intarsys.tools.locator.ILocator;
-
-public interface IImageContainer extends IAttributeSupport {
-
- public void close() throws IOException;
-
- public IImageEntry getImageAt(int index);
-
- public int getImageCount();
-
- public ILocator getLocator();
-
- public ImageMetadata getMetadata() throws IOException;
-
-}
diff --git a/src/de/intarsys/cwt/image/ImageEntry.java b/src/de/intarsys/cwt/image/ImageEntry.java
deleted file mode 100644
index a69cf2b..0000000
--- a/src/de/intarsys/cwt/image/ImageEntry.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.image;
-
-import java.io.IOException;
-import java.lang.ref.SoftReference;
-
-import de.intarsys.tools.attribute.AttributeMap;
-
-public abstract class ImageEntry implements IImageEntry {
-
- final private IImageContainer container;
-
- final private AttributeMap attributes = new AttributeMap();
-
- private SoftReference delegate;
-
- protected ImageEntry(IImageContainer container) {
- super();
- this.container = container;
- }
-
- public Object getAttribute(Object key) {
- return attributes.get(key);
- }
-
- public IImageContainer getContainer() {
- return container;
- }
-
- synchronized protected IImage getDelegate() {
- IImage image = null;
- if (delegate != null) {
- image = (IImage) delegate.get();
- }
- if (image == null) {
- try {
- image = loadContent();
- } catch (Exception e) {
- image = getErrorImage(e);
- }
- delegate = new SoftReference(image);
- }
- return image;
- }
-
- abstract protected IImage getErrorImage(Exception e);
-
- public int getHeight() {
- return getDelegate().getHeight();
- }
-
- public int getWidth() {
- return getDelegate().getWidth();
- }
-
- abstract protected IImage loadContent() throws IOException;
-
- public Object removeAttribute(Object key) {
- return attributes.remove(key);
- }
-
- public Object setAttribute(Object key, Object o) {
- return attributes.put(key, o);
- }
-
-}
diff --git a/src/de/intarsys/cwt/image/ImageMetadata.java b/src/de/intarsys/cwt/image/ImageMetadata.java
deleted file mode 100644
index d103ac8..0000000
--- a/src/de/intarsys/cwt/image/ImageMetadata.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.image;
-
-import java.io.IOException;
-
-import javax.imageio.ImageReader;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.metadata.IIOMetadataNode;
-
-import org.w3c.dom.Node;
-
-public class ImageMetadata {
- public static ImageMetadata createFromImageReader(ImageReader imageReader)
- throws IOException {
- IIOMetadata[] imageMetadata;
-
- imageMetadata = new IIOMetadata[imageReader.getNumImages(true)];
- for (int index = 0; index < imageMetadata.length; index++) {
- imageMetadata[index] = imageReader.getImageMetadata(index);
- }
-
- return new ImageMetadata(imageReader.getStreamMetadata(), imageMetadata);
-
- }
-
- private IIOMetadata[] imageMetadata;
-
- private IIOMetadata streamMetadata;
-
- protected ImageMetadata() {
- super();
- }
-
- public ImageMetadata(IIOMetadata paramStreamMetadata,
- IIOMetadata[] paramImageMetadata) {
- streamMetadata = paramStreamMetadata;
- imageMetadata = paramImageMetadata;
- }
-
- public Node getAsTree(String formatName) {
- Node root;
-
- root = new IIOMetadataNode("root");
- if (streamMetadata != null) {
- root.appendChild(streamMetadata.getAsTree(formatName));
- }
- for (int index = 0; index < imageMetadata.length; index++) {
- Node node;
-
- node = new IIOMetadataNode(String.valueOf(index));
- root.appendChild(node);
- node.appendChild(imageMetadata[index].getAsTree(formatName));
- }
- return root;
- }
-
- public IIOMetadata[] getImageMetadata() {
- return imageMetadata;
- }
-
- public String getNativeMetadataFormatName() {
- // expect at least 1 image metadata entry
- return imageMetadata[0].getNativeMetadataFormatName();
- }
-
- public IIOMetadata getStreamMetadata() {
- return streamMetadata;
- }
-
- protected void setImageMetadata(IIOMetadata[] paramMetadata) {
- imageMetadata = paramMetadata;
- }
-
- protected void setStreamMetadata(IIOMetadata paramMetadata) {
- streamMetadata = paramMetadata;
- }
-}
diff --git a/src/de/intarsys/cwt/image/ImageTools.java b/src/de/intarsys/cwt/image/ImageTools.java
deleted file mode 100644
index afc6614..0000000
--- a/src/de/intarsys/cwt/image/ImageTools.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.image;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-
-import javax.imageio.IIOException;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.metadata.IIOMetadataFormatImpl;
-import javax.imageio.stream.ImageInputStream;
-
-import org.w3c.dom.Node;
-
-public class ImageTools {
-
- public static String extractJPEGColorSpaceType(ImageReader reader)
- throws IOException {
- IIOMetadata metadata;
- Node node;
- Node allegedChromaNode;
- Node allegedColorNode;
- Node name;
-
- try {
- metadata = reader.getImageMetadata(0);
- } catch (RuntimeException ex) {
- throw new ImageException(ex);
- } catch (IIOException ex) {
- throw new ImageException(ex);
- }
- node = metadata
- .getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
- /*
- * expect wanted nodes to always be there and to always have the needed
- * attribute
- */
- allegedChromaNode = node.getFirstChild();
- while (!allegedChromaNode.getLocalName().equals("Chroma")) { //$NON-NLS-1$
- allegedChromaNode = allegedChromaNode.getNextSibling();
- }
- allegedColorNode = allegedChromaNode.getFirstChild();
- while (!allegedColorNode.getLocalName().equals("ColorSpaceType")) { //$NON-NLS-1$
- allegedColorNode = allegedColorNode.getNextSibling();
- }
- if ((name = allegedColorNode.getAttributes().getNamedItem("name")) == null) { //$NON-NLS-1$
- throw new ImageException("color space not declared"); //$NON-NLS-1$
- }
- return name.getNodeValue();
- }
-
- public static String extractJPEGColorSpaceType(InputStream stream)
- throws IOException {
- ImageInputStream imageStream;
-
- imageStream = ImageIO.createImageInputStream(stream);
-
- try {
- Iterator<ImageReader> readers;
- ImageReader reader;
-
- readers = ImageIO.getImageReaders(imageStream);
- if (!readers.hasNext()) {
- throw new ImageException("no reader for this image type");
- }
- reader = readers.next();
- try {
- imageStream.reset();
- reader.setInput(imageStream);
- return extractJPEGColorSpaceType(reader);
- } finally {
- reader.dispose();
- }
- } finally {
- imageStream.close();
- }
- }
-
-}
diff --git a/src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsContext.java b/src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsContext.java
deleted file mode 100644
index 6a56486..0000000
--- a/src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsContext.java
+++ /dev/null
@@ -1,910 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.environment;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.RenderingHints.Key;
-import java.awt.font.FontRenderContext;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Area;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Rectangle2D;
-import java.util.Map;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.LineAttributes;
-import org.eclipse.swt.graphics.Path;
-import org.eclipse.swt.graphics.Pattern;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Region;
-import org.eclipse.swt.graphics.Transform;
-
-import de.intarsys.cwt.common.BlendMode;
-import de.intarsys.cwt.common.IGraphicsObject;
-import de.intarsys.cwt.common.IPaint;
-import de.intarsys.cwt.environment.IGraphicsContext;
-import de.intarsys.cwt.environment.IGraphicsEnvironment;
-import de.intarsys.cwt.image.IImage;
-import de.intarsys.tools.geometry.ApplySpaceChangeShape;
-import de.intarsys.tools.geometry.ShapeTools;
-import de.intarsys.tools.geometry.TransformedShape;
-import de.intarsys.tools.resourcetracker.ResourceTracker;
-
-/**
- * An {@link IGraphicsContext} mapping to SWT.
- * <p>
- * It is currently not safe to use this {@link IGraphicsContext} concurrently.
- */
-public class CwtSwtGraphicsContext implements IGraphicsContext {
-
- static final int BACKGROUND = 1 << 1;
-
- static final int FOREGROUND = 1 << 0;
-
- /**
- * A tracker handling path resources used by shapes. The path will be
- * disposed when the shape is no longer referenced.
- */
- private static ResourceTracker tracker = new ResourceTracker() {
- @Override
- protected void basicDispose(Object resource) {
- ((Path) resource).dispose();
- }
- };
-
- static public Path toPath(Device device, PathIterator pathIterator) {
- Path path;
- float[] coords;
-
- path = new Path(device);
- if (pathIterator.isDone()) {
- // empty path, might result from intersection
- path.addRectangle(0, 0, 0, 0);
- return path;
- }
- coords = new float[6];
- while (!pathIterator.isDone()) {
- int type;
-
- type = pathIterator.currentSegment(coords);
- switch (type) {
- case PathIterator.SEG_CLOSE:
- path.close();
- break;
- case PathIterator.SEG_CUBICTO:
- path.cubicTo(coords[0], coords[1], coords[2], coords[3],
- coords[4], coords[5]);
- break;
- case PathIterator.SEG_LINETO:
- path.lineTo(coords[0], coords[1]);
- break;
- case PathIterator.SEG_MOVETO:
- path.moveTo(coords[0], coords[1]);
- break;
- case PathIterator.SEG_QUADTO:
- path.quadTo(coords[0], coords[1], coords[2], coords[3]);
- break;
- default:
- throw new InternalError(
- "Program execution should not reach this point.");
- }
- pathIterator.next();
- }
- return path;
- }
-
- static public Rectangle2D toRectangle2D(Rectangle rect) {
- return new Rectangle2D.Float(rect.x, rect.y, rect.width, rect.height);
- }
-
- /**
- * This methods intentionally duplicated to avoid compile time dependency..
- *
- */
- static public Transform toTransform(Device device, AffineTransform at) {
- double[] tempElements = new double[6];
- at.getMatrix(tempElements);
- return new Transform(device, (float) tempElements[0],
- (float) tempElements[1], (float) tempElements[2],
- (float) tempElements[3], (float) tempElements[4],
- (float) tempElements[5]);
- }
-
- /**
- * This methods intentionally duplicated to avoid compile time dependency..
- *
- */
- static public Transform toTransform(Device device, Transform st,
- AffineTransform at) {
- if (st == null) {
- return new Transform(device, (float) at.getScaleX(), (float) at
- .getShearX(), (float) at.getShearY(), (float) at
- .getScaleY(), (float) at.getTranslateX(), (float) at
- .getTranslateY());
- }
- st.setElements((float) at.getScaleX(), (float) at.getShearX(),
- (float) at.getShearY(), (float) at.getScaleY(), (float) at
- .getTranslateX(), (float) at.getTranslateY());
- return st;
- }
-
- private boolean applyAlphaBackground;
-
- private boolean applyAlphaForeground;
-
- private boolean applyTransform = false;
-
- private Color backgroundColor;
-
- private Pattern backgroundPattern;
-
- private BlendMode blendMode = BlendMode.META.getDefault();
-
- private AffineTransform cachedAWTShapeTransform;
-
- private Transform cachedSWTShapeTransform;
-
- private TransformedShape currentClip;
-
- private AffineTransform currentTransform;
-
- private Device device;
-
- private float[] elements = new float[6];
-
- private double[] flatmatrix = new double[6];
-
- private org.eclipse.swt.graphics.Font font;
-
- private Transform fontTransform;
-
- private Color foregroundColor;
-
- private Pattern foregroundPattern;
-
- private GC gc;
-
- private int swtBackgroundAlpha;
-
- private org.eclipse.swt.graphics.Color swtBackgroundColor;
-
- private int swtForegroundAlpha;
-
- private org.eclipse.swt.graphics.Color swtForegroundColor;
-
- private Transform swtTransform;
-
- public CwtSwtGraphicsContext(GC paramGC, Device paramDevice) {
- swtBackgroundAlpha = 255;
- swtBackgroundColor = null;
- backgroundColor = null;
- device = paramDevice;
- font = null;
- swtForegroundAlpha = 255;
- swtForegroundColor = null;
- foregroundColor = null;
- gc = paramGC;
- applyAlphaForeground = false;
- applyAlphaBackground = false;
-
- swtTransform = new Transform(paramDevice);
- paramGC.getTransform(swtTransform);
- swtTransform.getElements(elements);
- currentTransform = new AffineTransform(elements);
-
- // this is the "default" clipping
- Rectangle2D rect = toRectangle2D(paramGC.getClipping());
- currentClip = ApplySpaceChangeShape.create(new Area(rect),
- currentTransform);
-
- // when setting to SWT.DEFAULT here curved shapes (like letters) will
- // look awful on gtk
- paramGC.setAntialias(SWT.OFF);
- paramGC.setInterpolation(SWT.NONE);
- }
-
- protected void applyAlphaBackground() {
- if (applyAlphaBackground) {
- applyAlphaBackground = false;
- if (gc.getAlpha() != swtBackgroundAlpha) {
- gc.setAlpha(swtBackgroundAlpha);
- if (swtForegroundAlpha != swtBackgroundAlpha) {
- applyAlphaForeground = true;
- }
- }
- }
- }
-
- protected void applyAlphaForeground() {
- if (applyAlphaForeground) {
- applyAlphaForeground = false;
- if (gc.getAlpha() != swtForegroundAlpha) {
- gc.setAlpha(swtForegroundAlpha);
- if (swtBackgroundAlpha != swtForegroundAlpha) {
- applyAlphaBackground = true;
- }
- }
- }
- }
-
- protected void applyClip() {
- if (currentClip == null) {
- gc.setClipping((Region) null);
- } else {
- // transform gc before clip is set
- applyTransform();
- PathIterator pathIterator = currentClip.getPathIterator(null);
- if (pathIterator.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
- gc.setFillRule(SWT.FILL_EVEN_ODD);
- } else {
- gc.setFillRule(SWT.FILL_WINDING);
- }
- Path clipPath = toPath(device, pathIterator);
- gc.setClipping(clipPath);
- clipPath.dispose();
- }
- }
-
- protected void applyTransform() {
- if (applyTransform) {
- applyTransform = false;
- currentTransform.getMatrix(flatmatrix);
- swtTransform.setElements((float) flatmatrix[0],
- (float) flatmatrix[1], (float) flatmatrix[2],
- (float) flatmatrix[3], (float) flatmatrix[4],
- (float) flatmatrix[5]);
- gc.setTransform(swtTransform);
- }
- }
-
- public void clip(Shape shape) {
- Area tempShape = ShapeTools.createArea(shape, false);
- if (currentClip == null) {
- currentClip = ApplySpaceChangeShape.create(tempShape,
- currentTransform);
- } else {
- Area tempClip = ShapeTools.createArea(currentClip, true);
- tempClip.intersect(tempShape);
- currentClip = ApplySpaceChangeShape.create(tempClip,
- currentTransform);
- }
- applyClip();
- }
-
- protected Path createPath(Shape s) {
- Path path;
- if (s instanceof IGraphicsObject) {
- path = (Path) ((IGraphicsObject) s).getData();
- if (path != null && !path.isDisposed()
- && !path.getDevice().isDisposed()) {
- return path;
- }
- }
- if (s instanceof Rectangle2D) {
- Rectangle2D rect = (Rectangle2D) s;
- path = new Path(device);
- path.addRectangle((float) rect.getX(), (float) rect.getY(),
- (float) rect.getWidth(), (float) rect.getHeight());
- } else {
- path = toPath(device, s.getPathIterator(null));
- }
- tracker.trackPhantom(s, path);
- if (s instanceof IGraphicsObject) {
- ((IGraphicsObject) s).setData(path);
- }
- return path;
- }
-
- public void dispose() {
- // The underlying GC might be used beyond the lifetime of this
- // IGraphicsContext implementation. Thus we have to assert that eventual
- // transformation resettings are propagated properly to the GC.
- applyTransform();
- if (swtBackgroundColor != null) {
- swtBackgroundColor.dispose();
- }
- if (backgroundPattern != null) {
- backgroundPattern.dispose();
- }
- if (font != null) {
- font.dispose();
- }
- if (fontTransform != null) {
- fontTransform.dispose();
- }
- if (swtForegroundColor != null) {
- swtForegroundColor.dispose();
- }
- if (foregroundPattern != null) {
- foregroundPattern.dispose();
- }
- if (swtTransform != null) {
- swtTransform.dispose();
- }
- if (cachedSWTShapeTransform != null) {
- cachedSWTShapeTransform.dispose();
- }
- }
-
- public void draw(Shape s) {
- applyAlphaForeground();
- if (s instanceof TransformedShape && gc.getForegroundPattern() == null) {
- AffineTransform awtShapeTransform = ((TransformedShape) s)
- .getTransform();
- if (awtShapeTransform != null) {
- // do NOT applyTransform here
- if (awtShapeTransform != cachedAWTShapeTransform) {
- cachedAWTShapeTransform = awtShapeTransform;
- if (cachedSWTShapeTransform != null) {
- cachedSWTShapeTransform.dispose();
- }
- cachedSWTShapeTransform = toTransform(device,
- awtShapeTransform);
- }
- Transform tempTransform = new Transform(device);
- currentTransform.getMatrix(flatmatrix);
- tempTransform.setElements((float) flatmatrix[0],
- (float) flatmatrix[1], (float) flatmatrix[2],
- (float) flatmatrix[3], (float) flatmatrix[4],
- (float) flatmatrix[5]);
- tempTransform.multiply(cachedSWTShapeTransform);
- gc.setTransform(tempTransform);
- } else {
- applyTransform();
- }
- Shape baseShape = ((TransformedShape) s).getBaseShape();
- gc.drawPath(createPath(baseShape));
- gc.setTransform(swtTransform);
- } else {
- applyTransform();
- gc.drawPath(createPath(s));
- }
- }
-
- public void drawImage(IImage image, float x, float y) {
- applyAlphaBackground();
- applyTransform();
- image.drawFromGraphicsContext(this, x, y);
- }
-
- public void drawString(String s, float x, float y) {
- applyTransform();
- boolean reset;
- applyAlphaForeground();
- reset = false;
- if (fontTransform != null) {
- float[] point;
-
- if (swtTransform == null) {
- swtTransform = new Transform(device);
- }
- gc.getTransform(swtTransform);
- swtTransform.getElements(elements);
- swtTransform.translate(x, y);
- point = new float[] { 0, 0 - gc.textExtent(s).y };
- fontTransform.transform(point);
- swtTransform.translate(point[0], point[1]);
- swtTransform.multiply(fontTransform);
- gc.setTransform(swtTransform);
- reset = true;
- }
- try {
- gc.drawString(s, 0, 0);
- } finally {
- if (reset) {
- swtTransform.setElements(elements[0], elements[1], elements[2],
- elements[3], elements[4], elements[5]);
- gc.setTransform(swtTransform);
- }
- }
- }
-
- public void fill(Shape s) {
- applyAlphaBackground();
- if (s instanceof TransformedShape && gc.getBackgroundPattern() == null) {
- AffineTransform awtShapeTransform = ((TransformedShape) s)
- .getTransform();
- if (awtShapeTransform != null) {
- // do NOT applyTransform here
- if (awtShapeTransform != cachedAWTShapeTransform) {
- cachedAWTShapeTransform = awtShapeTransform;
- if (cachedSWTShapeTransform != null) {
- cachedSWTShapeTransform.dispose();
- }
- cachedSWTShapeTransform = toTransform(device,
- awtShapeTransform);
- }
- Transform tempTransform = new Transform(device);
- currentTransform.getMatrix(flatmatrix);
- tempTransform.setElements((float) flatmatrix[0],
- (float) flatmatrix[1], (float) flatmatrix[2],
- (float) flatmatrix[3], (float) flatmatrix[4],
- (float) flatmatrix[5]);
- tempTransform.multiply(cachedSWTShapeTransform);
- gc.setTransform(tempTransform);
- } else {
- applyTransform();
- }
- Shape baseShape = ((TransformedShape) s).getBaseShape();
- if (ShapeTools.getWindingRule(baseShape) == PathIterator.WIND_EVEN_ODD) {
- gc.setFillRule(SWT.FILL_EVEN_ODD);
- } else {
- gc.setFillRule(SWT.FILL_WINDING);
- }
- Path path = createPath(baseShape);
- gc.fillPath(path);
- gc.setTransform(swtTransform);
- } else {
- applyTransform();
- PathIterator pathIterator = s.getPathIterator(null);
- if (pathIterator.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
- gc.setFillRule(SWT.FILL_EVEN_ODD);
- } else {
- gc.setFillRule(SWT.FILL_WINDING);
- }
- Path path = createPath(s);
- gc.fillPath(path);
- }
- }
-
- public Color getBackgroundColor() {
- if (backgroundColor == null) {
- RGB rgb = swtBackgroundColor.getRGB();
- backgroundColor = new Color(rgb.red, rgb.green, rgb.blue);
- }
- return backgroundColor;
- }
-
- public BlendMode getBlendMode() {
- return blendMode;
- }
-
- public Shape getClip() {
- if (currentClip == null) {
- return null;
- }
- return (Shape) currentClip.clone();
- }
-
- public Device getDevice() {
- return device;
- }
-
- public Font getFont() {
- // TODO;
- return null;
- }
-
- public FontRenderContext getFontRenderContext() {
- // TODO
- return null;
- }
-
- public Color getForegroundColor() {
- if (foregroundColor == null) {
- RGB rgb = swtForegroundColor.getRGB();
- foregroundColor = new Color(rgb.red, rgb.green, rgb.blue);
- }
- return foregroundColor;
- }
-
- public GC getGc() {
- return gc;
- }
-
- public IGraphicsEnvironment getGraphicsEnvironment() {
- return CwtSwtGraphicsEnvironment.get();
- }
-
- public RenderingHints getRenderingHints() {
- RenderingHints renderingHints;
- int value;
-
- renderingHints = new RenderingHints(null);
-
- value = gc.getAntialias();
- if (value == SWT.DEFAULT) {
- renderingHints.put(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_DEFAULT);
- } else if (value == SWT.OFF) {
- renderingHints.put(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_OFF);
- } else {
- renderingHints.put(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- }
-
- value = gc.getInterpolation();
- if (value == SWT.HIGH) {
- renderingHints.put(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- } else {
- renderingHints.put(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
- }
-
- value = gc.getTextAntialias();
- if (value == SWT.DEFAULT) {
- renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
- } else if (value == SWT.OFF) {
- renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
- } else {
- renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- }
-
- // TODO transfer other values
- return renderingHints;
- }
-
- public AffineTransform getTransform() {
- return (AffineTransform) currentTransform.clone();
- }
-
- protected float[] getTransformationValues(AffineTransform tx) {
- tx.getMatrix(flatmatrix);
- elements[0] = (float) flatmatrix[0];
- elements[1] = (float) flatmatrix[1];
- elements[2] = (float) flatmatrix[2];
- elements[3] = (float) flatmatrix[3];
- elements[4] = (float) flatmatrix[4];
- elements[5] = (float) flatmatrix[5];
- return elements;
- }
-
- public void resetAdvanced() {
- gc.setAdvanced(false);
- }
-
- public void rotate(float theta) {
- currentTransform.rotate(theta);
- applyTransform = true;
- if (currentClip != null) {
- currentClip.invalidate();
- }
- }
-
- public void scale(float x, float y) {
- currentTransform.scale(x, y);
- applyTransform = true;
- if (currentClip != null) {
- currentClip.invalidate();
- }
- }
-
- public void setBackgroundColor(Color color) {
- backgroundColor = color;
- swtBackgroundAlpha = color.getAlpha();
- applyAlphaBackground = true;
- org.eclipse.swt.graphics.Color newColor = new org.eclipse.swt.graphics.Color(
- device, color.getRed(), color.getGreen(), color.getBlue());
- setBackgroundColor(newColor);
- }
-
- public void setBackgroundColor(org.eclipse.swt.graphics.Color resource) {
- if (swtBackgroundColor != null) {
- swtBackgroundColor.dispose();
- }
- swtBackgroundColor = resource;
- backgroundColor = null;
- gc.setBackground(swtBackgroundColor);
- }
-
- public void setBackgroundPaint(IPaint paint) {
- swtBackgroundAlpha = (int) (paint.getAlphaValue() * 255);
- applyAlphaBackground = true;
- paint.setBackgroundPaintFromGraphicsContext(this);
- }
-
- public void setBackgroundPattern(Pattern resource) {
- if (backgroundPattern != null) {
- backgroundPattern.dispose();
- }
- backgroundPattern = resource;
- gc.setBackgroundPattern(backgroundPattern);
- }
-
- public void setBlendMode(BlendMode blendMode) {
- this.blendMode = blendMode;
- }
-
- public void setClip(Shape shape) {
- if (shape == null) {
- currentClip = null;
- } else {
- currentClip = ApplySpaceChangeShape.create(ShapeTools
- .createArea(shape, false), currentTransform);
- }
- applyClip();
- }
-
- public void setFont(Font awtFont) {
- int style;
- AffineTransform tx;
-
- if (font != null) {
- font.dispose();
- }
- style = SWT.NORMAL;
- if ((awtFont.getStyle() & Font.BOLD) > 0) {
- style |= SWT.BOLD;
- }
- if ((awtFont.getStyle() & Font.ITALIC) > 0) {
- style |= SWT.ITALIC;
- }
- if (fontTransform != null) {
- fontTransform.dispose();
- }
- if ((tx = awtFont.getTransform()).isIdentity()) {
- fontTransform = null;
- } else {
- fontTransform = new Transform(device, getTransformationValues(tx));
- }
- font = new org.eclipse.swt.graphics.Font(device, awtFont.getFontName(),
- awtFont.getSize(), style);
- gc.setFont(font);
- }
-
- public void setForegroundColor(Color color) {
- foregroundColor = color;
- swtForegroundAlpha = color.getAlpha();
- applyAlphaForeground = true;
- org.eclipse.swt.graphics.Color newColor = new org.eclipse.swt.graphics.Color(
- device, color.getRed(), color.getGreen(), color.getBlue());
- setForegroundColor(newColor);
- }
-
- public void setForegroundColor(org.eclipse.swt.graphics.Color resource) {
- if (swtForegroundColor != null) {
- swtForegroundColor.dispose();
- }
- swtForegroundColor = resource;
- foregroundColor = null;
- gc.setForeground(swtForegroundColor);
- }
-
- public void setForegroundPaint(IPaint paint) {
- swtForegroundAlpha = (int) (paint.getAlphaValue() * 255);
- applyAlphaForeground = true;
- paint.setForegroundPaintFromGraphicsContext(this);
- }
-
- public void setForegroundPattern(Pattern resource) {
- if (foregroundPattern != null) {
- foregroundPattern.dispose();
- }
- foregroundPattern = resource;
- gc.setForegroundPattern(foregroundPattern);
- }
-
- public void setRenderingHint(Key hintKey, Object hintValue) {
- if (hintKey == RenderingHints.KEY_ALPHA_INTERPOLATION) {
- // TODO might not have an equivalent
- return;
- }
- if (hintKey == RenderingHints.KEY_ANTIALIASING) {
- if (hintValue == RenderingHints.VALUE_ANTIALIAS_DEFAULT) {
- gc.setAntialias(SWT.DEFAULT);
- } else if (hintValue == RenderingHints.VALUE_ANTIALIAS_OFF) {
- gc.setAntialias(SWT.OFF);
- } else {
- gc.setAntialias(SWT.ON);
- }
- return;
- }
- if (hintKey == RenderingHints.KEY_COLOR_RENDERING) {
- // TODO might not have an equivalent
- return;
- }
- if (hintKey == RenderingHints.KEY_DITHERING) {
- // TODO might not have an equivalent
- return;
- }
- if (hintKey == RenderingHints.KEY_FRACTIONALMETRICS) {
- // TODO might not have an equivalent
- return;
- }
- if (hintKey == RenderingHints.KEY_INTERPOLATION) {
- if (hintValue == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
- gc.setInterpolation(SWT.HIGH);
- } else if (hintValue == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
- gc.setInterpolation(SWT.HIGH);
- } else {
- gc.setInterpolation(SWT.LOW);
- }
- return;
- }
- if (hintKey == RenderingHints.KEY_RENDERING) {
- // TODO might not have an equivalent
- return;
- }
- if (hintKey == RenderingHints.KEY_STROKE_CONTROL) {
- // TODO might not have an equivalent
- return;
- }
- if (hintKey == RenderingHints.KEY_TEXT_ANTIALIASING) {
- if (hintValue == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) {
- gc.setTextAntialias(SWT.DEFAULT);
- } else if (hintValue == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) {
- gc.setTextAntialias(SWT.OFF);
- } else {
- gc.setTextAntialias(SWT.ON);
- }
- }
- }
-
- public void setRenderingHints(Map hints) {
- if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) {
- // TODO
- }
- if (hints.containsKey(RenderingHints.KEY_ANTIALIASING)) {
- if (hints.get(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_DEFAULT) {
- gc.setAntialias(SWT.DEFAULT);
- } else if (hints.get(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_OFF) {
- gc.setAntialias(SWT.OFF);
- } else {
- gc.setAntialias(SWT.ON);
- }
- } else {
- gc.setAntialias(SWT.DEFAULT);
- }
- if (hints.containsKey(RenderingHints.KEY_COLOR_RENDERING)) {
- // TODO
- }
- if (hints.containsKey(RenderingHints.KEY_DITHERING)) {
- // TODO
- }
- if (hints.containsKey(RenderingHints.KEY_FRACTIONALMETRICS)) {
- // TODO
- }
- if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) {
- // TODO assign values
- if (hints.get(RenderingHints.KEY_INTERPOLATION) == RenderingHints.VALUE_INTERPOLATION_BICUBIC) {
- gc.setInterpolation(SWT.HIGH);
- } else if (hints.get(RenderingHints.KEY_INTERPOLATION) == RenderingHints.VALUE_INTERPOLATION_BILINEAR) {
- gc.setInterpolation(SWT.HIGH);
- } else {
- gc.setInterpolation(SWT.LOW);
- }
- } else {
- gc.setInterpolation(SWT.NONE);
- }
- if (hints.containsKey(RenderingHints.KEY_RENDERING)) {
- // TODO
- }
- if (hints.containsKey(RenderingHints.KEY_STROKE_CONTROL)) {
- // TODO
- }
- if (hints.containsKey(RenderingHints.KEY_TEXT_ANTIALIASING)) {
- if (hints.get(RenderingHints.KEY_TEXT_ANTIALIASING) == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) {
- gc.setTextAntialias(SWT.DEFAULT);
- } else if (hints.get(RenderingHints.KEY_TEXT_ANTIALIASING) == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) {
- gc.setTextAntialias(SWT.OFF);
- } else {
- gc.setTextAntialias(SWT.ON);
- }
- } else {
- gc.setTextAntialias(SWT.DEFAULT);
- }
- }
-
- public void setStroke(Stroke s) {
- if (s instanceof BasicStroke) {
- BasicStroke stroke;
- LineAttributes attributes;
- float[] dash;
- int value;
-
- stroke = (BasicStroke) s;
- attributes = new LineAttributes(stroke.getLineWidth());
-
- dash = stroke.getDashArray();
- if (dash == null) {
- attributes.style = SWT.LINE_SOLID;
- } else {
- for (int index = 0; index < dash.length; index++) {
- if (dash[index] <= 0) {
- // workaround for strange dash definitions,this will NOT
- // create a semantically equal dash!
- dash[index] = 1f;
- }
- }
- attributes.style = SWT.LINE_CUSTOM;
- attributes.dash = dash;
- }
-
- value = stroke.getEndCap();
- if (value == BasicStroke.CAP_BUTT) {
- attributes.cap = SWT.CAP_FLAT;
- } else if (value == BasicStroke.CAP_ROUND) {
- attributes.cap = SWT.CAP_ROUND;
- } else {
- attributes.cap = SWT.CAP_SQUARE;
- }
-
- value = stroke.getLineJoin();
- if (value == BasicStroke.JOIN_BEVEL) {
- attributes.join = SWT.JOIN_BEVEL;
- } else if (value == BasicStroke.JOIN_MITER) {
- attributes.join = SWT.JOIN_MITER;
- } else {
- attributes.join = SWT.JOIN_ROUND;
- }
-
- gc.setLineAttributes(attributes);
- // workaround for swt bug #210412 - set explicitly
- gc.setLineCap(attributes.cap);
- return;
- }
- // TODO do we use others?
- }
-
- public void setTransform(AffineTransform pTransform) {
- currentTransform = (AffineTransform) pTransform.clone();
- applyTransform = true;
- if (currentClip != null) {
- currentClip = ApplySpaceChangeShape.setTransform(currentClip,
- currentTransform);
- }
- }
-
- public java.awt.Point textExtent(String s) {
- Point extent = gc.textExtent(s);
- return new java.awt.Point(extent.x, extent.y);
- }
-
- public void transform(AffineTransform deltaTransform) {
- currentTransform.concatenate(deltaTransform);
- applyTransform = true;
- if (currentClip != null) {
- currentClip.invalidate();
- }
- }
-
- public void translate(float x, float y) {
- currentTransform.translate(x, y);
- applyTransform = true;
- if (currentClip != null) {
- currentClip.invalidate();
- }
- }
-
-}
diff --git a/src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsEnvironment.java b/src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsEnvironment.java
deleted file mode 100644
index 5c831e0..0000000
--- a/src/de/intarsys/cwt/swt/environment/CwtSwtGraphicsEnvironment.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.environment;
-
-import de.intarsys.cwt.environment.IGraphicsEnvironment;
-
-public class CwtSwtGraphicsEnvironment implements IGraphicsEnvironment {
-
- final private static CwtSwtGraphicsEnvironment ACTIVE = new CwtSwtGraphicsEnvironment();
-
- static public CwtSwtGraphicsEnvironment get() {
- return ACTIVE;
- }
-
-}
diff --git a/src/de/intarsys/cwt/swt/image/CwtSwtImage.java b/src/de/intarsys/cwt/swt/image/CwtSwtImage.java
deleted file mode 100644
index fc9911c..0000000
--- a/src/de/intarsys/cwt/swt/image/CwtSwtImage.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.image;
-
-import java.util.Arrays;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.Transform;
-import org.eclipse.swt.printing.Printer;
-
-import de.intarsys.cwt.environment.IGraphicsContext;
-import de.intarsys.cwt.swt.environment.CwtSwtGraphicsContext;
-
-public class CwtSwtImage implements ISwtImage {
-
- public static final boolean IS_GTK = "gtk".equals(SWT.getPlatform()); //$NON-NLS-1$
- private int height;
- private Image swtImage;
- private ImageData swtImageData;
-
- private int width;
-
- public CwtSwtImage(ImageData imageData) {
- swtImageData = imageData;
- setWidth(imageData.width);
- setHeight(imageData.height);
- }
-
- protected Image createSwtImage(Device device) {
- return new Image(device, getImageData());
- }
-
- public void drawFromGraphicsContext(IGraphicsContext graphicsContext,
- float x, float y) {
- Transform transform;
- GC gc = ((CwtSwtGraphicsContext) graphicsContext).getGc();
- ImageData imageData = getImageData();
- /*
- * swt seems to have a size limit for images; above a certain size
- * images are simply not displayed anymore; don't know the exact value
- */
- transform = null;
- if (imageData.data.length > (Integer.MAX_VALUE >> 7)) { // arbitrary
- float[] elements;
- Transform tempTransform;
- double scaleX;
- double scaleY;
-
- transform = new Transform(gc.getDevice());
- gc.getTransform(transform);
- elements = new float[6];
- transform.getElements(elements);
- double tx = elements[0];
- double ty = elements[3];
- double sx = elements[1];
- double sy = elements[2];
- scaleX = Math.pow((tx * tx) + (sy * sy), 0.5);
- scaleY = Math.pow((ty * ty) + (sx * sx), 0.5);
- imageData = imageData.scaledTo((int) Math.round(imageData.width
- * scaleX), (int) Math.round(imageData.height * scaleY));
- tempTransform = new Transform(gc.getDevice(), elements);
- tempTransform.scale((float) (1 / scaleX), (float) (1 / scaleY));
- gc.setTransform(tempTransform);
- tempTransform.dispose();
- }
-
- try {
- // workaround for eclipse bug #174027
- byte[] bytes = null;
- if (IS_GTK && gc.getDevice() instanceof Printer) {
- if (imageData.transparentPixel == -1
- && imageData.alphaData == null
- && imageData.maskData == null) {
- bytes = new byte[imageData.width * imageData.height];
- Arrays.fill(bytes, (byte) -1);
- imageData.alphaData = bytes;
- }
- }
- try {
- Image deviceImage = new Image(gc.getDevice(), imageData);
- try {
- gc.drawImage(deviceImage, (int) x, (int) y);
- } finally {
- deviceImage.dispose();
- }
- } finally {
- if (bytes != null) {
- imageData.alphaData = null;
- }
- }
- } finally {
- if (transform != null) {
- gc.setTransform(transform);
- transform.dispose();
- }
- }
- }
-
- public int getHeight() {
- return height;
- }
-
- public Image getImage(Device device) {
- if (swtImage == null) {
- swtImage = createSwtImage(device);
- }
- return swtImage;
- }
-
- public ImageData getImageData() {
- return swtImageData;
- }
-
- public int getWidth() {
- return width;
- }
-
- protected void setHeight(int paramHeight) {
- height = paramHeight;
- }
-
- protected void setWidth(int paramWidth) {
- width = paramWidth;
- }
-}
diff --git a/src/de/intarsys/cwt/swt/image/CwtSwtImageTools.java b/src/de/intarsys/cwt/swt/image/CwtSwtImageTools.java
deleted file mode 100644
index 192e831..0000000
--- a/src/de/intarsys/cwt/swt/image/CwtSwtImageTools.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.image;
-
-import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.graphics.RGB;
-
-public class CwtSwtImageTools {
-
- private static PaletteData[] GrayPalettes;
-
- private static PaletteData RgbPalette;
-
- public static PaletteData getGrayPalette(int bits) {
- int paletteIndex;
-
- if (GrayPalettes == null) {
- GrayPalettes = new PaletteData[4];
- }
-
- paletteIndex = (int) (Math.log(bits) / Math.log(2));
- if (GrayPalettes[paletteIndex] == null) {
- RGB[] colors;
-
- colors = new RGB[(int) Math.pow(2, bits)];
- for (int index = 0; index < colors.length; index++) {
- int value;
-
- value = (int) (index * (float) 255 / (colors.length - 1));
- colors[index] = new RGB(value, value, value);
- }
- GrayPalettes[paletteIndex] = new PaletteData(colors);
- }
- return GrayPalettes[paletteIndex];
- }
-
- public static PaletteData getRgbPalette() {
- if (RgbPalette == null) {
- RgbPalette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
- }
- return RgbPalette;
- }
-
-}
diff --git a/src/de/intarsys/cwt/swt/image/ISwtImage.java b/src/de/intarsys/cwt/swt/image/ISwtImage.java
deleted file mode 100644
index c541a95..0000000
--- a/src/de/intarsys/cwt/swt/image/ISwtImage.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.image;
-
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-
-import de.intarsys.cwt.image.IImage;
-
-public interface ISwtImage extends IImage {
- public Image getImage(Device device);
-
- public ImageData getImageData();
-
-}
diff --git a/src/de/intarsys/cwt/swt/image/ISwtPaint.java b/src/de/intarsys/cwt/swt/image/ISwtPaint.java
deleted file mode 100644
index 81cf82a..0000000
--- a/src/de/intarsys/cwt/swt/image/ISwtPaint.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.image;
-
-import org.eclipse.swt.graphics.Device;
-import org.eclipse.swt.graphics.Resource;
-
-import de.intarsys.cwt.common.IPaint;
-
-public interface ISwtPaint extends IPaint {
-
- public Resource toResource(Device device);
-}
diff --git a/src/de/intarsys/cwt/swt/image/ImageConverterAwt2Swt.java b/src/de/intarsys/cwt/swt/image/ImageConverterAwt2Swt.java
deleted file mode 100644
index 6869689..0000000
--- a/src/de/intarsys/cwt/swt/image/ImageConverterAwt2Swt.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.image;
-
-import java.awt.Point;
-import java.awt.Transparency;
-import java.awt.color.ColorSpace;
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorConvertOp;
-import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.ComponentSampleModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.IndexColorModel;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.graphics.RGB;
-
-import sun.awt.image.ByteInterleavedRaster;
-import sun.awt.image.BytePackedRaster;
-import de.intarsys.cwt.awt.image.CwtAwtImageTools;
-import de.intarsys.tools.system.SystemTools;
-import de.intarsys.tools.valueholder.IValueHolder;
-import de.intarsys.tools.valueholder.ObjectValueHolder;
-
-public class ImageConverterAwt2Swt {
-
- static class OS_Other implements OS_Switch {
- public PaletteData createRgbPaletteData() {
- return new PaletteData(0xFF0000, 0xFF00, 0xFF);
- }
-
- public void initializeRgbBandOffsets(int[] bandOffsets) {
- for (int index = 0; index < 3; index++) {
- bandOffsets[index] = index;
- }
- }
- }
-
- static interface OS_Switch {
- PaletteData createRgbPaletteData();
-
- void initializeRgbBandOffsets(int[] bandOffsets);
- }
-
- static class OS_Windows implements OS_Switch {
- public PaletteData createRgbPaletteData() {
- return new PaletteData(0xFF, 0xFF00, 0xFF0000);
- }
-
- public void initializeRgbBandOffsets(int[] bandOffsets) {
- for (int index = 0; index < 3; index++) {
- bandOffsets[index] = 2 - index;
- }
- }
- }
-
- private static Map<ColorSpace, Map<ColorSpace, ColorConvertOp>> ConvertOps;
-
- private static OS_Switch OsSwitch;
-
- static {
- ConvertOps = new HashMap<ColorSpace, Map<ColorSpace, ColorConvertOp>>();
- if (SystemTools.isWindows()) {
- OsSwitch = new OS_Windows();
- } else {
- OsSwitch = new OS_Other();
- }
- }
-
- public static BufferedImage createSwtCompatibleAwtImage(int width,
- int height, boolean transparent) {
- ComponentColorModel colorModel;
- int bands;
- int[] bandOffsets;
- SampleModel sampleModel;
- DataBuffer dataBuffer;
- WritableRaster raster;
-
- if (transparent) {
- colorModel = CwtAwtImageTools.getRgbTransparentColorModel();
- } else {
- colorModel = CwtAwtImageTools.getRgbColorModel();
- }
- bands = colorModel.getNumComponents();
- bandOffsets = new int[bands];
- OsSwitch.initializeRgbBandOffsets(bandOffsets);
- if (bandOffsets.length > 3) {
- bandOffsets[3] = 3;
- }
- sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
- width, height, bands, width * bands, bandOffsets);
- dataBuffer = new DataBufferByte(width * height * bands);
- raster = new SwtCompatibleRaster(sampleModel, dataBuffer, new Point(0,
- 0));
- return new BufferedImage(colorModel, raster, false, null);
- }
-
- protected static Map<ColorSpace, Map<ColorSpace, ColorConvertOp>> getConvertOps() {
- return ConvertOps;
- }
-
- private BufferedImage bufferedImage;
- private ImageData imageData;
-
- public ImageConverterAwt2Swt(BufferedImage paramBufferedImage) {
- bufferedImage = paramBufferedImage;
- }
-
- protected void computeValuesFromAwtImage(int depth, IValueHolder palette,
- IValueHolder scanlinePad, IValueHolder transparentPixel) {
- SampleModel sampleModel;
- ColorModel colorModel;
-
- sampleModel = getBufferedImage().getSampleModel();
- if (sampleModel.getDataType() != DataBuffer.TYPE_BYTE) {
- throw new IllegalStateException();
- }
- colorModel = getBufferedImage().getColorModel();
- if (!colorModel.getColorSpace().isCS_sRGB()) {
- throw new IllegalStateException();
- }
-
- if (colorModel instanceof ComponentColorModel) {
- if (!(sampleModel instanceof ComponentSampleModel)) {
- throw new IllegalStateException();
- }
- computeValuesPaletteDirect((ComponentSampleModel) sampleModel,
- (ComponentColorModel) colorModel, palette, scanlinePad,
- transparentPixel);
- return;
- } else if (colorModel instanceof IndexColorModel) {
- computeValuesPaletteIndexed((IndexColorModel) colorModel, depth,
- palette, scanlinePad, transparentPixel);
- return;
- }
- throw new IllegalStateException();
- }
-
- protected void computeValuesPaletteDirect(ComponentSampleModel sampleModel,
- ComponentColorModel colorModel, IValueHolder palette,
- IValueHolder scanlinePad, IValueHolder transparentPixel) {
- int[] componentSize;
- int[] bandOffsets;
- PaletteData paletteData;
-
- componentSize = colorModel.getComponentSize();
- for (int index = 0; index < componentSize.length; index++) {
- if (componentSize[index] != 8) {
- throw new IllegalStateException();
- }
- }
- bandOffsets = (sampleModel).getBandOffsets();
- if (bandOffsets.length == 4 && bandOffsets[3] != 3) {
- throw new IllegalStateException();
- }
- paletteData = new PaletteData(0xFF0000 >> (bandOffsets[0] << 3),
- 0xFF0000 >> (bandOffsets[1] << 3),
- 0xFF0000 >> (bandOffsets[2] << 3));
- palette.set(paletteData);
- scanlinePad.set(3);
- }
-
- protected void computeValuesPaletteIndexed(IndexColorModel colorModel,
- int depth, IValueHolder paletteHolder,
- IValueHolder scanlinePadHolder, IValueHolder transparentPixelHolder) {
- int[] awtRgb;
- RGB[] swtRgb;
-
- awtRgb = new int[colorModel.getMapSize()];
- colorModel.getRGBs(awtRgb);
-
- swtRgb = new RGB[(int) Math.pow(2, depth)];
- for (int index = 0; index < awtRgb.length; index++) {
- RGB rgb;
-
- rgb = new RGB((awtRgb[index] >> 16) & 0xFF,
- (awtRgb[index] >> 8) & 0xFF, awtRgb[index] & 0xFF);
- swtRgb[index] = rgb;
- }
- for (int index = awtRgb.length; index < swtRgb.length; index++) {
- swtRgb[index] = new RGB(0, 0, 0);
- }
- paletteHolder.set(new PaletteData(swtRgb));
- scanlinePadHolder.set(1);
- transparentPixelHolder.set(colorModel.getTransparentPixel());
- }
-
- protected void convert(BufferedImage srcImage, BufferedImage destImage) {
- ColorSpace srcColorSpace;
- ColorSpace destColorSpace;
- Map<ColorSpace, ColorConvertOp> srcMatchingConvertOps;
- ColorConvertOp matchingConvertOp;
-
- srcColorSpace = srcImage.getColorModel().getColorSpace();
- destColorSpace = destImage.getColorModel().getColorSpace();
- srcMatchingConvertOps = getConvertOps().get(srcColorSpace);
- if (srcMatchingConvertOps == null) {
- srcMatchingConvertOps = new HashMap<ColorSpace, ColorConvertOp>();
- getConvertOps().put(srcColorSpace, srcMatchingConvertOps);
- matchingConvertOp = null;
- } else {
- matchingConvertOp = srcMatchingConvertOps.get(destColorSpace);
- }
- if (matchingConvertOp == null) {
- matchingConvertOp = new ColorConvertOp(null);
- srcMatchingConvertOps.put(destColorSpace, matchingConvertOp);
- }
- matchingConvertOp.filter(srcImage, destImage);
- }
-
- protected ImageData createImageData() {
- ColorModel colorModel;
- int depth;
- IValueHolder palette;
- IValueHolder scanlinePad;
- IValueHolder transparentPixel;
- WritableRaster raster;
- byte[] bytes;
- byte[] rgbBytes;
- byte[] alphaBytes;
-
- colorModel = getBufferedImage().getColorModel();
- depth = colorModel.getPixelSize();
- if (colorModel.getTransparency() == Transparency.TRANSLUCENT) {
- depth = depth / colorModel.getNumComponents()
- * colorModel.getNumColorComponents();
- }
- palette = new ObjectValueHolder(null);
- scanlinePad = new ObjectValueHolder(0);
- transparentPixel = new ObjectValueHolder(-1);
- try {
- computeValuesFromAwtImage(depth, palette, scanlinePad,
- transparentPixel);
- raster = getBufferedImage().getRaster();
- } catch (IllegalStateException ex) {
- BufferedImage newBufferedImage;
-
- newBufferedImage = createSwtCompatibleAwtImage(getBufferedImage()
- .getWidth(), getBufferedImage().getHeight(), colorModel
- .hasAlpha());
- /*
- * this yields inexact colors but is much faster than drawing on the
- * new image
- */
- // TODO is there a way to improve this?
- convert(getBufferedImage(), newBufferedImage);
- depth = 24;
- palette.set(OsSwitch.createRgbPaletteData());
- scanlinePad.set(3);
- raster = newBufferedImage.getRaster();
- }
-
- if (raster instanceof SwtCompatibleRaster) {
- bytes = ((SwtCompatibleRaster) raster).getDataStorage();
- } else if (raster instanceof ByteInterleavedRaster) {
- // TODO this is a sun... class
- bytes = ((ByteInterleavedRaster) raster).getDataStorage();
- } else if (raster instanceof BytePackedRaster) {
- // TODO this is a sun... class
- bytes = ((BytePackedRaster) raster).getDataStorage();
- } else {
- bytes = (byte[]) raster.getDataElements(raster.getMinX(), raster
- .getMinY(), raster.getWidth(), raster.getHeight(), null);
- }
- if (((PaletteData) palette.get()).isDirect && colorModel.hasAlpha()) {
- alphaBytes = new byte[bytes.length / 4];
- rgbBytes = new byte[bytes.length / 4 * 3];
- for (int index = 0; index < alphaBytes.length; index++) {
- rgbBytes[index * 3] = bytes[index * 4];
- rgbBytes[(index * 3) + 1] = bytes[(index * 4) + 1];
- rgbBytes[(index * 3) + 2] = bytes[(index * 4) + 2];
- alphaBytes[index] = bytes[(index * 4) + 3];
- }
- } else {
- alphaBytes = null;
- rgbBytes = bytes;
- }
- imageData = new ImageData(getBufferedImage().getWidth(),
- getBufferedImage().getHeight(), depth, (PaletteData) palette
- .get(), (Integer) scanlinePad.get(), rgbBytes);
- imageData.transparentPixel = (Integer) transparentPixel.get();
- if (alphaBytes != null) {
- imageData.alphaData = alphaBytes;
- }
- return imageData;
- }
-
- public BufferedImage getBufferedImage() {
- return bufferedImage;
- }
-
- public ImageData getImageData() {
- if (imageData == null) {
- imageData = createImageData();
- }
- return imageData;
- }
-}
diff --git a/src/de/intarsys/cwt/swt/image/ImageConverterSwt2Awt.java b/src/de/intarsys/cwt/swt/image/ImageConverterSwt2Awt.java
deleted file mode 100644
index 9bfaf70..0000000
--- a/src/de/intarsys/cwt/swt/image/ImageConverterSwt2Awt.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.image;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.WritableRaster;
-
-import org.eclipse.swt.graphics.ImageData;
-
-import de.intarsys.cwt.awt.image.CwtAwtImageTools;
-
-public class ImageConverterSwt2Awt {
-
- private BufferedImage bufferedImage;
-
- private ImageData imageData;
-
- public ImageConverterSwt2Awt(ImageData imageData) {
- this.imageData = imageData;
- }
-
- protected BufferedImage createBufferedImage() {
- ColorModel colorModel;
- WritableRaster raster;
- // will only work if device independent image is standard rgb
- // TODO we also have others
- colorModel = CwtAwtImageTools.getRgbColorModel();
- raster = colorModel.createCompatibleWritableRaster(
- getImageData().width, getImageData().height);
- raster.setDataElements(0, 0, getImageData().data);
- return new BufferedImage(colorModel, raster, false, null);
- }
-
- public BufferedImage getBufferedImage() {
- if (bufferedImage == null) {
- bufferedImage = createBufferedImage();
- }
- return bufferedImage;
- }
-
- public ImageData getImageData() {
- return imageData;
- }
-}
diff --git a/src/de/intarsys/cwt/swt/image/SwtCompatibleRaster.java b/src/de/intarsys/cwt/swt/image/SwtCompatibleRaster.java
deleted file mode 100644
index d903316..0000000
--- a/src/de/intarsys/cwt/swt/image/SwtCompatibleRaster.java
+++ /dev/null
@@ -1,1336 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.cwt.swt.image;
-
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.image.ComponentSampleModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.PixelInterleavedSampleModel;
-import java.awt.image.Raster;
-import java.awt.image.RasterFormatException;
-import java.awt.image.SampleModel;
-import java.awt.image.SinglePixelPackedSampleModel;
-import java.awt.image.WritableRaster;
-
-public class SwtCompatibleRaster extends WritableRaster {
-
- /** private band offset for use by native code */
- protected int bandOffset;
-
- /** If packed == true, the SampleModel's bit masks. */
- int[] bitMasks;
-
- /** If packed == true, the SampleModel's bit offsets. */
- int[] bitOffsets;
-
- /** The image data array. */
- protected byte[] data;
-
- /** Data offsets for each band of image data. */
- protected int[] dataOffsets;
-
- /**
- * The DataBuffer offset, minus sampleModelTranslateX*pixelStride, minus
- * sampleModelTranslateY*scanlineStride, used to calculate pixel offsets.
- */
- int dbOffset;
-
- int dbOffsetPacked;
-
- /** True if the data offsets range from 0 to (pixelStride - 1) in order. */
- boolean inOrder;
-
- /** A cached copy of minX + width for use in bounds checks. */
- private int maxX;
-
- /** A cached copy of minY + height for use in bounds checks. */
- private int maxY;
-
- /** True if a SinglePixelPackedSampleModel is being used. */
- boolean packed = false;
-
- /** Pixel stride of the image data contained in this Raster. */
- protected int pixelStride;
-
- /** Scanline stride of the image data contained in this Raster. */
- protected int scanlineStride;
-
- int type;
-
- public SwtCompatibleRaster(SampleModel paramSampleModel,
- DataBuffer paramDataBuffer, Point origin) {
- this(paramSampleModel, paramDataBuffer, new Rectangle(origin.x,
- origin.y, paramSampleModel.getWidth(), paramSampleModel
- .getHeight()), origin, null);
- }
-
- public SwtCompatibleRaster(SampleModel paramSampleModel,
- DataBuffer paramDataBuffer, Rectangle aRegion, Point origin,
- WritableRaster paramParent) {
- super(paramSampleModel, paramDataBuffer, aRegion, origin, paramParent);
- this.maxX = minX + width;
- this.maxY = minY + height;
-
- if (!(dataBuffer instanceof DataBufferByte)) {
- throw new RasterFormatException("SwtCompatibleRasters must have "
- + "byte DataBuffers");
- }
-
- DataBufferByte dbb = (DataBufferByte) dataBuffer;
- this.data = dbb.getData();
-
- int xOffset = aRegion.x - origin.x;
- int yOffset = aRegion.y - origin.y;
- if (sampleModel instanceof PixelInterleavedSampleModel
- || (sampleModel instanceof ComponentSampleModel && isInterleaved((ComponentSampleModel) sampleModel))) {
- ComponentSampleModel csm = (ComponentSampleModel) sampleModel;
- this.scanlineStride = csm.getScanlineStride();
- this.pixelStride = csm.getPixelStride();
- this.dataOffsets = csm.getBandOffsets();
- for (int i = 0; i < getNumDataElements(); i++) {
- dataOffsets[i] += xOffset * pixelStride + yOffset
- * scanlineStride;
- }
- } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
- SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sampleModel;
- this.packed = true;
- this.bitMasks = sppsm.getBitMasks();
- this.bitOffsets = sppsm.getBitOffsets();
- this.scanlineStride = sppsm.getScanlineStride();
- this.pixelStride = 1;
- this.dataOffsets = new int[1];
- this.dataOffsets[0] = dbb.getOffset();
- dataOffsets[0] += xOffset * pixelStride + yOffset * scanlineStride;
- } else {
- throw new RasterFormatException(
- "SwtCompatibleRasters must "
- + "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"
- + " or interleaved ComponentSampleModel. Sample model is "
- + sampleModel);
- }
- this.bandOffset = this.dataOffsets[0];
-
- this.dbOffsetPacked = dataBuffer.getOffset() - sampleModelTranslateY
- * scanlineStride - sampleModelTranslateX * pixelStride;
- this.dbOffset = dbOffsetPacked
- - (xOffset * pixelStride + yOffset * scanlineStride);
-
- // Set inOrder to true if the data elements are in order and
- // have no gaps between them
- this.inOrder = false;
- if (numDataElements == pixelStride) {
- inOrder = true;
- for (int i = 1; i < numDataElements; i++) {
- if (dataOffsets[i] - dataOffsets[0] != i) {
- inOrder = false;
- break;
- }
- }
- }
-
- verify(false);
- }
-
- public SwtCompatibleRaster(SampleModel paramSampleModel, Point origin) {
- super(paramSampleModel, origin);
- }
-
- /**
- * Creates a subraster given a region of the raster. The x and y coordinates
- * specify the horizontal and vertical offsets from the upper-left corner of
- * this raster to the upper-left corner of the subraster. A subset of the
- * bands of the parent Raster may be specified. If this is null, then all
- * the bands are present in the subRaster. A translation to the subRaster
- * may also be specified. Note that the subraster will reference the same
- * DataBuffer as the parent raster, but using different offsets.
- *
- * @param x
- * X offset.
- * @param y
- * Y offset.
- * @param width
- * Width (in pixels) of the subraster.
- * @param height
- * Height (in pixels) of the subraster.
- * @param x0
- * Translated X origin of the subraster.
- * @param y0
- * Translated Y origin of the subraster.
- * @param bandList
- * Array of band indices.
- * @exception RasterFormatException
- * if the specified bounding box is outside of the parent
- * raster.
- */
- @Override
- public Raster createChild(int x, int y, int width, int height, int x0,
- int y0, int[] bandList) {
- return createWritableChild(x, y, width, height, x0, y0, bandList);
- }
-
- /**
- * Creates a Raster with the same layout and the same width and height, and
- * with new zeroed data arrays. If the Raster is a subRaster, this will call
- * createCompatibleRaster(width, height).
- */
- @Override
- public WritableRaster createCompatibleWritableRaster() {
- return createCompatibleWritableRaster(width, height);
- }
-
- /**
- * Creates a Raster with the same layout but using a different width and
- * height, and with new zeroed data arrays.
- */
- @Override
- public WritableRaster createCompatibleWritableRaster(int w, int h) {
- if (w <= 0 || h <= 0) {
- throw new RasterFormatException("negative "
- + ((w <= 0) ? "width" : "height"));
- }
-
- SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);
-
- return new SwtCompatibleRaster(sm, new Point(0, 0));
-
- }
-
- /**
- * Creates a Writable subRaster given a region of the Raster. The x and y
- * coordinates specify the horizontal and vertical offsets from the
- * upper-left corner of this Raster to the upper-left corner of the
- * subRaster. A subset of the bands of the parent Raster may be specified.
- * If this is null, then all the bands are present in the subRaster. A
- * translation to the subRaster may also be specified. Note that the
- * subRaster will reference the same DataBuffer as the parent Raster, but
- * using different offsets.
- *
- * @param x
- * X offset.
- * @param y
- * Y offset.
- * @param width
- * Width (in pixels) of the subraster.
- * @param height
- * Height (in pixels) of the subraster.
- * @param x0
- * Translated X origin of the subraster.
- * @param y0
- * Translated Y origin of the subraster.
- * @param bandList
- * Array of band indices.
- * @exception RasterFormatException
- * if the specified bounding box is outside of the parent
- * Raster.
- */
- @Override
- public WritableRaster createWritableChild(int x, int y, int width,
- int height, int x0, int y0, int[] bandList) {
- if (x < this.minX) {
- throw new RasterFormatException("x lies outside the raster");
- }
- if (y < this.minY) {
- throw new RasterFormatException("y lies outside the raster");
- }
- if ((x + width < x) || (x + width > this.minX + this.width)) {
- throw new RasterFormatException("(x + width) is outside of Raster");
- }
- if ((y + height < y) || (y + height > this.minY + this.height)) {
- throw new RasterFormatException("(y + height) is outside of Raster");
- }
-
- SampleModel sm;
-
- if (bandList != null)
- sm = sampleModel.createSubsetSampleModel(bandList);
- else
- sm = sampleModel;
-
- int deltaX = x0 - x;
- int deltaY = y0 - y;
-
- return new SwtCompatibleRaster(sm, dataBuffer, new Rectangle(x0, y0,
- width, height), new Point(sampleModelTranslateX + deltaX,
- sampleModelTranslateY + deltaY), this);
- }
-
- /**
- * Returns a byte array of data elements from the specified rectangular
- * region. An ArrayIndexOutOfBounds exception will be thrown at runtime if
- * the pixel coordinates are out of bounds.
- *
- * <pre>
- * byte[] bandData = raster.getByteData(x, y, w, h, null);
- * int numDataElements = raster.getnumDataElements();
- * byte[] pixel = new byte[numDataElements];
- * // To find a data element at location (x2, y2)
- * System.arraycopy(bandData, ((y2 - y) * w + (x2 - x)) * numDataElements, pixel,
- * 0, numDataElements);
- * </pre>
- *
- * @param x
- * The X coordinate of the upper left pixel location.
- * @param y
- * The Y coordinate of the upper left pixel location.
- * @param width
- * Width of the pixel rectangle.
- * @param height
- * Height of the pixel rectangle.
- * @param outData
- * If non-null, data elements for all bands at the specified
- * location are returned in this array.
- * @return Data array with data elements for all bands.
- */
- public byte[] getByteData(int x, int y, int w, int h, byte[] outData) {
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- if (outData == null) {
- outData = new byte[numDataElements * w * h];
- }
- int yoff = (y - minY) * scanlineStride + (x - minX) * pixelStride;
- int xoff;
- int off = 0;
- int xstart;
- int ystart;
-
- if (inOrder) {
- yoff += dataOffsets[0];
- int rowBytes = w * pixelStride;
- if (scanlineStride == rowBytes) {
- System.arraycopy(data, yoff, outData, off, rowBytes * h);
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- System.arraycopy(data, yoff, outData, off, rowBytes);
- off += rowBytes;
- }
- }
- } else if (numDataElements == 1) {
- yoff += dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- outData[off++] = data[xoff];
- }
- }
- } else if (numDataElements == 2) {
- yoff += dataOffsets[0];
- int d1 = dataOffsets[1] - dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- outData[off++] = data[xoff];
- outData[off++] = data[xoff + d1];
- }
- }
- } else if (numDataElements == 3) {
- yoff += dataOffsets[0];
- int d1 = dataOffsets[1] - dataOffsets[0];
- int d2 = dataOffsets[2] - dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- outData[off++] = data[xoff];
- outData[off++] = data[xoff + d1];
- outData[off++] = data[xoff + d2];
- }
- }
- } else if (numDataElements == 4) {
- yoff += dataOffsets[0];
- int d1 = dataOffsets[1] - dataOffsets[0];
- int d2 = dataOffsets[2] - dataOffsets[0];
- int d3 = dataOffsets[3] - dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- outData[off++] = data[xoff];
- outData[off++] = data[xoff + d1];
- outData[off++] = data[xoff + d2];
- outData[off++] = data[xoff + d3];
- }
- }
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- for (int c = 0; c < numDataElements; c++) {
- outData[off++] = data[dataOffsets[c] + xoff];
- }
- }
- }
- }
-
- return outData;
- }
-
- /**
- * Returns a byte array of data elements from the specified rectangular
- * region for the specified band. An ArrayIndexOutOfBounds exception will be
- * thrown at runtime if the pixel coordinates are out of bounds.
- *
- * <pre>
- * byte[] bandData = raster.getByteData(x, y, w, h, null);
- *
- * // To find the data element at location (x2, y2)
- * byte bandElement = bandData[((y2 - y) * w + (x2 - x))];
- * </pre>
- *
- * @param x
- * The X coordinate of the upper left pixel location.
- * @param y
- * The Y coordinate of the upper left pixel location.
- * @param width
- * Width of the pixel rectangle.
- * @param height
- * Height of the pixel rectangle.
- * @param band
- * The band to return.
- * @param outData
- * If non-null, data elements for all bands at the specified
- * location are returned in this array.
- * @return Data array with data elements for all bands.
- */
- public byte[] getByteData(int x, int y, int w, int h, int band,
- byte[] outData) {
- // Bounds check for 'band' will be performed automatically
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- if (outData == null) {
- outData = new byte[w * h];
- }
- int yoff = (y - minY) * scanlineStride + (x - minX) * pixelStride
- + dataOffsets[band];
- int xoff;
- int off = 0;
- int xstart;
- int ystart;
-
- if (pixelStride == 1) {
- if (scanlineStride == w) {
- System.arraycopy(data, yoff, outData, 0, w * h);
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- System.arraycopy(data, yoff, outData, off, w);
- off += w;
- }
- }
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- outData[off++] = data[xoff];
- }
- }
- }
-
- return outData;
- }
-
- /**
- * Returns an array of data elements from the specified rectangular region.
- * An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel
- * coordinates are out of bounds. A ClassCastException will be thrown if the
- * input object is non null and references anything other than an array of
- * transferType.
- *
- * <pre>
- * byte[] bandData = (byte[]) raster.getDataElements(x, y, w, h, null);
- * int numDataElements = raster.getNumDataElements();
- * byte[] pixel = new byte[numDataElements];
- * // To find a data element at location (x2, y2)
- * System.arraycopy(bandData, ((y2 - y) * w + (x2 - x)) * numDataElements, pixel,
- * 0, numDataElements);
- * </pre>
- *
- * @param x
- * The X coordinate of the upper left pixel location.
- * @param y
- * The Y coordinate of the upper left pixel location.
- * @param width
- * Width of the pixel rectangle.
- * @param height
- * Height of the pixel rectangle.
- * @param outData
- * An object reference to an array of type defined by
- * getTransferType() and length w*h*getNumDataElements(). If null
- * an array of appropriate type and size will be allocated.
- * @return An object reference to an array of type defined by
- * getTransferType() with the request pixel data.
- */
- @Override
- public Object getDataElements(int x, int y, int w, int h, Object obj) {
- return getByteData(x, y, w, h, (byte[]) obj);
- }
-
- /**
- * Returns the data elements for all bands at the specified location. An
- * ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel
- * coordinate is out of bounds. A ClassCastException will be thrown if the
- * input object is non null and references anything other than an array of
- * transferType.
- *
- * @param actualX
- * The X coordinate of the pixel location.
- * @param actualY
- * The Y coordinate of the pixel location.
- * @param outData
- * An object reference to an array of type defined by
- * getTransferType() and length getNumDataElements(). If null an
- * array of appropriate type and size will be allocated.
- * @return An object reference to an array of type defined by
- * getTransferType() with the request pixel data.
- */
- @Override
- public Object getDataElements(int actualX, int actualY, Object obj) {
- byte outData[];
- if (obj == null) {
- outData = new byte[numDataElements];
- } else {
- outData = (byte[]) obj;
- }
- if ((actualX < this.minX) || (actualY < this.minY)
- || (actualX >= this.maxX) || (actualY >= this.maxY)) {
- for (int band = 0; band < numDataElements; band++) {
- outData[band] = 0;
- }
- return outData;
- }
- int off = (actualY - minY) * scanlineStride + (actualX - minX)
- * pixelStride;
-
- for (int band = 0; band < numDataElements; band++) {
- outData[band] = data[dataOffsets[band] + off];
- }
-
- return outData;
- }
-
- /**
- * Returns the data offset for the specified band. The data offset is the
- * index into the data array in which the first sample of the first scanline
- * is stored.
- *
- * @param band
- * The band whose offset is returned.
- */
- public int getDataOffset(int band) {
- return dataOffsets[band];
- }
-
- /**
- * Returns a copy of the data offsets array. For each band the data offset
- * is the index into the band's data array, of the first sample of the band.
- */
- public int[] getDataOffsets() {
- return dataOffsets.clone();
- }
-
- /**
- * Returns a reference to the data array.
- */
- public byte[] getDataStorage() {
- return data;
- }
-
- @Override
- public int[] getPixels(int x, int y, int w, int h, int[] iArray) {
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- int pixels[];
- if (iArray != null) {
- pixels = iArray;
- } else {
- pixels = new int[w * h * numBands];
- }
-
- int lineOffset = y * scanlineStride + x * pixelStride;
- int dstOffset = 0;
-
- if (packed) {
- lineOffset += dbOffsetPacked;
- for (int j = 0; j < h; j++) {
- for (int i = 0; i < w; i++) {
- int value = data[lineOffset + i];
- for (int k = 0; k < numBands; k++) {
- pixels[dstOffset++] = (value & bitMasks[k]) >>> bitOffsets[k];
- }
- }
- lineOffset += scanlineStride;
- }
- } else {
- lineOffset += dbOffset;
- int d0 = dataOffsets[0];
-
- if (numBands == 1) {
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- pixels[dstOffset++] = data[pixelOffset] & 0xff;
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else if (numBands == 2) {
- int d1 = dataOffsets[1] - d0;
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- pixels[dstOffset++] = data[pixelOffset] & 0xff;
- pixels[dstOffset++] = data[pixelOffset + d1] & 0xff;
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else if (numBands == 3) {
- int d1 = dataOffsets[1] - d0;
- int d2 = dataOffsets[2] - d0;
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- pixels[dstOffset++] = data[pixelOffset] & 0xff;
- pixels[dstOffset++] = data[pixelOffset + d1] & 0xff;
- pixels[dstOffset++] = data[pixelOffset + d2] & 0xff;
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else if (numBands == 4) {
- int d1 = dataOffsets[1] - d0;
- int d2 = dataOffsets[2] - d0;
- int d3 = dataOffsets[3] - d0;
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- pixels[dstOffset++] = data[pixelOffset] & 0xff;
- pixels[dstOffset++] = data[pixelOffset + d1] & 0xff;
- pixels[dstOffset++] = data[pixelOffset + d2] & 0xff;
- pixels[dstOffset++] = data[pixelOffset + d3] & 0xff;
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else {
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset;
- for (int i = 0; i < w; i++) {
- for (int k = 0; k < numBands; k++) {
- pixels[dstOffset++] = data[pixelOffset
- + dataOffsets[k]] & 0xff;
- }
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- }
- }
-
- return pixels;
- }
-
- /**
- * Returns pixel stride -- the number of data array elements between two
- * samples for the same band on the same scanline.
- */
- public int getPixelStride() {
- return pixelStride;
- }
-
- @Override
- public int getSample(int x, int y, int b) {
- if ((x < this.minX) || (y < this.minY) || (x >= this.maxX)
- || (y >= this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- if (packed) {
- int offset = y * scanlineStride + x + dbOffsetPacked;
- byte sample = data[offset];
- return (sample & bitMasks[b]) >>> bitOffsets[b];
- } else {
- int offset = y * scanlineStride + x * pixelStride + dbOffset;
- return data[offset + dataOffsets[b]] & 0xff;
- }
- }
-
- @Override
- public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray) {
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- int samples[];
- if (iArray != null) {
- samples = iArray;
- } else {
- samples = new int[w * h];
- }
-
- int lineOffset = y * scanlineStride + x * pixelStride;
- int dstOffset = 0;
-
- if (packed) {
- lineOffset += dbOffsetPacked;
- int bitMask = bitMasks[b];
- int bitOffset = bitOffsets[b];
-
- for (int j = 0; j < h; j++) {
- int sampleOffset = lineOffset;
- for (int i = 0; i < w; i++) {
- int value = data[sampleOffset++];
- samples[dstOffset++] = ((value & bitMask) >>> bitOffset);
- }
- lineOffset += scanlineStride;
- }
- } else {
- lineOffset += dbOffset + dataOffsets[b];
- for (int j = 0; j < h; j++) {
- int sampleOffset = lineOffset;
- for (int i = 0; i < w; i++) {
- samples[dstOffset++] = data[sampleOffset] & 0xff;
- sampleOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- }
-
- return samples;
- }
-
- /**
- * Returns the scanline stride -- the number of data array elements between
- * a given sample and the sample in the same column of the next row in the
- * same band.
- */
- public int getScanlineStride() {
- return scanlineStride;
- }
-
- /**
- * * Analyzes a ComponentSampleModel to determine if it can function as a
- * PixelInterleavedSampleModel. In order to do so, it must use only bank 0
- * of its DataBuffer, and the data offsets must span a range of less than
- * pixelStride.
- *
- * <p>
- * These properties are trivially true for a 1-banded SampleModel.
- */
- private boolean isInterleaved(ComponentSampleModel sm) {
- // Analyze ComponentSampleModel to determine if it has the
- // properties of a PixelInterleavedSampleModel
-
- int numBands = sampleModel.getNumBands();
- if (numBands == 1) {
- return true;
- }
-
- // Determine banks used
- int[] bankIndices = sm.getBankIndices();
- for (int i = 0; i < numBands; i++) {
- if (bankIndices[i] != 0) {
- return false;
- }
- }
-
- // Determine range of band offsets
- int[] bandOffsets = sm.getBandOffsets();
- int minOffset = bandOffsets[0];
- int maxOffset = minOffset;
- for (int i = 1; i < numBands; i++) {
- int offset = bandOffsets[i];
- if (offset < minOffset) {
- minOffset = offset;
- }
- if (offset > maxOffset) {
- maxOffset = offset;
- }
- }
- if (maxOffset - minOffset >= sm.getPixelStride()) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Stores a byte array of data elements into the specified rectangular
- * region. An ArrayIndexOutOfBounds exception will be thrown at runtime if
- * the pixel coordinates are out of bounds. The data elements in the data
- * array are assumed to be packed. That is, a data element for the nth band
- * at location (x2, y2) would be found at:
- *
- * <pre>
- * inData[((y2 - y) * w + (x2 - x)) * numDataElements + n]
- * </pre>
- *
- * @param x
- * The X coordinate of the upper left pixel location.
- * @param y
- * The Y coordinate of the upper left pixel location.
- * @param w
- * Width of the pixel rectangle.
- * @param h
- * Height of the pixel rectangle.
- * @param inData
- * The data elements to be stored.
- */
- public void putByteData(int x, int y, int w, int h, byte[] inData) {
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- int yoff = (y - minY) * scanlineStride + (x - minX) * pixelStride;
-
- int xoff;
- int off = 0;
- int xstart;
- int ystart;
-
- if (inOrder) {
- yoff += dataOffsets[0];
- int rowBytes = w * pixelStride;
- if (rowBytes == scanlineStride) {
- System.arraycopy(inData, 0, data, yoff, rowBytes * h);
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- System.arraycopy(inData, off, data, yoff, rowBytes);
- off += rowBytes;
- }
- }
- } else if (numDataElements == 1) {
- yoff += dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- data[xoff] = inData[off++];
- }
- }
- } else if (numDataElements == 2) {
- yoff += dataOffsets[0];
- int d1 = dataOffsets[1] - dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- data[xoff] = inData[off++];
- data[xoff + d1] = inData[off++];
- }
- }
- } else if (numDataElements == 3) {
- yoff += dataOffsets[0];
- int d1 = dataOffsets[1] - dataOffsets[0];
- int d2 = dataOffsets[2] - dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- data[xoff] = inData[off++];
- data[xoff + d1] = inData[off++];
- data[xoff + d2] = inData[off++];
- }
- }
- } else if (numDataElements == 4) {
- yoff += dataOffsets[0];
- int d1 = dataOffsets[1] - dataOffsets[0];
- int d2 = dataOffsets[2] - dataOffsets[0];
- int d3 = dataOffsets[3] - dataOffsets[0];
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- data[xoff] = inData[off++];
- data[xoff + d1] = inData[off++];
- data[xoff + d2] = inData[off++];
- data[xoff + d3] = inData[off++];
- }
- }
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- for (int c = 0; c < numDataElements; c++) {
- data[dataOffsets[c] + xoff] = inData[off++];
- }
- }
- }
- }
- }
-
- /**
- * Stores a byte array of data elements into the specified rectangular
- * region for the specified band. An ArrayIndexOutOfBounds exception will be
- * thrown at runtime if the pixel coordinates are out of bounds. The data
- * elements in the data array are assumed to be packed. That is, a data
- * element at location (x2, y2) would be found at:
- *
- * <pre>
- * inData[((y2 - y) * w + (x2 - x)) + n]
- * </pre>
- *
- * @param x
- * The X coordinate of the upper left pixel location.
- * @param y
- * The Y coordinate of the upper left pixel location.
- * @param w
- * Width of the pixel rectangle.
- * @param h
- * Height of the pixel rectangle.
- * @param band
- * The band to set.
- * @param inData
- * The data elements to be stored.
- */
- public void putByteData(int x, int y, int w, int h, int band, byte[] inData) {
- // Bounds check for 'band' will be performed automatically
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- int yoff = (y - minY) * scanlineStride + (x - minX) * pixelStride
- + dataOffsets[band];
- int xoff;
- int off = 0;
- int xstart;
- int ystart;
-
- if (pixelStride == 1) {
- if (scanlineStride == w) {
- System.arraycopy(inData, 0, data, yoff, w * h);
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- System.arraycopy(inData, off, data, yoff, w);
- off += w;
- }
- }
- } else {
- for (ystart = 0; ystart < h; ystart++, yoff += scanlineStride) {
- xoff = yoff;
- for (xstart = 0; xstart < w; xstart++, xoff += pixelStride) {
- data[xoff] = inData[off++];
- }
- }
- }
- }
-
- /**
- * Stores the Raster data at the specified location.
- *
- * @param dstX
- * The absolute X coordinate of the destination pixel that will
- * receive a copy of the upper-left pixel of the inRaster
- * @param dstY
- * The absolute Y coordinate of the destination pixel that will
- * receive a copy of the upper-left pixel of the inRaster
- * @param srcX
- * The absolute X coordinate of the upper-left source pixel that
- * will be copied into this Raster
- * @param srcY
- * The absolute Y coordinate of the upper-left source pixel that
- * will be copied into this Raster
- * @param width
- * The number of pixels to store horizontally
- * @param height
- * The number of pixels to store vertically
- * @param inRaster
- * Raster of data to place at x,y location.
- */
- private void setDataElements(int dstX, int dstY, int srcX, int srcY,
- int width, int height, Raster inRaster) {
- // Assume bounds checking has been performed previously
- if (width <= 0 || height <= 0) {
- return;
- }
-
- // Write inRaster (minX, minY) to (dstX, dstY)
-
- int srcOffX = inRaster.getMinX();
- int srcOffY = inRaster.getMinY();
- Object tdata = null;
-
- if (inRaster instanceof SwtCompatibleRaster) {
- SwtCompatibleRaster bct = (SwtCompatibleRaster) inRaster;
- byte[] bdata = bct.getDataStorage();
- // copy whole scanlines
- if (inOrder && bct.inOrder && pixelStride == bct.pixelStride) {
- int toff = bct.getDataOffset(0);
- int tss = bct.getScanlineStride();
- int tps = bct.getPixelStride();
-
- int srcOffset = toff + (srcY - srcOffY) * tss
- + (srcX - srcOffX) * tps;
- int dstOffset = dataOffsets[0] + (dstY - minY) * scanlineStride
- + (dstX - minX) * pixelStride;
-
- int nbytes = width * pixelStride;
- for (int tmpY = 0; tmpY < height; tmpY++) {
- System.arraycopy(bdata, srcOffset, data, dstOffset, nbytes);
- srcOffset += tss;
- dstOffset += scanlineStride;
- }
- return;
- }
- }
-
- for (int startY = 0; startY < height; startY++) {
- // Grab one scanline at a time
- tdata = inRaster.getDataElements(srcOffX, srcOffY + startY, width,
- 1, tdata);
- setDataElements(dstX, dstY + startY, width, 1, tdata);
- }
-
- }
-
- /**
- * Stores an array of data elements into the specified rectangular region.
- * An ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel
- * coordinates are out of bounds. A ClassCastException will be thrown if the
- * input object is non null and references anything other than an array of
- * transferType. The data elements in the data array are assumed to be
- * packed. That is, a data element for the nth band at location (x2, y2)
- * would be found at:
- *
- * <pre>
- * inData[((y2 - y) * w + (x2 - x)) * numDataElements + n]
- * </pre>
- *
- * @param x
- * The X coordinate of the upper left pixel location.
- * @param y
- * The Y coordinate of the upper left pixel location.
- * @param w
- * Width of the pixel rectangle.
- * @param h
- * Height of the pixel rectangle.
- * @param inData
- * An object reference to an array of type defined by
- * getTransferType() and length w*h*getNumDataElements()
- * containing the pixel data to place between x,y and x+h, y+h.
- */
- @Override
- public void setDataElements(int x, int y, int w, int h, Object obj) {
- putByteData(x, y, w, h, (byte[]) obj);
- }
-
- /**
- * Stores the data elements for all bands at the specified location. An
- * ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel
- * coordinate is out of bounds. A ClassCastException will be thrown if the
- * input object is non null and references anything other than an array of
- * transferType.
- *
- * @param x
- * The X coordinate of the pixel location.
- * @param y
- * The Y coordinate of the pixel location.
- * @param inData
- * An object reference to an array of type defined by
- * getTransferType() and length getNumDataElements() containing
- * the pixel data to place at x,y.
- */
- @Override
- public void setDataElements(int x, int y, Object obj) {
- if ((x < this.minX) || (y < this.minY) || (x >= this.maxX)
- || (y >= this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- byte inData[] = (byte[]) obj;
- int off = (y - minY) * scanlineStride + (x - minX) * pixelStride;
-
- for (int i = 0; i < numDataElements; i++) {
- data[dataOffsets[i] + off] = inData[i];
- }
-
- }
-
- /**
- * Stores the Raster data at the specified location. An
- * ArrayIndexOutOfBounds exception will be thrown at runtime if the pixel
- * coordinates are out of bounds.
- *
- * @param x
- * The X coordinate of the pixel location.
- * @param y
- * The Y coordinate of the pixel location.
- * @param inRaster
- * Raster of data to place at x,y location.
- */
- @Override
- public void setDataElements(int x, int y, Raster inRaster) {
- int srcOffX = inRaster.getMinX();
- int srcOffY = inRaster.getMinY();
- int dstOffX = x + srcOffX;
- int dstOffY = y + srcOffY;
- int width = inRaster.getWidth();
- int height = inRaster.getHeight();
- if ((dstOffX < this.minX) || (dstOffY < this.minY)
- || (dstOffX + width > this.maxX)
- || (dstOffY + height > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
-
- setDataElements(dstOffX, dstOffY, srcOffX, srcOffY, width, height,
- inRaster);
- }
-
- @Override
- public void setPixels(int x, int y, int w, int h, int[] iArray) {
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- int lineOffset = y * scanlineStride + x * pixelStride;
- int srcOffset = 0;
-
- if (packed) {
- lineOffset += dbOffsetPacked;
- for (int j = 0; j < h; j++) {
- for (int i = 0; i < w; i++) {
- int value = 0;
- for (int k = 0; k < numBands; k++) {
- int srcValue = iArray[srcOffset++];
- value |= ((srcValue << bitOffsets[k]) & bitMasks[k]);
- }
- data[lineOffset + i] = (byte) value;
- }
- lineOffset += scanlineStride;
- }
- } else {
- lineOffset += dbOffset;
- int d0 = dataOffsets[0];
-
- if (numBands == 1) {
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- data[pixelOffset] = (byte) iArray[srcOffset++];
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else if (numBands == 2) {
- int d1 = dataOffsets[1] - d0;
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- data[pixelOffset] = (byte) iArray[srcOffset++];
- data[pixelOffset + d1] = (byte) iArray[srcOffset++];
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else if (numBands == 3) {
- int d1 = dataOffsets[1] - d0;
- int d2 = dataOffsets[2] - d0;
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- data[pixelOffset] = (byte) iArray[srcOffset++];
- data[pixelOffset + d1] = (byte) iArray[srcOffset++];
- data[pixelOffset + d2] = (byte) iArray[srcOffset++];
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else if (numBands == 4) {
- int d1 = dataOffsets[1] - d0;
- int d2 = dataOffsets[2] - d0;
- int d3 = dataOffsets[3] - d0;
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset + d0;
- for (int i = 0; i < w; i++) {
- data[pixelOffset] = (byte) iArray[srcOffset++];
- data[pixelOffset + d1] = (byte) iArray[srcOffset++];
- data[pixelOffset + d2] = (byte) iArray[srcOffset++];
- data[pixelOffset + d3] = (byte) iArray[srcOffset++];
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- } else {
- for (int j = 0; j < h; j++) {
- int pixelOffset = lineOffset;
- for (int i = 0; i < w; i++) {
- for (int k = 0; k < numBands; k++) {
- data[pixelOffset + dataOffsets[k]] = (byte) iArray[srcOffset++];
- }
- pixelOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- }
- }
-
- }
-
- @Override
- public void setRect(int dx, int dy, Raster srcRaster) {
- if (!(srcRaster instanceof SwtCompatibleRaster)) {
- super.setRect(dx, dy, srcRaster);
- return;
- }
-
- int width = srcRaster.getWidth();
- int height = srcRaster.getHeight();
- int srcOffX = srcRaster.getMinX();
- int srcOffY = srcRaster.getMinY();
- int dstOffX = dx + srcOffX;
- int dstOffY = dy + srcOffY;
-
- // Clip to this raster
- if (dstOffX < this.minX) {
- int skipX = minX - dstOffX;
- width -= skipX;
- srcOffX += skipX;
- dstOffX = this.minX;
- }
- if (dstOffY < this.minY) {
- int skipY = this.minY - dstOffY;
- height -= skipY;
- srcOffY += skipY;
- dstOffY = this.minY;
- }
- if (dstOffX + width > this.maxX) {
- width = this.maxX - dstOffX;
- }
- if (dstOffY + height > this.maxY) {
- height = this.maxY - dstOffY;
- }
-
- setDataElements(dstOffX, dstOffY, srcOffX, srcOffY, width, height,
- srcRaster);
- }
-
- @Override
- public void setSample(int x, int y, int b, int s) {
- if ((x < this.minX) || (y < this.minY) || (x >= this.maxX)
- || (y >= this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- if (packed) {
- int offset = y * scanlineStride + x + dbOffsetPacked;
- int bitMask = bitMasks[b];
-
- byte value = data[offset];
- value &= ~bitMask;
- value |= (s << bitOffsets[b]) & bitMask;
- data[offset] = value;
- } else {
- int offset = y * scanlineStride + x * pixelStride + dbOffset;
- data[offset + dataOffsets[b]] = (byte) s;
- }
- }
-
- @Override
- public void setSamples(int x, int y, int w, int h, int b, int iArray[]) {
- if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX)
- || (y + h > this.maxY)) {
- throw new ArrayIndexOutOfBoundsException(
- "Coordinate out of bounds!");
- }
- int lineOffset = y * scanlineStride + x * pixelStride;
- int srcOffset = 0;
-
- if (packed) {
- lineOffset += dbOffsetPacked;
- int bitMask = bitMasks[b];
-
- for (int j = 0; j < h; j++) {
- int sampleOffset = lineOffset;
- for (int i = 0; i < w; i++) {
- byte value = data[sampleOffset];
- value &= ~bitMask;
- int sample = iArray[srcOffset++];
- value |= (sample << bitOffsets[b]) & bitMask;
- data[sampleOffset++] = value;
- }
- lineOffset += scanlineStride;
- }
- } else {
- lineOffset += dbOffset + dataOffsets[b];
- for (int i = 0; i < h; i++) {
- int sampleOffset = lineOffset;
- for (int j = 0; j < w; j++) {
- data[sampleOffset] = (byte) iArray[srcOffset++];
- sampleOffset += pixelStride;
- }
- lineOffset += scanlineStride;
- }
- }
- }
-
- @Override
- public String toString() {
- return new String("SwtCompatibleRaster: width = " + width
- + " height = " + height + " #numDataElements "
- + numDataElements
- // +" xOff = "+xOffset+" yOff = "+yOffset
- + " dataOff[0] = " + dataOffsets[0]);
- }
-
- /**
- * Verify that the layout parameters are consistent with the data. If
- * strictCheck is false, this method will check for ArrayIndexOutOfBounds
- * conditions. If strictCheck is true, this method will check for additional
- * error conditions such as line wraparound (width of a line greater than
- * the scanline stride).
- *
- * @return String Error string, if the layout is incompatible with the data.
- * Otherwise returns null.
- */
- private void verify(boolean strictCheck) {
- int maxSize = 0;
- int size;
-
- for (int i = 0; i < numDataElements; i++) {
- size = (height - 1) * scanlineStride + (width - 1) * pixelStride
- + dataOffsets[i];
- if (size > maxSize) {
- maxSize = size;
- }
- }
- if (data.length < maxSize) {
- throw new RasterFormatException("Data array too small (should be "
- + maxSize + " )");
- }
- }
-}
diff --git a/src/de/intarsys/nativec/api/CLong.java b/src/de/intarsys/nativec/api/CLong.java
new file mode 100644
index 0000000..1ce4352
--- /dev/null
+++ b/src/de/intarsys/nativec/api/CLong.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.api;
+
+/**
+ * A plain Java object representing a platform long. In contrast to the fixed 8
+ * byte Java primitive type the platform long may vary in size, depending on
+ * operating system and processor architecture.
+ *
+ */
+public class CLong extends Number {
+
+ private Number value;
+
+ public CLong(long pValue) {
+ value = pValue;
+ }
+
+ @Override
+ public double doubleValue() {
+ return value.doubleValue();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof CLong) {
+ return value.equals(((CLong) obj).value);
+ }
+ return false;
+ }
+
+ @Override
+ public float floatValue() {
+ return value.floatValue();
+ }
+
+ @Override
+ public int hashCode() {
+ return value.hashCode();
+ }
+
+ @Override
+ public int intValue() {
+ return value.intValue();
+ }
+
+ @Override
+ public long longValue() {
+ return value.longValue();
+ }
+
+}
diff --git a/src/de/intarsys/cwt/font/truetype/TrueTypeException.java b/src/de/intarsys/nativec/api/CWideString.java
index ff5a22a..38ce544 100644
--- a/src/de/intarsys/cwt/font/truetype/TrueTypeException.java
+++ b/src/de/intarsys/nativec/api/CWideString.java
@@ -27,27 +27,26 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font.truetype;
+package de.intarsys.nativec.api;
/**
+ * Wrapper class to indicate use of a "wide" string on native side.
+ * <p>
+ * Use this to indicate on a native call parameter or return type that you will
+ * deal with the platforms wide string capabilities.
*
*/
-public class TrueTypeException extends Exception {
+final public class CWideString {
- public TrueTypeException() {
- super();
- }
+ private final String string;
- public TrueTypeException(String message) {
- super(message);
- }
-
- public TrueTypeException(String message, Throwable cause) {
- super(message, cause);
+ public CWideString(String string) {
+ super();
+ this.string = string;
}
- public TrueTypeException(Throwable cause) {
- super(cause);
+ public String getString() {
+ return string;
}
}
diff --git a/src/de/intarsys/cwt/image/IImageEntry.java b/src/de/intarsys/nativec/api/ICallback.java
index 90d8fc4..841c506 100644
--- a/src/de/intarsys/cwt/image/IImageEntry.java
+++ b/src/de/intarsys/nativec/api/ICallback.java
@@ -27,14 +27,14 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.image;
+package de.intarsys.nativec.api;
-import de.intarsys.tools.attribute.IAttributeSupport;
+public interface ICallback {
-public interface IImageEntry extends IImage, IAttributeSupport {
+ public Class<?>[] getParameterTypes();
- public IImageContainer getContainer();
+ public Class<?> getReturnType();
- public int getIndex();
+ public Object invoke(Object[] objects);
}
diff --git a/src/de/intarsys/cwt/common/IShape.java b/src/de/intarsys/nativec/api/INativeCallback.java
index 7cb3aaa..a490103 100644
--- a/src/de/intarsys/cwt/common/IShape.java
+++ b/src/de/intarsys/nativec/api/INativeCallback.java
@@ -27,10 +27,8 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.common;
-
-import java.awt.Shape;
-
-public interface IShape extends IGraphicsObject, Shape {
+package de.intarsys.nativec.api;
+public interface INativeCallback {
+ // no methods
}
diff --git a/src/de/intarsys/cwt/font/IFontProgram.java b/src/de/intarsys/nativec/api/INativeFunction.java
index c59d1e2..085275d 100644
--- a/src/de/intarsys/cwt/font/IFontProgram.java
+++ b/src/de/intarsys/nativec/api/INativeFunction.java
@@ -27,20 +27,21 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font;
-
-import de.intarsys.tools.locator.ILocatorSupport;
+package de.intarsys.nativec.api;
/**
- * An abstraction of the font program.
- *
+ * The representation of a native function.
*/
-public interface IFontProgram extends ILocatorSupport {
+public interface INativeFunction {
/**
- * The {@link IFont} implemented by this program.
+ * Invoke the native function.
*
- * @return The {@link IFont} implemented by this program.
+ * @param returnType
+ * The expected return type.
+ * @param objects
+ * The arguments to the function
+ * @return The result of executing the function
*/
- public IFont getFont();
+ public <T> T invoke(Class<T> returnType, Object... objects);
}
diff --git a/src/de/intarsys/nativec/api/INativeHandle.java b/src/de/intarsys/nativec/api/INativeHandle.java
new file mode 100644
index 0000000..7dc3ecd
--- /dev/null
+++ b/src/de/intarsys/nativec/api/INativeHandle.java
@@ -0,0 +1,271 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.api;
+
+/**
+ * A "handle" to a piece of memory (in c space).
+ * <p>
+ * The handle combines an address and a memory chunk of a specified size.
+ */
+public interface INativeHandle {
+
+ /**
+ * The start address of the memory chunk
+ *
+ * @return The start address of the memory chunk
+ */
+ public long getAddress();
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to a byte.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return A byte marshaled from the memory chunk
+ */
+ public byte getByte(int index);
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to a byte array of length <code>count</code>.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param count
+ * The size of the byte array
+ * @return A byte array marshaled from the memory chunk
+ */
+ public byte[] getByteArray(int index, int count);
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to a long. Get only the "platform" number of bytes.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return A long marshaled from the memory chunk
+ */
+ public long getCLong(int index);
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to an int.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return An int marshaled from the memory chunk
+ */
+ public int getInt(int index);
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to a long value (which is always 8 byte).
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return A long marshaled from the memory chunk
+ */
+ public long getLong(int index);
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to an {@link INativeHandle}.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return An {@link INativeHandle} marshaled from the memory chunk
+ */
+ public INativeHandle getNativeHandle(int index);
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to a short.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return A short marshaled from the memory chunk
+ */
+ public short getShort(int index);
+
+ /**
+ * The size for the handle in bytes.
+ * <p>
+ * You can not access bytes from outside the range defined by getAdddress +
+ * size.
+ *
+ */
+ public int getSize();
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to a String.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return A String marshaled from the memory chunk
+ */
+ public String getString(int index);
+
+ /**
+ * Marshal the data at byte offset <code>index</code> from the start of the
+ * memory chunk to a String using the platform wide character conversion.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @return A String marshaled from the memory chunk
+ */
+ public String getWideString(int index);
+
+ /**
+ * Create a new {@link INativeHandle}, offset from this by
+ * <code>offset</code> bytes.
+ *
+ * @param offset
+ * The byte offset from the start of the memory chunk
+ * @return A new {@link INativeHandle} pointing to "getAddress() + offset".
+ */
+ public INativeHandle offset(int offset);
+
+ /**
+ * Write a byte to the memory at byte offset <code>index</code> from the
+ * start of the memory chunk.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setByte(int index, byte value);
+
+ /**
+ * Write a byte array to the memory at byte offset <code>index</code> from
+ * the start of the memory chunk. The method will write
+ * <code>valueCount</code> bytes from <code>value</code> starting at
+ * <code>valueOffset</code>.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setByteArray(int index, byte[] value, int valueOffset,
+ int valueCount);
+
+ /**
+ * Write a long to the memory at byte offset <code>index</code> from the
+ * start of the memory chunk. Write only the "platform" number of bytes. The
+ * caller is responsible for observing the value range.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setCLong(int index, long value);
+
+ /**
+ * Write an int to the memory at byte offset <code>index</code> from the
+ * start of the memory chunk.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setInt(int index, int value);
+
+ /**
+ * Write a long to the memory at byte offset <code>index</code> from the
+ * start of the memory chunk.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setLong(int index, long value);
+
+ /**
+ * Write an {@link INativeHandle} to the memory at byte offset
+ * <code>index</code> from the start of the memory chunk.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setNativeHandle(int index, INativeHandle valueHandle);
+
+ /**
+ * Write a short to the memory at byte offset <code>index</code> from the
+ * start of the memory chunk.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setShort(int index, short value);
+
+ /**
+ * Set the valid size for the handle to <code>count</code> bytes.
+ * <p>
+ * You can not access bytes from outside the range defined by getAdddress +
+ * size.
+ *
+ * @param count
+ * The size of the memory managed by the {@link INativeHandle}
+ */
+ public void setSize(int count);
+
+ /**
+ * Write a String to the memory at byte offset <code>index</code>from the
+ * start of the memory chunk.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setString(int index, String value);
+
+ /**
+ * Write a String to the memory at byte offset <code>index</code>from the
+ * start of the memory chunk using the platform wide character conversion.
+ *
+ * @param index
+ * The byte offset from the start of the memory chunk
+ * @param value
+ * The value to write.
+ */
+ public void setWideString(int index, String value);
+
+}
diff --git a/src/de/intarsys/nativec/api/INativeInterface.java b/src/de/intarsys/nativec/api/INativeInterface.java
new file mode 100644
index 0000000..8a78a44
--- /dev/null
+++ b/src/de/intarsys/nativec/api/INativeInterface.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.api;
+
+
+/**
+ * The abstraction of a generic interface to c native code.
+ */
+public interface INativeInterface {
+
+ /**
+ * Add a directory to the search path.
+ *
+ * @param path
+ * The path to be added;
+ */
+ public void addSearchPath(String path);
+
+ /**
+ * Allocate c memory and return the respective {@link INativeHandle}.
+ *
+ * @param size
+ * The size in bytes.
+ * @return The new allocated {@link INativeHandle}
+ */
+ public INativeHandle allocate(int size);
+
+ public INativeCallback createCallback(ICallback callback);
+
+ /**
+ * Create an {@link INativeFunction} from a function pointer.
+ * <p>
+ * There is no special handling for the 0 address!
+ *
+ * @param address
+ * The function pointer.
+ * @return The function object.
+ */
+ public INativeFunction createFunction(long address);
+
+ /**
+ * Create a void {@link INativeHandle} to a memory address.
+ * <p>
+ * There is no special handling for the 0 address!
+ *
+ * @param address
+ * The memory address.
+ * @return The handle to the memory address.
+ */
+ public INativeHandle createHandle(long address);
+
+ /**
+ * Load a new {@link INativeLibrary}.
+ *
+ * @param name
+ * The name of the library to load.
+ * @return The new {@link INativeLibrary}
+ */
+ public INativeLibrary createLibrary(String name);
+
+ /**
+ * The platform long size.
+ *
+ * @return The platform long size.
+ */
+ public int longSize();
+
+ /**
+ * The platform pointer size.
+ *
+ * @return The platform pointer size.
+ */
+ public int pointerSize();
+
+ /**
+ * The platform wide char size.
+ *
+ * @return The platform wide char size.
+ */
+ public int wideCharSize();
+
+}
diff --git a/src/de/intarsys/cwt/awt/image/IAwtImage.java b/src/de/intarsys/nativec/api/INativeLibrary.java
index 82d8844..5f955d4 100644
--- a/src/de/intarsys/cwt/awt/image/IAwtImage.java
+++ b/src/de/intarsys/nativec/api/INativeLibrary.java
@@ -27,23 +27,28 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.awt.image;
-
-import java.awt.image.BufferedImage;
-
-import de.intarsys.cwt.image.IImage;
+package de.intarsys.nativec.api;
/**
- * An {@link IImage} that recognizes itself as an AWT (enabled) image.
+ * A native library (DLL or shared library).
*
*/
-public interface IAwtImage extends IImage {
-
+public interface INativeLibrary {
/**
- * The {@link BufferedImage} that represents this image.
+ * Lookup a {@link INativeFunction} from the library.
*
- * @return The {@link BufferedImage} that represents this image.
+ * @param name
+ * The function name
+ * @return The {@link INativeFunction}
*/
- public BufferedImage getBufferedImage();
+ public INativeFunction getFunction(String name);
+ /**
+ * Lookup a global in the library.
+ *
+ * @param symbolName
+ * The global name
+ * @return The {@link INativeHandle} to the global.
+ */
+ public INativeHandle getGlobal(String symbolName);
}
diff --git a/src/de/intarsys/nativec/api/NativeInterface.java b/src/de/intarsys/nativec/api/NativeInterface.java
new file mode 100644
index 0000000..aa1e84d
--- /dev/null
+++ b/src/de/intarsys/nativec/api/NativeInterface.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.api;
+
+import java.util.Iterator;
+
+import sun.misc.Service;
+
+/**
+ * Access the VM singleton for {@link INativeInterface}.
+ * <p>
+ * To make this work, just do one of the following:
+ * <ul>
+ * <li> set the class name of your implementation with {@link NativeInterface}
+ * </li>
+ * <li> set a {@link INativeInterface} of your choice in {@link NativeInterface}.
+ * </li>
+ * <li> set system property "de.intarsys.nativec.api.INativeInterface" to the
+ * class name of your implementation. </li>
+ * <li> include a service provider file
+ * "de.intarsys.nativec.api.INativeInterface" in your deployment with the class
+ * name of your implementation. </li>
+ * </ul>
+ *
+ */
+public class NativeInterface {
+
+ private static INativeInterface ACTIVE;
+
+ private static String NAME;
+
+ public static INativeHandle NULL;
+
+ public static final String PROP_NATIVEINTERFACE = "de.intarsys.nativec.api.INativeInterface"; //$NON-NLS-1$
+
+ static protected INativeInterface createNativeInterface() {
+ String className = getName();
+ if (className == null) {
+ className = System.getProperty(PROP_NATIVEINTERFACE);
+ }
+ if (className != null) {
+ try {
+ Class clazz = Class.forName(className);
+ return (INativeInterface) clazz.newInstance();
+ } catch (Exception e) {
+ throw new NoClassDefFoundError(className);
+ }
+ }
+ return findNativeInterface();
+ }
+
+ static protected INativeInterface findNativeInterface() {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = NativeInterface.class.getClassLoader();
+ }
+ Iterator ps = Service.providers(INativeInterface.class, loader);
+ if (ps.hasNext()) {
+ try {
+ return (INativeInterface) ps.next();
+ } catch (Throwable e) {
+ // ignore and try on
+ }
+ }
+ return null;
+ }
+
+ synchronized static public INativeInterface get() {
+ if (ACTIVE == null) {
+ set(createNativeInterface());
+ }
+ return ACTIVE;
+ }
+
+ synchronized static public String getName() {
+ return NAME;
+ }
+
+ synchronized static public void set(INativeInterface nativeInterface) {
+ if (nativeInterface == null) {
+ throw new NullPointerException("no native interface available");
+ }
+ ACTIVE = nativeInterface;
+ NULL = nativeInterface.createHandle(0);
+ }
+
+ synchronized static public void setName(String name) {
+ NAME = name;
+ }
+
+}
diff --git a/src/de/intarsys/nativec/api/NativeTools.java b/src/de/intarsys/nativec/api/NativeTools.java
new file mode 100644
index 0000000..8cd6ba9
--- /dev/null
+++ b/src/de/intarsys/nativec/api/NativeTools.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.api;
+
+import de.intarsys.nativec.type.INativeType;
+import de.intarsys.nativec.type.NativeArray;
+import de.intarsys.nativec.type.NativeArrayType;
+import de.intarsys.nativec.type.NativeBuffer;
+import de.intarsys.nativec.type.NativeBufferType;
+import de.intarsys.nativec.type.NativeInt;
+import de.intarsys.nativec.type.NativeLong;
+import de.intarsys.tools.valueholder.IValueHolder;
+import de.intarsys.tools.valueholder.ObjectValueHolder;
+
+/**
+ * Tool class for for dealing with the native framework.
+ */
+public class NativeTools {
+
+ public static byte[] fromNativeByteArray(long ptr, int count) {
+ INativeHandle handle;
+ INativeType type;
+ NativeBuffer nativeValue;
+
+ if (ptr == 0) {
+ return null;
+ }
+ handle = NativeInterface.get().createHandle(ptr);
+ type = NativeBufferType.create(count);
+ nativeValue = (NativeBuffer) type.createNative(handle);
+ return nativeValue.getBytes();
+ }
+
+ public static long fromNativeCLong(long ptr) {
+ INativeHandle handle;
+ NativeLong nativeValue;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ nativeValue = (NativeLong) NativeLong.META.createNative(handle);
+ return nativeValue.intValue();
+ }
+
+ public static IValueHolder<Number> fromNativeCLongHolder(long ptr) {
+ return new ObjectValueHolder<Number>(fromNativeCLong(ptr));
+ }
+
+ public static int fromNativeInt(long ptr) {
+ INativeHandle handle;
+ NativeInt nativeValue;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ nativeValue = (NativeInt) NativeInt.META.createNative(handle);
+ return nativeValue.intValue();
+ }
+
+ public static int[] fromNativeIntArray(INativeHandle handle, int count) {
+ int[] ints;
+ int offset;
+
+ ints = new int[count];
+ offset = NativeInt.META.getByteCount();
+ for (int index = 0; index < count; index++) {
+ ints[index] = handle.getInt(index * offset);
+ }
+ return ints;
+ }
+
+ public static int[] fromNativeIntArray(long ptr, int count) {
+ INativeHandle handle;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ return fromNativeIntArray(handle, count);
+ }
+
+ public static IValueHolder<Integer> fromNativeIntHolder(long ptr) {
+ return new ObjectValueHolder<Integer>(fromNativeInt(ptr));
+ }
+
+ public static String fromNativeString(long ptr, int count) {
+ return null;
+ }
+
+ public static INativeHandle toHandle(long address) {
+ return NativeInterface.get().createHandle(address);
+ }
+
+ public static void toNativeByteArray(long ptr, byte[] value) {
+ if (value != null) {
+ INativeHandle handle;
+ INativeType type;
+ NativeBuffer buffer;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ type = NativeBufferType.create(value.length);
+ buffer = (NativeBuffer) type.createNative(handle);
+ buffer.setValue(value);
+ }
+ }
+
+ public static void toNativeCLong(long ptr, IValueHolder<Number> value) {
+ toNativeCLong(ptr, value.get().longValue());
+ }
+
+ public static void toNativeCLong(long ptr, long value) {
+ INativeHandle handle;
+ NativeLong nativeValue;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ nativeValue = (NativeLong) NativeLong.META.createNative(handle);
+ nativeValue.setValue(value);
+ }
+
+ public static void toNativeCLong(long ptr, int[] value) {
+ if (value != null) {
+ INativeHandle handle;
+ NativeArrayType type;
+ NativeArray array;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ type = NativeArrayType.create(NativeLong.META, value.length);
+ array = (NativeArray) type.createNative(handle);
+ for (int index = 0; index < value.length; index++) {
+ array.setValue(index, value[index]);
+ }
+ }
+ }
+
+ public static void toNativeCLong(long ptr, long[] value) {
+ if (value != null) {
+ INativeHandle handle;
+ NativeArrayType type;
+ NativeArray array;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ type = NativeArrayType.create(NativeLong.META, value.length);
+ array = (NativeArray) type.createNative(handle);
+ for (int index = 0; index < value.length; index++) {
+ array.setValue(index, value[index]);
+ }
+ }
+ }
+
+ public static void toNativeInt(long ptr, int value) {
+ INativeHandle handle;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ handle.setSize(NativeInt.META.getByteCount());
+ handle.setInt(0, value);
+ }
+
+ public static void toNativeInt(long ptr, int[] value) {
+ if (value != null) {
+ INativeHandle handle;
+ NativeArrayType type;
+ NativeArray array;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ type = NativeArrayType.create(NativeInt.META, value.length);
+ array = (NativeArray) type.createNative(handle);
+ for (int index = 0; index < value.length; index++) {
+ array.setValue(index, value[index]);
+ }
+ }
+ }
+
+ public static void toNativeInt(long ptr, IValueHolder<Integer> value) {
+ toNativeInt(ptr, value.get());
+ }
+
+ public static void toNativePointer(long ptr, INativeHandle value) {
+ INativeHandle handle;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ handle.setNativeHandle(0, value);
+ }
+
+}
diff --git a/src/de/intarsys/nativec/api/package.html b/src/de/intarsys/nativec/api/package.html
new file mode 100644
index 0000000..1f134f0
--- /dev/null
+++ b/src/de/intarsys/nativec/api/package.html
@@ -0,0 +1,35 @@
+<html>
+<body>
+This is the main package of the native c component.
+<p>
+Here we define the API's and the VM singleton access to native c.
+<p>
+The component itself was built, as we didn't (once again) find anything
+around that satisfied our needs. We wanted:
+<ul>
+<li>Clean, layered design</li>
+<li>Unrestricted access to all modeled objects and concepts.</li>
+<li>Easy adaption and integration with other views. This means primarily unrestricted
+access to pointers. There is no use in a native library if i can't bootstrap
+with a simple address (in our point of view).</li>
+<li>Clean design for c data structures (primitive, composites and references)</li>
+<li>Exchangeable native implementation</li>
+<li>Platform independence</li>
+</ul>
+
+So we created an API and a data structure component and mapped it to JNA, which has
+great ideas (but in our opinion is to sealed off and has not well done on the
+data structure side) and can serve as a good foundation.
+
+There are some topics we didn't care about yet - this means they may be working or may
+not, its simply not tested. JNA brings a lot of basic features...
+
+<ul>
+<li>Pointer size was not really an issue</li>
+<li>We didn't care about byte order</li>
+</ul>
+
+64 bit implementation is under way.
+
+</body>
+</html> \ No newline at end of file
diff --git a/src/de/intarsys/nativec/jna/JnaNativeCallback.java b/src/de/intarsys/nativec/jna/JnaNativeCallback.java
new file mode 100644
index 0000000..af5b7c5
--- /dev/null
+++ b/src/de/intarsys/nativec/jna/JnaNativeCallback.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.jna;
+
+import com.sun.jna.CallbackProxy;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+import com.sun.jna.WString;
+
+import de.intarsys.nativec.api.CLong;
+import de.intarsys.nativec.api.CWideString;
+import de.intarsys.nativec.api.ICallback;
+import de.intarsys.nativec.api.INativeCallback;
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.type.INativeType;
+import de.intarsys.nativec.type.NativeObject;
+import de.intarsys.nativec.type.NativeType;
+
+public class JnaNativeCallback implements INativeCallback, CallbackProxy {
+
+ public static Class<?> translateType(Class<?> type) {
+ // TODO implement more elegant type translation
+ if (CWideString.class.isAssignableFrom(type)) {
+ return WString.class;
+ } else if (CLong.class.isAssignableFrom(type)) {
+ return NativeLong.class;
+ } else if (NativeObject.class.isAssignableFrom(type)) {
+ return Pointer.class;
+ } else if (INativeHandle.class.isAssignableFrom(type)) {
+ return Pointer.class;
+ }
+ return type;
+ }
+
+ private ICallback callback;
+
+ public JnaNativeCallback(ICallback pCallback) {
+ callback = pCallback;
+ }
+
+ public Object callback(Object[] args) {
+ for (int index = 0; index < args.length; index++) {
+ Class<?> parameterType;
+ Object object;
+
+ parameterType = callback.getParameterTypes()[index];
+ if (CWideString.class.isAssignableFrom(parameterType)) {
+ WString wstring = (WString) args[index];
+ object = new CWideString(wstring.toString());
+ } else if (CLong.class.isAssignableFrom(parameterType)) {
+ NativeLong nativeLong = (NativeLong) args[index];
+ object = new CLong(nativeLong.longValue());
+ } else if (NativeObject.class.isAssignableFrom(parameterType)) {
+ Pointer pointer = (Pointer) args[index];
+ if (pointer == null) {
+ object = null;
+ } else {
+ INativeHandle handle = new JnaNativeHandle(pointer);
+ INativeType type = NativeType.lookup(parameterType);
+ if (type == null) {
+ throw new IllegalArgumentException("no type for '"
+ + parameterType + "'");
+ }
+ object = type.createNative(handle);
+ }
+ } else if (INativeHandle.class.isAssignableFrom(parameterType)) {
+ Pointer pointer = (Pointer) args[index];
+ if (pointer == null) {
+ object = null;
+ } else {
+ object = new JnaNativeHandle(pointer);
+ }
+ } else {
+ object = args[index];
+ }
+ args[index] = object;
+ }
+ // TODO map return value too
+ return callback.invoke(args);
+ }
+
+ public Class<?>[] getParameterTypes() {
+ Class<?>[] genericParameterTypes;
+ Class<?>[] nativeParameterTypes;
+
+ genericParameterTypes = callback.getParameterTypes();
+ nativeParameterTypes = new Class<?>[genericParameterTypes.length];
+
+ for (int index = 0; index < genericParameterTypes.length; index++) {
+ nativeParameterTypes[index] = translateType(genericParameterTypes[index]);
+ }
+ return nativeParameterTypes;
+ }
+
+ public Class<?> getReturnType() {
+ return translateType(callback.getReturnType());
+ }
+
+}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeFunction.java b/src/de/intarsys/nativec/jna/JnaNativeFunction.java
new file mode 100644
index 0000000..d1e4a1b
--- /dev/null
+++ b/src/de/intarsys/nativec/jna/JnaNativeFunction.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.jna;
+
+import com.sun.jna.Function;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+import com.sun.jna.WString;
+
+import de.intarsys.nativec.api.CLong;
+import de.intarsys.nativec.api.INativeFunction;
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.CWideString;
+import de.intarsys.nativec.type.INativeObject;
+import de.intarsys.nativec.type.INativeType;
+import de.intarsys.nativec.type.NativeObject;
+import de.intarsys.nativec.type.NativeType;
+
+public class JnaNativeFunction implements INativeFunction {
+
+ private Function function;
+
+ public JnaNativeFunction(Function function) {
+ this.function = function;
+ }
+
+ protected Function getFunction() {
+ return function;
+ }
+
+ public <T> T invoke(Class<T> returnType, Object... objects) {
+ for (int i = 0; i < objects.length; i++) {
+ Object object = objects[i];
+ if (object instanceof INativeObject) {
+ JnaNativeHandle handle = (JnaNativeHandle) ((INativeObject) object)
+ .getNativeHandle();
+ if (handle == null) {
+ objects[i] = null;
+ } else {
+ objects[i] = handle.getPointer();
+ }
+ } else if (object instanceof INativeHandle) {
+ JnaNativeHandle handle = (JnaNativeHandle) object;
+ objects[i] = handle.getPointer();
+ } else if (object instanceof CWideString) {
+ objects[i] = new WString(((CWideString) object).getString());
+ } else if (object instanceof CLong) {
+ objects[i] = new NativeLong(((CLong) object).longValue());
+ }
+ }
+ // if (Log.isLoggable(Level.FINE)) {
+ // Log.log(Level.FINE, "jna invoke " + function.getName());
+ // }
+ T result;
+ if (CWideString.class.isAssignableFrom(returnType)) {
+ WString wstring = (WString) function.invoke(WString.class, objects);
+ result = (T) new CWideString(wstring.toString());
+ } else if (CLong.class.isAssignableFrom(returnType)) {
+ NativeLong nativeLong = (NativeLong) function.invoke(
+ NativeLong.class, objects);
+ result = (T) new CLong(nativeLong.longValue());
+ } else if (NativeObject.class.isAssignableFrom(returnType)) {
+ Pointer pointer = (Pointer) function.invoke(Pointer.class, objects);
+ if (pointer == null) {
+ result = null;
+ } else {
+ INativeHandle handle = new JnaNativeHandle(pointer);
+ INativeType type = NativeType.lookup(returnType);
+ if (type == null) {
+ throw new IllegalArgumentException("no type for '"
+ + returnType + "'");
+ }
+ result = (T) type.createNative(handle);
+ }
+ } else if (INativeHandle.class.isAssignableFrom(returnType)) {
+ Pointer pointer = (Pointer) function.invoke(Pointer.class, objects);
+ if (pointer == null) {
+ result = null;
+ } else {
+ result = (T) new JnaNativeHandle(pointer);
+ }
+ } else {
+ result = (T) function.invoke(returnType, objects);
+ }
+ return result;
+ }
+}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeHandle.java b/src/de/intarsys/nativec/jna/JnaNativeHandle.java
new file mode 100644
index 0000000..75680ee
--- /dev/null
+++ b/src/de/intarsys/nativec/jna/JnaNativeHandle.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.jna;
+
+import com.sun.jna.JNATools;
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+public class JnaNativeHandle implements INativeHandle {
+
+ final private Pointer pointer;
+
+ private int size;
+
+ public JnaNativeHandle(JnaNativeHandle handle, int offset) {
+ this.pointer = new Pointer(handle.getAddress() + offset);
+ this.size = handle.size - offset;
+ }
+
+ public JnaNativeHandle(long address) {
+ this.pointer = new Pointer(address);
+ }
+
+ public JnaNativeHandle(Pointer pointer) {
+ this.pointer = pointer;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof INativeHandle)) {
+ return false;
+ }
+ INativeHandle otherHandle = (INativeHandle) obj;
+ return JNATools.getPeer(pointer) == otherHandle.getAddress()
+ && size == otherHandle.getSize();
+ }
+
+ public long getAddress() {
+ return JNATools.getPeer(pointer);
+ }
+
+ public byte getByte(int index) {
+ return pointer.getByte(index);
+ }
+
+ public byte[] getByteArray(int index, int count) {
+ return pointer.getByteArray(index, count);
+ }
+
+ public long getCLong(int index) {
+ if (Native.LONG_SIZE == 4) {
+ return pointer.getInt(index);
+ }
+ return pointer.getLong(index);
+ }
+
+ public int getInt(int index) {
+ return pointer.getInt(index);
+ }
+
+ public long getLong(int index) {
+ return pointer.getLong(index);
+ }
+
+ public INativeHandle getNativeHandle(int index) {
+ Pointer tempPointer = pointer.getPointer(index);
+ return new JnaNativeHandle(tempPointer);
+ }
+
+ public Pointer getPointer() {
+ return pointer;
+ }
+
+ public short getShort(int index) {
+ return pointer.getShort(index);
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public String getString(int index) {
+ // if (buffer == null) {
+ // return null;
+ // }
+ // // todo encoding
+ // buffer.position(offset + index);
+ // int i = 0;
+ // while (buffer.get() != 0) {
+ // i++;
+ // }
+ // buffer.position(offset + index);
+ // byte[] valueBytes = new byte[i];
+ // buffer.get(valueBytes);
+ // return new String(valueBytes);
+ return getPointer().getString(index);
+ }
+
+ public String getWideString(int index) {
+ return getPointer().getString(index, true);
+ }
+
+ @Override
+ public int hashCode() {
+ return pointer.hashCode();
+ }
+
+ public INativeHandle offset(int offset) {
+ return new JnaNativeHandle(this, offset);
+ }
+
+ public void setByte(int index, byte value) {
+ pointer.setByte(index, value);
+ }
+
+ public void setByteArray(int index, byte[] value, int valueOffset,
+ int valueCount) {
+ pointer.write(index, value, valueOffset, valueCount);
+ }
+
+ public void setCLong(int index, long value) {
+ if (Native.LONG_SIZE == 4) {
+ pointer.setInt(index, (int) value);
+ return;
+ }
+ pointer.setLong(index, value);
+ }
+
+ public void setInt(int index, int value) {
+ pointer.setInt(index, value);
+ }
+
+ public void setLong(int index, long value) {
+ pointer.setLong(index, value);
+ }
+
+ public void setNativeHandle(int index, INativeHandle handle) {
+ pointer.setPointer(index, new Pointer(handle.getAddress()));
+ }
+
+ public void setShort(int index, short value) {
+ pointer.setShort(index, value);
+ }
+
+ public void setSize(int pSize) {
+ this.size = pSize;
+ }
+
+ public void setString(int index, String value) {
+ // // todo encoding
+ getPointer().setString(index, value);
+ }
+
+ public void setWideString(int index, String value) {
+ getPointer().setString(index, value, true);
+ }
+
+}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeInterface.java b/src/de/intarsys/nativec/jna/JnaNativeInterface.java
new file mode 100644
index 0000000..3f5d4b1
--- /dev/null
+++ b/src/de/intarsys/nativec/jna/JnaNativeInterface.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.jna;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.sun.jna.FastMemory;
+import com.sun.jna.Function;
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+
+import de.intarsys.nativec.api.ICallback;
+import de.intarsys.nativec.api.INativeCallback;
+import de.intarsys.nativec.api.INativeFunction;
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.INativeInterface;
+import de.intarsys.nativec.api.INativeLibrary;
+
+/**
+ * An {@link INativeInterface} implemented using JNA, a LGPL licensed Java
+ * native interface abstraction.
+ * <p>
+ * In our point of view, JNA has the power of deploying all what we wanted to
+ * have, but is ill designed in some key hot spots - so we worked around and
+ * built on top of our own interfaces.
+ *
+ */
+public class JnaNativeInterface implements INativeInterface {
+
+ static {
+ /*
+ * Ugly hack - multithreaded loading caused a deadlock here as
+ * com.sun.jna.Native requests a native library which later requires a
+ * lock on the class loader, while another piece of code
+ * (Security.addProvider) first locks the class loader and later on
+ * requests the runtime to load a native library. <p> We try here to
+ * provide the same ordering (which is based on a lot of assumptions...)
+ */
+ ClassLoader loader = JnaNativeInterface.class.getClassLoader();
+ synchronized (loader) {
+ try {
+ Class.forName("com.sun.jna.Native", true, loader);
+ } catch (ClassNotFoundException e) {
+ // will fail later anyway
+ }
+ }
+ }
+
+ private List<String> searchPaths = new ArrayList<String>();
+
+ public void addSearchPath(String path) {
+ if (searchPaths.contains(path)) {
+ return;
+ }
+ searchPaths.add(path);
+ }
+
+ public INativeHandle allocate(int size) {
+ return new JnaNativeHandle(new FastMemory(size));
+ }
+
+ public INativeCallback createCallback(ICallback callback) {
+ return new JnaNativeCallback(callback);
+ }
+
+ public INativeFunction createFunction(long address) {
+ Pointer pointer;
+ Function function;
+
+ pointer = new Pointer(address);
+ function = Function.getFunction(pointer);
+ return new JnaNativeFunction(function);
+ }
+
+ public INativeHandle createHandle(long address) {
+ return new JnaNativeHandle(address);
+ }
+
+ public INativeLibrary createLibrary(String name) {
+ return new JnaNativeLibrary(this, name);
+ }
+
+ protected List<String> getSearchPaths() {
+ return searchPaths;
+ }
+
+ public int longSize() {
+ return Native.LONG_SIZE;
+ }
+
+ public int pointerSize() {
+ return Native.POINTER_SIZE;
+ }
+
+ public int wideCharSize() {
+ return 2;
+ }
+}
diff --git a/src/de/intarsys/cwt/font/FontMapper.java b/src/de/intarsys/nativec/jna/JnaNativeLibrary.java
index 7ac3fbc..6a0a617 100644
--- a/src/de/intarsys/cwt/font/FontMapper.java
+++ b/src/de/intarsys/nativec/jna/JnaNativeLibrary.java
@@ -27,57 +27,52 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font;
+package de.intarsys.nativec.jna;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Iterator;
-/**
- *
- */
-public class FontMapper {
- private static FontMapper Active = new FontMapper();
+import com.sun.jna.Function;
+import com.sun.jna.NativeLibrary;
+import com.sun.jna.Pointer;
- public static synchronized FontMapper get() {
- return Active;
- }
+import de.intarsys.nativec.api.INativeFunction;
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.INativeLibrary;
- public static synchronized void set(FontMapper mapper) {
- Active = mapper;
- }
+public class JnaNativeLibrary implements INativeLibrary {
- private Map<String, FontMap> fontMaps = new HashMap<String, FontMap>();
+ final private NativeLibrary library;
- protected FontMapper() {
- super();
- }
+ final private JnaNativeInterface nativeInterface;
- public IFont lookupFont(String name) {
- FontMap fontMap = fontMaps.get(normalize(name));
- if (fontMap == null) {
- return null;
+ public JnaNativeLibrary(JnaNativeInterface nativeInterface, String name) {
+ this.nativeInterface = nativeInterface;
+ // this is a kludge - but i can't ask for the searchpaths already
+ // registered
+ for (Iterator<String> it = nativeInterface.getSearchPaths().iterator(); it
+ .hasNext();) {
+ String path = it.next();
+ NativeLibrary.addSearchPath(name, path);
}
- return fontMap.getFont();
+ library = NativeLibrary.getInstance(name);
}
- protected String normalize(String name) {
- if (name == null) {
- return null;
- }
- return name.toLowerCase();
- // StringBuilder result = new StringBuilder();
- // for (int i = 0; i < name.length(); i++) {
- // char c = name.charAt(i);
- // if ((c == ' ') || (c == '_') || (c == '-')) {
- // continue;
- // }
- // result.append(Character.toLowerCase(c));
- // }
- // return result.toString();
+ public INativeFunction getFunction(String name) {
+ Function function = getLibrary().getFunction(name);
+ return new JnaNativeFunction(function);
+ }
+
+ public INativeHandle getGlobal(String symbolName) {
+ Pointer pointer = getLibrary().getGlobalVariableAddress(symbolName);
+ return new JnaNativeHandle(pointer);
+ }
+
+ protected NativeLibrary getLibrary() {
+ return library;
}
- public void registerFontMap(FontMap map) {
- fontMaps.put(normalize(map.getKey()), map);
+ protected JnaNativeInterface getNativeInterface() {
+ return nativeInterface;
}
}
diff --git a/src/de/intarsys/cwt/common/IPaint.java b/src/de/intarsys/nativec/type/INativeObject.java
index 85540fb..89ac2cc 100644
--- a/src/de/intarsys/cwt/common/IPaint.java
+++ b/src/de/intarsys/nativec/type/INativeObject.java
@@ -27,28 +27,53 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.common;
+package de.intarsys.nativec.type;
-import de.intarsys.cwt.environment.IGraphicsContext;
+import de.intarsys.nativec.api.INativeHandle;
/**
+ * The Java object representation of a c memory construct.
+ * <p>
+ * The {@link INativeObject} has a reference to c memory (the
+ * {@link INativeHandle} and "marshalling" methods "getValue" and "setValue" to
+ * get and set the Java representation.
*
*/
-public interface IPaint {
+public interface INativeObject {
/**
- * @return
+ * The bytes that make up the {@link INativeObject}.
+ *
+ * @return The bytes that make up the {@link INativeObject}.
*/
- public IPaint copy();
-
- public float getAlphaValue();
+ public byte[] getBytes();
- public void setAlphaValue(float value);
+ /**
+ * The {@link INativeHandle} to the c memory for the object.
+ *
+ * @return
+ */
+ public INativeHandle getNativeHandle();
- public void setBackgroundPaintFromGraphicsContext(
- IGraphicsContext graphicsContext);
+ /**
+ * The {@link INativeType} for the object.
+ *
+ * @return
+ */
+ public INativeType getNativeType();
- public void setForegroundPaintFromGraphicsContext(
- IGraphicsContext graphicsContext);
+ /**
+ * A Java side representation from the memory.
+ *
+ * @return A Java side representation for the {@link INativeObject}.
+ */
+ public Object getValue();
+ /**
+ * Assign (and marshall to memory) the Java side representation.
+ *
+ * @param value
+ * The new Java value.
+ */
+ public void setValue(Object value);
}
diff --git a/src/de/intarsys/cwt/font/IFontFamily.java b/src/de/intarsys/nativec/type/INativeType.java
index 2c31bf1..7df146f 100644
--- a/src/de/intarsys/cwt/font/IFontFamily.java
+++ b/src/de/intarsys/nativec/type/INativeType.java
@@ -27,61 +27,66 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font;
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
/**
- * The family a font belongs to. This is a collection of similar fonts that are
- * different with respect to their style.
+ * The type (factory) for {@link INativeObject} instances.
+ * <p>
+ * A type has declaration style method to create more complex types.
*
*/
-public interface IFontFamily {
+public interface INativeType {
/**
- * for example
+ * Create an array type from this.
+ *
+ * @param size
+ * The predefined size for the array.
*
- * @return for example
+ * @return The derived type.
*/
- public String getFamilyName();
+ public INativeType Array(int size);
/**
- * The {@link IFont} within the family with a specific {@link FontStyle} or
- * null.
+ * Create an {@link INativeObject} for this type from the Java object.
*
- * @param style
- * The requested style.
- * @return The {@link IFont} within the family with a specific
- * {@link FontStyle} or null.
+ * @param value
+ *
+ * @return The new {@link INativeObject}
*/
- public IFont getFont(FontStyle style);
+ public INativeObject createNative(Object value);
/**
- * All {@link IFont} instances within this family.
+ * Create a new {@link INativeObject} from a {@link INativeHandle}.
*
- * @return All {@link IFont} instances within this family.
+ * @param handle
+ * The handle to memory.
+ * @return The new {@link INativeObject}
*/
- public IFont[] getFonts();
+ public INativeObject createNative(INativeHandle handle);
/**
- * The supported {@link FontStyle} instances in this family.
- *
- * @return The supported {@link FontStyle} instances in this family.
+ * The boundary where this type as a struct member would want to be aligned.
+ * A structure can override this value with packing.
*
+ * @return The preferred alignment boundary.
*/
- public FontStyle[] getFontStyles();
+ public int getPreferredBoundary();
/**
- * The font type. This is for example "TrueType" or "Type1".
+ * The size of the type in c memory.
*
- * @return The font type.
+ * @return The size of the type in c memory.
*/
- public String getFontType();
+ public int getByteCount();
/**
- * Add a new {@link IFont} to this family.
+ * Create a reference type to this.
*
- * @param font
- * The new {@link IFont}
+ * @return The derived type.
*/
- public void registerFont(IFont font);
+ public INativeType Ref();
}
diff --git a/src/de/intarsys/cwt/font/truetype/TTNaming.java b/src/de/intarsys/nativec/type/NativeAbstractStringType.java
index 48acbee..51f4eca 100644
--- a/src/de/intarsys/cwt/font/truetype/TTNaming.java
+++ b/src/de/intarsys/nativec/type/NativeAbstractStringType.java
@@ -27,49 +27,48 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font.truetype;
+package de.intarsys.nativec.type;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import de.intarsys.nativec.api.NativeInterface;
/**
- *
+ * A meta class implementation
*/
-public class TTNaming {
- private List nameRecords;
+public class NativeAbstractStringType extends NativeType {
- public TTNaming() {
- nameRecords = new ArrayList(20);
+ private final int characterSize;
+ private final int stringSize;
+
+ protected NativeAbstractStringType(int pCharacterSize) {
+ super();
+ characterSize = pCharacterSize;
+ stringSize = 0;
}
- public void add(int nameId, TTNameRecord record) {
- getNameRecords().add(record);
+ protected NativeAbstractStringType(int pStringSize, int pCharacterSize) {
+ super();
+ characterSize = pCharacterSize;
+ stringSize = pStringSize;
}
- public TTNameRecord getNameRecord(int nameId) {
- for (Iterator it = nameRecords.iterator(); it.hasNext();) {
- TTNameRecord record = (TTNameRecord) it.next();
- if (record.getNameID() == nameId) {
- return record;
- }
+ @Override
+ public int getByteCount() {
+ if (stringSize == 0) {
+ throw new IllegalStateException();
}
- return null;
+ return stringSize * characterSize;
}
- public List getNameRecords() {
- return nameRecords;
+ public int getPreferredBoundary() {
+ return NativeInterface.get().pointerSize();
}
- public String getValue(int nameId) {
- TTNameRecord r = getNameRecord(nameId);
- if (r != null) {
- return r.getValue();
- }
- return null;
+ public int getStringSize() {
+ return stringSize;
}
- public void setNameRecords(List list) {
- nameRecords = list;
+ public boolean hasByteCount() {
+ return stringSize != 0;
}
-}
+
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeArray.java b/src/de/intarsys/nativec/type/NativeArray.java
new file mode 100644
index 0000000..4f32c9c
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeArray.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * An {@link INativeObject} that represents a homogeneous (this means of equal
+ * length and type) sequence of other {@link INativeObject} instances.
+ */
+public class NativeArray extends NativeObject {
+
+ /** The meta class instance */
+ public static final NativeArrayType META = new NativeArrayType(
+ NativeVoid.META, 0);
+
+ static {
+ NativeType.register(NativeArray.class, META);
+ }
+
+ public static NativeArray create(INativeType baseType, int size) {
+ NativeArrayType type = new NativeArrayType(baseType, size);
+ return new NativeArray(type);
+ }
+
+ private INativeObject[] values;
+
+ private NativeArrayType type;
+
+ protected NativeArray(NativeArrayType type) {
+ this.type = type;
+ allocate();
+ }
+
+ protected NativeArray(NativeArrayType type, INativeHandle handle) {
+ super(handle);
+ this.type = type;
+ }
+
+ public INativeType getBaseType() {
+ return type.getBaseType();
+ }
+
+ @Override
+ public int getByteCount() {
+ return type.getByteCount();
+ }
+
+ /**
+ * The {@link INativeObject} at index in the sequence (the index'th element
+ * of the array).
+ *
+ * @param index
+ * The index of the element to be reported.
+ *
+ * @return The NativeObject at index
+ */
+ synchronized public INativeObject getNativeObject(int index) {
+ if (values == null) {
+ values = new INativeObject[getSize()];
+ }
+ INativeObject result = values[index];
+ if (result == null) {
+ int elementOffset = index * type.getBaseSize();
+ result = type.getBaseType().createNative(
+ handle.offset(elementOffset));
+ values[index] = result;
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
+ */
+ @Override
+ public INativeType getNativeType() {
+ return type;
+ }
+
+ /**
+ * The number of NativeObject instances in the sequence represented by this
+ * (in other terms the array size).
+ *
+ * @return The number of NativeObject instances in the sequence represented
+ * by this
+ */
+ public int getSize() {
+ return type.getArraySize();
+ }
+
+ public Object getValue() {
+ throw new UnsupportedOperationException(
+ "getValue not implemented for NativeArray");
+ }
+
+ public Object getValue(int index) {
+ return getNativeObject(index).getValue();
+ }
+
+ public void setBaseType(INativeType baseType) {
+ type = NativeArrayType.create(baseType, type.getArraySize());
+ this.values = null;
+ handle.setSize(getByteCount());
+ }
+
+ public void setSize(int size) {
+ type = NativeArrayType.create(type.getBaseType(), size);
+ this.values = null;
+ handle.setSize(getByteCount());
+ }
+
+ public void setValue(int index, Object value) {
+ getNativeObject(index).setValue(value);
+ }
+
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException(
+ "setValue not implemented for NativeArray");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#toNestedString()
+ */
+ @Override
+ public String toNestedString() {
+ return "[...]";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+ for (int i = 0; i < getSize(); i++) {
+ // NativeObject element = get(i);
+ // sb.append(element.toString());
+ // sb.append(", ");
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+}
diff --git a/src/de/intarsys/cwt/font/truetype/TTNameRecord.java b/src/de/intarsys/nativec/type/NativeArrayType.java
index 8df586a..f9006b2 100644
--- a/src/de/intarsys/cwt/font/truetype/TTNameRecord.java
+++ b/src/de/intarsys/nativec/type/NativeArrayType.java
@@ -27,91 +27,73 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font.truetype;
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
/**
- *
+ * The type for a {@link NativeArray}
*/
-public class TTNameRecord {
- private int platformID;
-
- private int encodingID;
-
- private int languageID;
-
- private int nameID;
-
- private int length;
-
- private String value;
-
- public TTNameRecord() {
- }
-
- public TTNameRecord(int platformID, int encodingID, int languageID,
- int nameID, String value) {
- super();
- setPlatformID(platformID);
- setEncodingID(encodingID);
- setLanguageID(languageID);
- setNameID(nameID);
- setValue(value);
- }
+public class NativeArrayType extends NativeType {
- public int getEncodingID() {
- return encodingID;
+ public static NativeArrayType create(INativeType baseType, int size) {
+ return new NativeArrayType(baseType, size);
}
- public int getLanguageID() {
- return languageID;
- }
+ private final int arraySize;
- public int getLength() {
- return length;
- }
+ /**
+ * The size of the base type of the array.
+ */
+ private final int baseSize;
- public int getNameID() {
- return nameID;
- }
+ /**
+ * The base type of the array.
+ */
+ private final INativeType baseType;
- public int getPlatformID() {
- return platformID;
+ protected NativeArrayType(INativeType baseDeclaration, int arraySize) {
+ super();
+ this.baseType = baseDeclaration;
+ this.baseSize = baseDeclaration.getByteCount();
+ this.arraySize = arraySize;
}
- public String getValue() {
- return value;
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ NativeArray array = new NativeArray(this, handle);
+ if (arraySize > 0) {
+ array.setSize(arraySize);
+ }
+ return array;
}
- public void setEncodingID(int i) {
- encodingID = i;
+ @Override
+ public INativeObject createNative(Object value) {
+ NativeArray array = new NativeArray(this);
+ return array;
}
- public void setLanguageID(int i) {
- languageID = i;
+ public int getArraySize() {
+ return arraySize;
}
- public void setLength(int i) {
- length = i;
+ public int getBaseSize() {
+ return baseSize;
}
- public void setNameID(int i) {
- nameID = i;
+ public INativeType getBaseType() {
+ return baseType;
}
- public void setPlatformID(int i) {
- platformID = i;
+ @Override
+ public int getByteCount() {
+ // todo take into account alignment / packing?
+ return arraySize * baseSize;
}
- public void setValue(String value) {
- /*
- * byte[] bytes = null; try { bytes = value.getBytes("UTF-16BE"); }
- * catch (Exception ignore) { } setData(bytes);
- */
- this.value = value;
+ public int getPreferredBoundary() {
+ return baseType.getPreferredBoundary();
}
- @Override
- public String toString() {
- return "ID:" + getNameID() + " Value:" + getValue(); //$NON-NLS-1$ //$NON-NLS-2$
- }
}
diff --git a/src/de/intarsys/nativec/type/NativeBuffer.java b/src/de/intarsys/nativec/type/NativeBuffer.java
new file mode 100644
index 0000000..a4b0568
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeBuffer.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import java.nio.ByteBuffer;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+
+/**
+ * A wrapper for a sequence of bytes.
+ *
+ */
+public class NativeBuffer extends NativeObject {
+
+ /** The meta class instance */
+ public static final NativeBufferType META = new NativeBufferType();
+
+ static {
+ NativeType.register(NativeBuffer.class, META);
+ }
+
+ private NativeBufferType type;
+
+ public NativeBuffer(byte[] bytes) {
+ type = new NativeBufferType(bytes.length);
+ handle = NativeInterface.get().allocate(bytes.length);
+ handle.setByteArray(0, bytes, 0, bytes.length);
+ }
+
+ protected NativeBuffer(INativeHandle handle) {
+ super(handle);
+ }
+
+ public NativeBuffer(int pSize) {
+ type = new NativeBufferType(pSize);
+ handle = NativeInterface.get().allocate(pSize);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeObject#getByteCount()
+ */
+ @Override
+ public int getByteCount() {
+ // todo alignment?
+ return type.getByteCount();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
+ */
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ /**
+ * The number of elements in the NativeBuffer
+ *
+ * @return
+ */
+ public int getSize() {
+ return type.getByteCount();
+ }
+
+ public Object getValue() {
+ return getBytes();
+ }
+
+ public void setSize(int size) {
+ type = new NativeBufferType(size);
+ handle.setSize(getByteCount());
+ }
+
+ public void setValue(Object value) {
+ if (value instanceof byte[]) {
+ byte[] data = (byte[]) value;
+ setByteArray(0, data, 0, data.length);
+ } else if (value instanceof ByteBuffer) {
+ byte[] data = new byte[getSize()];
+ ((ByteBuffer) value).get(data);
+ setByteArray(0, data, 0, data.length);
+ }
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeBufferType.java b/src/de/intarsys/nativec/type/NativeBufferType.java
new file mode 100644
index 0000000..bef5dbf
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeBufferType.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * The meta class implementation
+ */
+public class NativeBufferType extends NativeType {
+
+ public static NativeBufferType create(int size) {
+ return new NativeBufferType(size);
+ }
+
+ final private int bufferSize;
+
+ protected NativeBufferType() {
+ super();
+ this.bufferSize = 0;
+ }
+
+ protected NativeBufferType(int bufferSize) {
+ super();
+ this.bufferSize = bufferSize;
+ }
+
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ NativeBuffer buffer;
+
+ buffer = new NativeBuffer(handle);
+ // setSize() creates a new type object
+ // TODO create constructor to use the existing one?
+ buffer.setSize(bufferSize);
+ return buffer;
+ }
+
+ public int getBufferSize() {
+ return bufferSize;
+ }
+
+ @Override
+ public int getByteCount() {
+ return bufferSize;
+ }
+
+ public int getPreferredBoundary() {
+ return 1;
+ }
+
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeByte.java b/src/de/intarsys/nativec/type/NativeByte.java
new file mode 100644
index 0000000..e11fd45
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeByte.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+
+/**
+ * A wrapper for a primitive byte.
+ *
+ */
+public class NativeByte extends NativeNumber {
+
+ /** The meta class instance */
+ public static final NativeByteType META = new NativeByteType();
+
+ static {
+ NativeType.register(NativeByte.class, META);
+ }
+
+ static public NativeByte createFromAddress(long address) {
+ return (NativeByte) NativeByte.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeByte() {
+ allocate();
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeByte(byte value) {
+ allocate();
+ setValue(value);
+ }
+
+ protected NativeByte(INativeHandle handle) {
+ super(handle);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeNumber#byteValue()
+ */
+ @Override
+ public byte byteValue() {
+ return handle.getByte(0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
+ */
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativePrimitive#getValue()
+ */
+ public Object getValue() {
+ return new Byte(byteValue());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeNumber#intValue()
+ */
+ @Override
+ public int intValue() {
+ return byteValue();
+ }
+
+ @Override
+ public long longValue() {
+ return byteValue();
+ }
+
+ public void setValue(byte value) {
+ handle.setByte(0, value);
+ }
+
+ public void setValue(Object value) {
+ setValue(((Number) value).byteValue());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeNumber#shortValue()
+ */
+ @Override
+ public short shortValue() {
+ return byteValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(byteValue());
+ }
+}
diff --git a/src/de/intarsys/cwt/font/FontMap.java b/src/de/intarsys/nativec/type/NativeByteType.java
index 69bb240..49e4a4f 100644
--- a/src/de/intarsys/cwt/font/FontMap.java
+++ b/src/de/intarsys/nativec/type/NativeByteType.java
@@ -27,37 +27,31 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font;
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
/**
- *
+ * The meta class implementation
*/
-public abstract class FontMap {
-
- final private String name;
+public class NativeByteType extends NativeNumberType {
- final private FontMapper mapper;
-
- public FontMap(FontMapper mapper, String name) {
+ protected NativeByteType() {
super();
- this.mapper = mapper;
- this.name = name;
}
- public abstract IFont getFont();
-
- public String getKey() {
- if (name == null) {
- return null;
- }
- return getName().toLowerCase();
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeByte(handle);
}
- public FontMapper getMapper() {
- return mapper;
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeByte(((Number) value).byteValue());
}
- public String getName() {
- return name;
+ @Override
+ public int getByteCount() {
+ return NativeByte.SIZE_BYTE;
}
-}
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeGenericStruct.java b/src/de/intarsys/nativec/type/NativeGenericStruct.java
new file mode 100644
index 0000000..74eec69
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeGenericStruct.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * The generic struct may change its type at runtime.
+ *
+ */
+public class NativeGenericStruct extends NativeStruct {
+
+ private NativeStructType type;
+
+ protected NativeGenericStruct(NativeStructType type) {
+ super();
+ this.type = type;
+ allocate();
+ }
+
+ protected NativeGenericStruct(NativeStructType type, INativeHandle handle) {
+ super(handle);
+ this.type = type;
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return type;
+ }
+
+ @Override
+ public NativeStructType getStructType() {
+ return type;
+ }
+
+ public void setNativeType(NativeStructType type) {
+ this.type = type;
+ this.values = null;
+ }
+
+}
diff --git a/src/de/intarsys/nativec/type/NativeInt.java b/src/de/intarsys/nativec/type/NativeInt.java
new file mode 100644
index 0000000..6c15ddb
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeInt.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+
+/**
+ * A wrapper for a primitive int (which is always 4 bytes except on ILP64
+ * systems which can be treated as non-existent for our purposes).
+ */
+public class NativeInt extends NativeNumber {
+
+ /** The meta class instance */
+ public static final NativeIntType META = new NativeIntType();
+
+ static {
+ NativeType.register(NativeInt.class, META);
+ }
+
+ static public NativeInt createFromAddress(long address) {
+ return (NativeInt) NativeInt.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeInt() {
+ allocate();
+ }
+
+ protected NativeInt(INativeHandle handle) {
+ super(handle);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeInt(long value) {
+ allocate();
+ setValue(value);
+ }
+
+ @Override
+ public byte byteValue() {
+ return (byte) intValue();
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ public Object getValue() {
+ return new Integer(intValue());
+ }
+
+ @Override
+ public int intValue() {
+ return handle.getInt(0);
+ }
+
+ @Override
+ public long longValue() {
+ return intValue();
+ }
+
+ public void setValue(int value) {
+ handle.setInt(0, value);
+ }
+
+ public void setValue(Object value) {
+ setValue(((Number) value).intValue());
+ }
+
+ @Override
+ public short shortValue() {
+ return (short) intValue();
+ }
+
+ @Override
+ public String toString() {
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(intValue());
+ }
+}
diff --git a/src/de/intarsys/cwt/image/ImageException.java b/src/de/intarsys/nativec/type/NativeIntType.java
index 789ac8b..2c0c8b4 100644
--- a/src/de/intarsys/cwt/image/ImageException.java
+++ b/src/de/intarsys/nativec/type/NativeIntType.java
@@ -27,41 +27,31 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.image;
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
/**
- *
- *
+ * The meta class implementation
*/
-public class ImageException extends RuntimeException {
+public class NativeIntType extends NativeNumberType {
- /**
- *
- */
- public ImageException() {
+ protected NativeIntType() {
super();
}
- /**
- * @param message
- */
- public ImageException(String message) {
- super(message);
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeInt(handle);
}
- /**
- * @param message
- * @param cause
- */
- public ImageException(String message, Throwable cause) {
- super(message, cause);
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeInt(((Number) value).longValue());
}
- /**
- * @param cause
- */
- public ImageException(Throwable cause) {
- super(cause);
+ @Override
+ public int getByteCount() {
+ return NativeInt.SIZE_INT;
}
-
-}
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeLong.java b/src/de/intarsys/nativec/type/NativeLong.java
new file mode 100644
index 0000000..5e2fac9
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeLong.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+
+/**
+ * A wrapper for a primitive long. The size of a long depends on the platform;
+ * on a 64-bit Linux or Mac OS X we have 8 byte longs...
+ */
+public class NativeLong extends NativeNumber {
+
+ /** The meta class instance */
+ public static final NativeLongType META = new NativeLongType();
+
+ static {
+ NativeType.register(NativeLong.class, META);
+ }
+
+ static public NativeLong createFromAddress(long address) {
+ return (NativeLong) NativeLong.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLong() {
+ allocate();
+ }
+
+ protected NativeLong(INativeHandle handle) {
+ super(handle);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLong(long value) {
+ allocate();
+ setValue(value);
+ }
+
+ @Override
+ public byte byteValue() {
+ return (byte) intValue();
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ public Object getValue() {
+ return new Long(longValue());
+ }
+
+ @Override
+ public int intValue() {
+ return (int) longValue();
+ }
+
+ @Override
+ public long longValue() {
+ return handle.getCLong(0);
+ }
+
+ public void setValue(long value) {
+ handle.setCLong(0, value);
+ }
+
+ public void setValue(Object value) {
+ setValue(((Number) value).longValue());
+ }
+
+ @Override
+ public short shortValue() {
+ return (short) longValue();
+ }
+
+ @Override
+ public String toString() {
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(longValue());
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeLongLP64.java b/src/de/intarsys/nativec/type/NativeLongLP64.java
new file mode 100644
index 0000000..379f9cb
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeLongLP64.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+
+/**
+ * A wrapper for the Windows type LONG_PTR. This type has the same size as a
+ * pointer but is semantically a simple integer. (same as NativeLong on LP64
+ * platforms size-wise)
+ */
+public class NativeLongLP64 extends NativeNumber {
+
+ /** The meta class instance */
+ public static final NativeLongLP64Type META = new NativeLongLP64Type();
+
+ static {
+ NativeType.register(NativeLongLP64.class, META);
+ }
+
+ static public NativeLongLP64 createFromAddress(long address) {
+ return (NativeLongLP64) NativeLongLP64.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLongLP64() {
+ allocate();
+ }
+
+ protected NativeLongLP64(INativeHandle handle) {
+ super(handle);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLongLP64(long value) {
+ allocate();
+ setValue(value);
+ }
+
+ @Override
+ public byte byteValue() {
+ return (byte) intValue();
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ public Object getValue() {
+ return new Long(longValue());
+ }
+
+ @Override
+ public int intValue() {
+ return (int) longValue();
+ }
+
+ @Override
+ public long longValue() {
+ if (NativeObject.SIZE_PTR == 4) {
+ return handle.getInt(0);
+ }
+ return handle.getLong(0);
+ }
+
+ public void setValue(long value) {
+ if (NativeObject.SIZE_PTR == 4) {
+ handle.setInt(0, (int) value);
+ return;
+ }
+ handle.setLong(0, value);
+ }
+
+ public void setValue(Object value) {
+ setValue(((Number) value).longValue());
+ }
+
+ @Override
+ public short shortValue() {
+ return (short) longValue();
+ }
+
+ @Override
+ public String toString() {
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(longValue());
+ }
+
+}
diff --git a/src/de/intarsys/cwt/image/ImageContainer.java b/src/de/intarsys/nativec/type/NativeLongLP64Type.java
index a9ac628..5c8ad31 100644
--- a/src/de/intarsys/cwt/image/ImageContainer.java
+++ b/src/de/intarsys/nativec/type/NativeLongLP64Type.java
@@ -27,45 +27,42 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.image;
+package de.intarsys.nativec.type;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import de.intarsys.nativec.api.INativeHandle;
-/*
- * DOCME
+/**
+ * The meta class implementation
*/
-public abstract class ImageContainer implements IImageContainer {
-
- private boolean closed;
-
- private Map attributes = new HashMap();
+public class NativeLongLP64Type extends NativeNumberType {
- protected ImageContainer() {
- super();
- }
-
- abstract protected void basicClose() throws IOException;
-
- public void close() throws IOException {
- if (closed) {
- throw new IllegalStateException("already closed");
+ /**
+ * Utility method: return the given number as another number object with
+ * compatible byte size
+ */
+ public static Object coerce(Number value) {
+ if (NativeObject.SIZE_PTR == 4) {
+ return value.intValue();
}
- closed = true;
- basicClose();
+ return value.longValue();
}
- public Object getAttribute(Object key) {
- return attributes.get(key);
+ protected NativeLongLP64Type() {
+ super();
}
- public Object removeAttribute(Object key) {
- return attributes.remove(key);
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeLongLP64(handle);
}
- public Object setAttribute(Object key, Object o) {
- return attributes.put(key, o);
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeLongLP64(((Number) value).longValue());
}
-}
+ @Override
+ public int getByteCount() {
+ return NativeObject.SIZE_PTR;
+ }
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeLongType.java b/src/de/intarsys/nativec/type/NativeLongType.java
new file mode 100644
index 0000000..d14f02e
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeLongType.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * The meta class implementation
+ */
+public class NativeLongType extends NativeNumberType {
+
+ protected NativeLongType() {
+ super();
+ }
+
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeLong(handle);
+ }
+
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeLong(((Number) value).longValue());
+ }
+
+ @Override
+ public int getByteCount() {
+ return NativeLong.SIZE_LONG;
+ }
+} \ No newline at end of file
diff --git a/src/de/intarsys/cwt/font/IFont.java b/src/de/intarsys/nativec/type/NativeNumber.java
index fa81715..6483dd8 100644
--- a/src/de/intarsys/cwt/font/IFont.java
+++ b/src/de/intarsys/nativec/type/NativeNumber.java
@@ -27,60 +27,50 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font;
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
/**
- * An abstract font description object.
- *
+ * An abstract superclass for the implementation of number
+ * {@link NativeSimple}.
*/
-public interface IFont {
+public abstract class NativeNumber extends NativeSimple {
/**
- * The font family name
- *
- * @return The font family name
+ * Create a wrapper
*/
- public String getFontFamilyName();
+ protected NativeNumber() {
+ }
- /**
- * The font name. This may deviate from the postscript font name for
- * TrueType fonts.
- *
- * @return The font name.
- */
- public String getFontName();
-
- /**
- * The canonical font name.
- *
- * @return The canonical font name.
- */
- public String getFontNameCanonical();
+ protected NativeNumber(INativeHandle handle) {
+ super(handle);
+ }
/**
- * The postscript font name.
+ * This as a java primitive byte value.
*
- * @return The postscript font name.
+ * @return This as a java primitive byte value.
*/
- public String getFontNamePostScript();
+ public abstract byte byteValue();
/**
- * The referenced {@link IFontProgram}.
+ * This as a java primitive int value.
*
- * @return The referenced {@link IFontProgram}.
+ * @return This as a java primitive int value.
*/
- public IFontProgram getFontProgram();
+ public abstract int intValue();
/**
- * The font style.
+ * This as a java primitive long value.
*
- * @return The font style.
+ * @return This as a java primitive long value.
*/
- public FontStyle getFontStyle();
+ public abstract long longValue();
/**
- * The font type. This is for example "TrueType" or "Type1".
+ * This as a java primitive short value.
*
- * @return The font type.
+ * @return This as a java primitive short value.
*/
- public String getFontType();
+ public abstract short shortValue();
}
diff --git a/src/de/intarsys/cwt/environment/IGraphicsEnvironment.java b/src/de/intarsys/nativec/type/NativeNumberType.java
index 0bc40c0..873d163 100644
--- a/src/de/intarsys/cwt/environment/IGraphicsEnvironment.java
+++ b/src/de/intarsys/nativec/type/NativeNumberType.java
@@ -27,12 +27,14 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.environment;
+package de.intarsys.nativec.type;
/**
- * The graphics environment for the active platform.
- *
+ * The meta class implementation
*/
-public interface IGraphicsEnvironment {
+public class NativeNumberType extends NativeSimpleType {
-}
+ protected NativeNumberType() {
+ super();
+ }
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeObject.java b/src/de/intarsys/nativec/type/NativeObject.java
new file mode 100644
index 0000000..21b85b3
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeObject.java
@@ -0,0 +1,290 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+
+/**
+ * An instance of an external (C memory) represented object. The C-object is
+ * represented using the handle (the pointer to the object in C memory) and its
+ * type {@link INativeType}.
+ * <p>
+ * Supported data types are
+ * <ul>
+ * <li>primitive types (char, byte, int, short, long, String...)</li>
+ * <li>byte buffer</li>
+ * <li>array types</li>
+ * <li>structures</li>
+ * <li>references</li>
+ * </ul>
+ * </p>
+ */
+public abstract class NativeObject implements INativeObject {
+
+ public static final int SIZE_BYTE = 1;
+
+ public static final int SIZE_INT = 4;
+
+ public static final int SHIFT_INT = 2;
+
+ public static final int SIZE_LONGLONG = 8;
+
+ public static final int SHIFT_LONGLONG = 3;
+
+ public static final int SIZE_LONG = NativeInterface.get().longSize();
+
+ public static final int SHIFT_LONG = SIZE_LONG == 4 ? 2 : 3;
+
+ public static final int SIZE_PTR = NativeInterface.get().pointerSize();
+
+ public static final int SIZE_SHORT = 2;
+
+ /** DEBUG flag */
+ public static boolean DEBUG = true;
+
+ /**
+ * The handle to the memory chunk used by this object. While in fact this is
+ * final, Java language semantics does not allow to declare so!
+ * <p>
+ * The handle should only be assigned in the constructor, via parameter or
+ * "allocate".
+ */
+ protected INativeHandle handle;
+
+ /**
+ *
+ */
+ protected NativeObject() {
+ //
+ }
+
+ /**
+ * Create a new NativeObject in C-Memory at pointer "handle". The bytes
+ * belonging to this object may already have been copied from C-Memory and
+ * made available in bytes at location offset.
+ *
+ * @param handle
+ * The pointer in C-memory
+ */
+ protected NativeObject(INativeHandle handle) {
+ this.handle = handle;
+ }
+
+ /**
+ * Manage the objects memory in Java. C memory will be valid at least as
+ * long as we hold a reference to the buffer. C memory is undefined (but not
+ * a memory leak) and may be reclaimed at any time after dropping our
+ * pointer to the buffer.
+ */
+ protected void allocate() {
+ int size = getByteCount();
+ handle = NativeInterface.get().allocate(size);
+ }
+
+ /**
+ * This is a special form of the "createNative" signature, implementing a
+ * "type cast" on the same memory location.
+ *
+ * @param declaration
+ * The new base declaration type.
+ * @return The {@link INativeObject} at the same memory location as this,
+ * but of a different type.
+ */
+ public INativeObject cast(INativeType declaration) {
+ return declaration.createNative(handle);
+ }
+
+ public INativeObject createReference() {
+ NativeReference ref = NativeReference.create(getNativeType());
+ ref.setValue(this);
+ return ref;
+ }
+
+ /**
+ * The byte at index as a native byte.
+ *
+ * @param index
+ * The index of the element to be reported.
+ * @return The element at index as a native byte.
+ */
+ public byte getByte(int index) {
+ return handle.getByte(index);
+ }
+
+ /**
+ * The element at index as an array of native byte with dimension count.
+ * This is a lightweight optimization.
+ *
+ * @param index
+ * The index of the element to be reported.
+ * @return The element at index as an array of native byte with dimension
+ * count.
+ */
+ public byte[] getByteArray(int index, int count) {
+ return handle.getByteArray(index, count);
+ }
+
+ /**
+ * The number of bytes occupied by this.
+ *
+ * @return The number of bytes occupied by this.
+ */
+ public abstract int getByteCount();
+
+ /**
+ * The bytes copied from C-memory that represent this.
+ *
+ * @return The bytes copied from C-memory that represent this.
+ */
+ public byte[] getBytes() {
+ return handle.getByteArray(0, getByteCount());
+ }
+
+ /**
+ * The element at index as a native long. Only the "platform" number of
+ * bytes are read.
+ *
+ * @param index
+ * The index of the element to be reported.
+ * @return The element at index as a native long.
+ */
+ public long getCLong(int index) {
+ return handle.getCLong(index);
+ }
+
+ /**
+ * The element at index as a native int.
+ *
+ * @param index
+ * The index of the element to be reported.
+ * @return The element at index as a native int.
+ */
+ public int getInt(int index) {
+ return handle.getInt(index);
+ }
+
+ /**
+ * The C-Pointer where the associated memory is found.
+ *
+ * @return The C-Pointer where the associated memory is found.
+ */
+ public INativeHandle getNativeHandle() {
+ return handle;
+ }
+
+ public INativeHandle getNativeHandle(int index) {
+ return handle.getNativeHandle(index);
+ }
+
+ /**
+ * The meta information and behavior for the NativeObject.
+ * <p>
+ * There is exactly one meta instance for all NativeObject instances of a
+ * certain type.
+ *
+ * @return The meta information and behavior for the NativeObject.
+ *
+ */
+ abstract public INativeType getNativeType();
+
+ /**
+ * The element at index as a native short. This is a lightweight
+ * optimization.
+ *
+ * @param index
+ * The index of the element to be reported.
+ * @return The element at index as a native short.
+ */
+ public short getShort(int index) {
+ return handle.getShort(index);
+ }
+
+ public String getString(int index) {
+ return handle.getString(index);
+ }
+
+ public String getWideString(int index) {
+ return handle.getWideString(index);
+ }
+
+ /**
+ * Answer <code>true</code> if this is "null". This means the associated
+ * C-pointer is pointing to 0.
+ *
+ * @return Answer <code>true</code> if this is "null".
+ */
+ public boolean isNull() {
+ return handle == null || handle.getAddress() == 0;
+ }
+
+ public void setByte(int index, byte value) {
+ handle.setByte(index, value);
+ }
+
+ public void setByteArray(int index, byte[] value, int valueOffset,
+ int valueCount) {
+ handle.setByteArray(index, value, valueOffset, valueCount);
+ }
+
+ public void setCLong(int index, long value) {
+ handle.setCLong(index, value);
+ }
+
+ public void setInt(int index, int value) {
+ handle.setInt(index, value);
+ }
+
+ public void setNativeHandle(int index, INativeHandle value) {
+ handle.setNativeHandle(index, value);
+ }
+
+ public void setShort(int index, short value) {
+ handle.setShort(index, value);
+ }
+
+ public void setString(int index, String value) {
+ handle.setString(index, value);
+ }
+
+ public void setWideString(int index, String value) {
+ handle.setWideString(index, value);
+ }
+
+ /**
+ * A string for debugging purposes.
+ *
+ * @return A string for debugging purposes.
+ */
+ public String toNestedString() {
+ return toString();
+ }
+
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeReference.java b/src/de/intarsys/nativec/type/NativeReference.java
new file mode 100644
index 0000000..a139d8c
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeReference.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+
+/**
+ * An object representing a reference to another object ("pointer").
+ */
+public class NativeReference extends NativeObject {
+
+ /** The meta class instance */
+ public static final NativeReferenceType META = new NativeReferenceType(
+ NativeVoid.META);
+
+ static {
+ NativeType.register(NativeReference.class, META);
+ }
+
+ public static NativeReference create(INativeType baseType) {
+ NativeReferenceType type = new NativeReferenceType(baseType);
+ return new NativeReference(type);
+ }
+
+ private INativeHandle dereferenceHandle;
+
+ private INativeObject dereferenced;
+
+ private NativeReferenceType type;
+
+ protected NativeReference(NativeReferenceType type) {
+ this.type = type;
+ allocate();
+ }
+
+ protected NativeReference(NativeReferenceType type, INativeHandle handle) {
+ super(handle);
+ this.type = type;
+ handle.setSize(getByteCount());
+ }
+
+ public INativeType getBaseType() {
+ return type.getBaseType();
+ }
+
+ @Override
+ public int getByteCount() {
+ return NativeInterface.get().pointerSize();
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return type;
+ }
+
+ synchronized public Object getValue() {
+ dereferenceHandle = handle.getNativeHandle(0);
+ // check if not yet computed or handle changed
+ if (dereferenced == null
+ || !dereferenced.getNativeHandle().equals(dereferenceHandle)) {
+ dereferenced = type.getBaseType().createNative(
+ dereferenceHandle);
+ }
+ return dereferenced;
+ }
+
+ public void setBaseType(INativeType baseType) {
+ type = NativeReferenceType.create(baseType);
+ dereferenceHandle = null;
+ dereferenced = null;
+ }
+
+ synchronized public void setValue(Object value) {
+ if (value instanceof INativeObject) {
+ INativeHandle valueHandle = ((INativeObject) value)
+ .getNativeHandle();
+ handle.setNativeHandle(0, valueHandle);
+ dereferenceHandle = valueHandle;
+ dereferenced = ((INativeObject) value);
+ } else if (value instanceof INativeHandle) {
+ INativeHandle valueHandle = (INativeHandle) value;
+ handle.setNativeHandle(0, valueHandle);
+ dereferenceHandle = valueHandle;
+ dereferenced = null;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+}
diff --git a/src/de/intarsys/nativec/type/NativeReferenceType.java b/src/de/intarsys/nativec/type/NativeReferenceType.java
new file mode 100644
index 0000000..fdbba2f
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeReferenceType.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+
+/**
+ * A declaration for a slot containing a reference to a native object.
+ */
+public class NativeReferenceType extends NativeType {
+
+ public static NativeReferenceType create(INativeType baseType) {
+ return new NativeReferenceType(baseType);
+ }
+
+ /** The declaration for the dereference slot */
+ private final INativeType baseType;
+
+ /**
+ * Declare a reference to a base type
+ */
+ protected NativeReferenceType(INativeType baseDeclaration) {
+ super();
+ this.baseType = baseDeclaration;
+ }
+
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeReference(this, handle);
+ }
+
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeReference(this);
+ }
+
+ public INativeType getBaseType() {
+ return baseType;
+ }
+
+ @Override
+ public int getByteCount() {
+ return NativeInterface.get().pointerSize();
+ }
+
+ public int getPreferredBoundary() {
+ return NativeInterface.get().pointerSize();
+ }
+
+}
diff --git a/src/de/intarsys/nativec/type/NativeShort.java b/src/de/intarsys/nativec/type/NativeShort.java
new file mode 100644
index 0000000..07da63f
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeShort.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+
+/**
+ * A wrapper for a primitive short.
+ *
+ */
+public class NativeShort extends NativeNumber {
+
+ /** The meta class instance */
+ public static final NativeShortType META = new NativeShortType();
+
+ static {
+ NativeType.register(NativeShort.class, META);
+ }
+
+ static public NativeShort createFromAddress(long address) {
+ return (NativeShort) NativeShort.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeShort() {
+ allocate();
+ }
+
+ protected NativeShort(INativeHandle handle) {
+ super(handle);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeShort(short value) {
+ allocate();
+ setValue(value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeNumber#byteValue()
+ */
+ @Override
+ public byte byteValue() {
+ return (byte) shortValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
+ */
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativePrimitive#getValue()
+ */
+ public Object getValue() {
+ return new Short(shortValue());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeNumber#intValue()
+ */
+ @Override
+ public int intValue() {
+ return shortValue();
+ }
+
+ @Override
+ public long longValue() {
+ return shortValue();
+ }
+
+ public void setValue(Object value) {
+ setValue(((Number) value).shortValue());
+ }
+
+ public void setValue(short value) {
+ handle.setShort(0, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeNumber#shortValue()
+ */
+ @Override
+ public short shortValue() {
+ return handle.getShort(0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(shortValue());
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeShortType.java b/src/de/intarsys/nativec/type/NativeShortType.java
new file mode 100644
index 0000000..15475e6
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeShortType.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * The meta class implementation
+ */
+public class NativeShortType extends NativeNumberType {
+
+ protected NativeShortType() {
+ super();
+ }
+
+ @Override
+ public NativeObject createNative(INativeHandle handle) {
+ return new NativeShort(handle);
+ }
+
+ @Override
+ public NativeObject createNative(Object value) {
+ return new NativeShort(((Number) value).shortValue());
+ }
+
+ @Override
+ public int getByteCount() {
+ return NativeShort.SIZE_SHORT;
+ }
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeSimple.java b/src/de/intarsys/nativec/type/NativeSimple.java
new file mode 100644
index 0000000..6b46a38
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeSimple.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * An abstract superclass for the implementation of primitive
+ * {@link NativeObject} instances. These {@link NativeObject} instances are not
+ * constructed from other {@link NativeObject} instances but implemented
+ * directly in Java, having a fixed size.
+ *
+ */
+public abstract class NativeSimple extends NativeObject {
+
+ /**
+ * Create a wrapper for a NativePrimitive
+ */
+ protected NativeSimple() {
+ }
+
+ protected NativeSimple(INativeHandle handle) {
+ super(handle);
+ handle.setSize(getByteCount());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeObject#getByteCount()
+ */
+ @Override
+ public int getByteCount() {
+ return getNativeType().getByteCount();
+ }
+
+}
diff --git a/src/de/intarsys/cwt/common/IGraphicsObject.java b/src/de/intarsys/nativec/type/NativeSimpleType.java
index dc9de9b..e4782e8 100644
--- a/src/de/intarsys/cwt/common/IGraphicsObject.java
+++ b/src/de/intarsys/nativec/type/NativeSimpleType.java
@@ -27,15 +27,19 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.common;
+package de.intarsys.nativec.type;
/**
- * An abstract super interface for objects used in the rendering process.
- *
+ * The meta class implementation
*/
-public interface IGraphicsObject {
+public class NativeSimpleType extends NativeType {
- public Object getData();
+ protected NativeSimpleType() {
+ super();
+ }
- public void setData(Object data);
-}
+ public int getPreferredBoundary() {
+ return getByteCount();
+ }
+
+} \ No newline at end of file
diff --git a/src/de/intarsys/cwt/font/FontFontMap.java b/src/de/intarsys/nativec/type/NativeStaticStruct.java
index a6e279a..978d891 100644
--- a/src/de/intarsys/cwt/font/FontFontMap.java
+++ b/src/de/intarsys/nativec/type/NativeStaticStruct.java
@@ -27,22 +27,23 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font;
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
/**
+ * A struct with a statically defined type.
*
*/
-public class FontFontMap extends FontMap {
-
- private final IFont font;
+public abstract class NativeStaticStruct extends NativeStruct {
- public FontFontMap(FontMapper mapper, String name, IFont font) {
- super(mapper, name);
- this.font = font;
+ protected NativeStaticStruct() {
+ allocate();
}
- @Override
- public IFont getFont() {
- return font;
+ protected NativeStaticStruct(INativeHandle handle) {
+ super(handle);
+ handle.setSize(getByteCount());
}
+
}
diff --git a/src/de/intarsys/nativec/type/NativeString.java b/src/de/intarsys/nativec/type/NativeString.java
new file mode 100644
index 0000000..810594f
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeString.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+
+/**
+ * A wrapper for a C single byte null terminated string.
+ */
+public class NativeString extends NativeObject {
+
+ /** The meta class instance */
+ public static final NativeStringType META = new NativeStringType();
+
+ static {
+ NativeType.register(NativeString.class, META);
+ }
+
+ static public NativeString createFromAddress(long address) {
+ return (NativeString) NativeString.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ private int size = 0;
+ private NativeStringType type;
+
+ protected NativeString(NativeStringType pType) {
+ type = pType;
+ allocate();
+ }
+
+ protected NativeString(NativeStringType pType, INativeHandle handle) {
+ super(handle);
+ type = pType;
+ if (type.hasByteCount()) {
+ handle.setSize(type.getByteCount());
+ }
+ }
+
+ protected NativeString(NativeStringType pType, String value) {
+ type = pType;
+ if (type.getStringSize() == 0) {
+ this.size = value.length() + 1;
+ }
+ allocate();
+ setValue(value);
+ }
+
+ public NativeString(String value) {
+ this(META, value);
+ }
+
+ @Override
+ public int getByteCount() {
+ if (type.hasByteCount()) {
+ return type.getByteCount();
+ }
+ return size;
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return type;
+ }
+
+ public Object getValue() {
+ return stringValue();
+ }
+
+ public void setValue(Object value) {
+ setValue((String) value);
+ }
+
+ public void setValue(String value) {
+ this.size = value.length() + 1;
+ handle.setString(0, value);
+ }
+
+ /**
+ * The java object corresponding to this.
+ *
+ * @return The java object corresponding to this.
+ */
+ public String stringValue() {
+ return handle.getString(0);
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeStringType.java b/src/de/intarsys/nativec/type/NativeStringType.java
new file mode 100644
index 0000000..b8bc746
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeStringType.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * The meta class implementation
+ */
+public class NativeStringType extends NativeAbstractStringType {
+
+ public static NativeStringType create(int size) {
+ return new NativeStringType(size);
+ }
+
+ protected NativeStringType() {
+ super(1);
+ }
+
+ protected NativeStringType(int size) {
+ super(size, 1);
+ }
+
+ public NativeObject createNative() {
+ return new NativeString(this);
+ }
+
+ @Override
+ public NativeObject createNative(INativeHandle handle) {
+ return new NativeString(this, handle);
+ }
+
+ @Override
+ public NativeObject createNative(Object value) {
+ return new NativeString(this, (String) value);
+ }
+
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeStruct.java b/src/de/intarsys/nativec/type/NativeStruct.java
new file mode 100644
index 0000000..07d726f
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeStruct.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import java.util.Iterator;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * An abstract superclass for the implementation of structured
+ * {@link NativeObject} instances. These objects are built using named slots
+ * with other {@link INativeObject} instances (as opposed to {@link NativeArray},
+ * using indexed slots).
+ *
+ */
+public abstract class NativeStruct extends NativeObject {
+
+ /** The meta class instance */
+ public static final NativeStructType META = new NativeStructType();
+
+ static {
+ NativeType.register(NativeGenericStruct.class, META);
+ }
+
+ protected INativeObject[] values;
+
+ public NativeStruct() {
+ super();
+ }
+
+ public NativeStruct(INativeHandle handle) {
+ super(handle);
+ }
+
+ @Override
+ public int getByteCount() {
+ return getNativeType().getByteCount();
+ }
+
+ /**
+ * The NativeObject at the named slot name.
+ * <p>
+ * The marshalling is delegated to the StructMember in the
+ * StructDeclaration.
+ *
+ * @param name
+ * The name of the slot in the structure.
+ *
+ * @return The NativeObject at the named slot name.
+ */
+ public INativeObject getNativeObject(String name) {
+ return getStructType().getNativeObject(this, name);
+ }
+
+ protected StructMember getStructField(String name) {
+ return getStructType().getField(name);
+ }
+
+ public NativeStructType getStructType() {
+ return (NativeStructType) getNativeType();
+ }
+
+ public Object getValue() {
+ throw new UnsupportedOperationException(
+ "getValue not implemented for NativeStruct");
+ }
+
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException(
+ "getValue not implemented for NativeStruct");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeObject#toNestedString()
+ */
+ @Override
+ public String toNestedString() {
+ return "Struct " + getClass().getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getClass().getName());
+ sb.append("\n");
+ for (Iterator it = getStructType().getFields().iterator(); it.hasNext();) {
+ StructMember field = (StructMember) it.next();
+ sb.append(field.getName());
+ sb.append("=");
+ try {
+ sb.append(getNativeObject(field.getName()).toString());
+ } catch (RuntimeException e) {
+ sb.append("**error**");
+ }
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeStructType.java b/src/de/intarsys/nativec/type/NativeStructType.java
new file mode 100644
index 0000000..58f0f38
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeStructType.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import de.intarsys.nativec.api.NativeInterface;
+
+/**
+ * The meta class implementation
+ */
+public class NativeStructType extends NativeType {
+
+ /**
+ * The boundary where the struct as a member of another struct would want to
+ * be aligned.
+ */
+ private int byteBoundary = 1;
+
+ /**
+ * The offset where theoretically a new member could be placed. Where it
+ * will actually be placed depends on the member itself.
+ */
+ private int byteOffset = 0;
+
+ /** The size in bytes of the member collection */
+ private int byteSize = 0;
+
+ /** The named members of the structure definition */
+ private final Map<String, StructMember> fields = new HashMap<String, StructMember>();
+
+ /**
+ * The number of members in the structure
+ */
+ private int fieldsSize = 0;
+
+ /** Where members should be aligned in native memory */
+ // expecting pointer size to be a reasonable default - have to look that up
+ private int packing = NativeInterface.get().pointerSize();
+
+ protected NativeStructType() {
+ super();
+ }
+
+ protected NativeStructType(Class<?> instanceClass) {
+ super(instanceClass);
+ }
+
+ /**
+ * Declare a new member for the struct.
+ *
+ * @param name
+ * The name of the new member slot.
+ * @param declaration
+ * The type declaration for the slot
+ */
+ public StructMember declare(String name, INativeType declaration) {
+ int size;
+ int boundary;
+
+ size = declaration.getByteCount();
+ boundary = Math.min(declaration.getPreferredBoundary(), packing);
+ byteBoundary = Math.max(byteBoundary, boundary);
+
+ byteOffset = byteOffset - ((byteOffset + boundary - 1) % boundary + 1)
+ + boundary;
+ StructMember field = new StructMember(this, name, fieldsSize++,
+ declaration, byteOffset);
+ fields.put(name, field);
+ byteOffset = byteOffset + size;
+ byteSize = byteOffset;
+ return field;
+ }
+
+ public int getByteBoundary() {
+ return byteBoundary;
+ }
+
+ @Override
+ public int getByteCount() {
+ return getByteSize();
+ }
+
+ /**
+ * The total size of the StructDeclaration.
+ *
+ * @return The total size of the StructDeclaration.
+ */
+ public int getByteSize() {
+ return byteSize;
+ }
+
+ public StructMember getField(String name) {
+ return fields.get(name);
+ }
+
+ /**
+ * The collection of StructMember instances in declaration order.
+ *
+ * @return The collection of StructMember instances in declaration order.
+ */
+ public List<StructMember> getFields() {
+ return new ArrayList<StructMember>(fields.values());
+ }
+
+ public int getFieldsSize() {
+ return fieldsSize;
+ }
+
+ public INativeObject getNativeObject(NativeStruct struct, String name) {
+ StructMember member = fields.get(name);
+ return member.getNativeObject(struct);
+ }
+
+ public int getPacking() {
+ return packing;
+ }
+
+ public int getPreferredBoundary() {
+ return getByteBoundary();
+ }
+
+ public void setPacking(int pPacking) {
+ if (!fields.isEmpty()) {
+ throw new IllegalStateException(
+ "packing must be set before members are declared");
+ }
+ packing = pPacking;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ for (StructMember field : getFields()) {
+ sb.append(field.toString());
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeType.java b/src/de/intarsys/nativec/type/NativeType.java
new file mode 100644
index 0000000..e113fd0
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeType.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * A common superclass for {@link INativeType} implementations
+ */
+public abstract class NativeType implements INativeType {
+
+ /** All known meta classes. */
+ private static Map<Class<?>, INativeType> metaClasses = new HashMap<Class<?>, INativeType>();
+
+ public static synchronized INativeType lookup(Class<?> clazz) {
+ INativeType result = metaClasses.get(clazz);
+ if (result == null) {
+ ClassLoader classLoader;
+
+ clazz.getClasses();
+ classLoader = Thread.currentThread().getContextClassLoader();
+ if (classLoader == null) {
+ classLoader = NativeType.class.getClassLoader();
+ }
+
+ try {
+ Class.forName(clazz.getName(), true, classLoader);
+ } catch (ClassNotFoundException ex) {
+ // ignore
+ }
+ result = metaClasses.get(clazz);
+ }
+ return result;
+ }
+
+ public static synchronized void register(Class<?> clazz, INativeType type) {
+ metaClasses.put(clazz, type);
+ }
+
+ protected NativeType() {
+ //
+ }
+
+ protected NativeType(Class<?> instanceClass) {
+ register(instanceClass, this);
+ }
+
+ /**
+ * Create a Declaration that represents an array of this.
+ *
+ * @return Create a Declaration that represents an array of this.
+ */
+ public INativeType Array(int size) {
+ return new NativeArrayType(this, size);
+ }
+
+ public INativeObject createNative(INativeHandle handle) {
+ throw new IllegalStateException("meta constructor missing");
+ }
+
+ public INativeObject createNative(Object value) {
+ throw new IllegalStateException("meta constructor missing");
+ }
+
+ public int getByteCount() {
+ return 0;
+ }
+
+ /**
+ * Create a Declaration that represents a reference to this.
+ *
+ * @return Create a Declaration that represents a reference to this.
+ */
+ public INativeType Ref() {
+ return new NativeReferenceType(this);
+ }
+}
diff --git a/src/de/intarsys/cwt/awt/image/CwtAwtImage.java b/src/de/intarsys/nativec/type/NativeVoid.java
index 5f2ffde..26da8d3 100644
--- a/src/de/intarsys/cwt/awt/image/CwtAwtImage.java
+++ b/src/de/intarsys/nativec/type/NativeVoid.java
@@ -27,59 +27,62 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.awt.image;
+package de.intarsys.nativec.type;
-import java.awt.image.BufferedImage;
-
-import de.intarsys.cwt.awt.environment.CwtAwtGraphicsContext;
-import de.intarsys.cwt.environment.IGraphicsContext;
-import de.intarsys.cwt.image.IImage;
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+import de.intarsys.nativec.api.NativeTools;
/**
- * The concrete implementation for an {@link IImage} for AWT.
+ * An object representing "void" (nothing)
*/
-public class CwtAwtImage implements IAwtImage {
-
- private BufferedImage awtImage;
+public class NativeVoid extends NativeSimple {
- private int height;
+ /** The meta class instance */
+ public static final NativeVoidType META = new NativeVoidType();
- private int width;
-
- protected CwtAwtImage() {
- super();
- }
+ public static final NativeVoid NULL = (NativeVoid) META
+ .createNative(NativeInterface.NULL);
- public CwtAwtImage(BufferedImage bufferedImage) {
- super();
- awtImage = bufferedImage;
- setWidth(bufferedImage.getWidth());
- setHeight(bufferedImage.getHeight());
+ static {
+ NativeType.register(NativeVoid.class, META);
}
- public void drawFromGraphicsContext(IGraphicsContext graphicsContext,
- float x, float y) {
- CwtAwtGraphicsContext awtGC = (CwtAwtGraphicsContext) graphicsContext;
- awtGC.getGraphics().drawImage(awtImage, (int) x, (int) y, null);
+ static public NativeVoid createFromAddress(long address) {
+ return (NativeVoid) NativeVoid.META.createNative(NativeTools
+ .toHandle(address));
}
- public BufferedImage getBufferedImage() {
- return awtImage;
+ /**
+ * Create a new wrapper instance
+ */
+ public NativeVoid() {
+ allocate();
}
- public int getHeight() {
- return height;
+ protected NativeVoid(INativeHandle handle) {
+ super(handle);
}
- public int getWidth() {
- return width;
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
+ */
+ @Override
+ public INativeType getNativeType() {
+ return META;
}
- protected void setHeight(int paramHeight) {
- height = paramHeight;
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativePrimitive#getValue()
+ */
+ public Object getValue() {
+ return null;
}
- protected void setWidth(int paramWidth) {
- width = paramWidth;
+ public void setValue(Object value) {
}
}
diff --git a/src/de/intarsys/cwt/font/FontAliasMap.java b/src/de/intarsys/nativec/type/NativeVoidType.java
index 64e1101..f585a9c 100644
--- a/src/de/intarsys/cwt/font/FontAliasMap.java
+++ b/src/de/intarsys/nativec/type/NativeVoidType.java
@@ -27,25 +27,31 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-package de.intarsys.cwt.font;
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
/**
- *
+ * The meta class implementation
*/
-public class FontAliasMap extends FontMap {
- final private String alias;
+public class NativeVoidType extends NativeSimpleType {
- public FontAliasMap(FontMapper mapper, String name, String alias) {
- super(mapper, name);
- this.alias = alias;
+ protected NativeVoidType() {
+ super();
}
- public String getAlias() {
- return alias;
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeVoid(handle);
+ }
+
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeVoid();
}
@Override
- public IFont getFont() {
- return getMapper().lookupFont(getAlias());
+ public int getByteCount() {
+ return 0;
}
-}
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeWideString.java b/src/de/intarsys/nativec/type/NativeWideString.java
new file mode 100644
index 0000000..55a1886
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeWideString.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+
+/**
+ * A wrapper for a C wide (double byte) string.
+ */
+public class NativeWideString extends NativeObject {
+
+ /** The meta class instance */
+ public static final NativeWideStringType META = new NativeWideStringType();
+
+ static {
+ NativeType.register(NativeWideString.class, META);
+ }
+
+ static public NativeWideString createFromAddress(long address) {
+ return (NativeWideString) NativeWideString.META
+ .createNative(NativeTools.toHandle(address));
+ }
+
+ private int size = 0;
+ private NativeWideStringType type;
+
+ protected NativeWideString(NativeWideStringType pType) {
+ type = pType;
+ allocate();
+ }
+
+ protected NativeWideString(NativeWideStringType pType, INativeHandle handle) {
+ super(handle);
+ type = pType;
+ if (type.hasByteCount()) {
+ handle.setSize(type.getByteCount());
+ }
+ }
+
+ protected NativeWideString(NativeWideStringType pType, String value) {
+ type = pType;
+ if (type.getStringSize() == 0) {
+ size = value.length() + 1;
+ size = size << 1;
+ }
+ allocate();
+ setValue(value);
+ }
+
+ public NativeWideString(String value) {
+ this(META, value);
+ }
+
+ @Override
+ public int getByteCount() {
+ if (type.hasByteCount()) {
+ return type.getByteCount();
+ }
+ return size;
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return type;
+ }
+
+ public Object getValue() {
+ return stringValue();
+ }
+
+ public void setValue(Object value) {
+ setValue((String) value);
+ }
+
+ public void setValue(String value) {
+ size = value.length() + 1;
+ size = size << 1;
+ handle.setWideString(0, value);
+ }
+
+ /**
+ * The java object corresponding to this.
+ *
+ * @return The java object corresponding to this.
+ */
+ public String stringValue() {
+ return handle.getWideString(0);
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeWideStringType.java b/src/de/intarsys/nativec/type/NativeWideStringType.java
new file mode 100644
index 0000000..9c4f1bd
--- /dev/null
+++ b/src/de/intarsys/nativec/type/NativeWideStringType.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * The meta class implementation
+ */
+public class NativeWideStringType extends NativeAbstractStringType {
+
+ public static NativeWideStringType create(int size) {
+ return new NativeWideStringType(size);
+ }
+
+ protected NativeWideStringType() {
+ super(2);
+ }
+
+ protected NativeWideStringType(int size) {
+ super(size, 2);
+ }
+
+ public NativeObject createNative() {
+ return new NativeWideString(this);
+ }
+
+ @Override
+ public NativeObject createNative(INativeHandle handle) {
+ return new NativeWideString(this, handle);
+ }
+
+ @Override
+ public NativeObject createNative(Object value) {
+ return new NativeWideString(this, (String) value);
+ }
+
+} \ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/StructMember.java b/src/de/intarsys/nativec/type/StructMember.java
new file mode 100644
index 0000000..da450f8
--- /dev/null
+++ b/src/de/intarsys/nativec/type/StructMember.java
@@ -0,0 +1,365 @@
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+
+/**
+ * A field definition within a {@link NativeStructType}.
+ */
+public class StructMember {
+
+ /** the members declaration */
+ private final INativeType memberType;
+
+ /** The members name */
+ protected final String name;
+
+ /** the index of the member within the struct */
+ protected final int index;
+
+ /** The offset of the declaration within its structure */
+ private final int offset;
+
+ /** the definition context of the member */
+ private final NativeStructType structType;
+
+ /**
+ * Create a slot with name "name" and the declaration "memberDeclaration"
+ */
+ protected StructMember(NativeStructType structType, String name, int index,
+ INativeType memberType, int offset) {
+ super();
+ this.structType = structType;
+ this.name = name;
+ this.index = index;
+ this.memberType = memberType;
+ this.offset = offset;
+ }
+
+ /**
+ * Performance shortcut to access "byte" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public byte getByte(NativeStruct struct, int index) {
+ return struct.handle.getByte(offset + index);
+ }
+
+ /**
+ * Performance shortcut to access "byte[]" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public byte[] getByteArray(NativeStruct struct, int index, int count) {
+ return struct.handle.getByteArray(offset + index, count);
+ }
+
+ /**
+ * Performance shortcut to access "platform sized long" in the struct
+ * member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public long getCLong(NativeStruct struct, int index) {
+ return struct.handle.getCLong(offset + index);
+ }
+
+ /**
+ * Performance shortcut to access "int" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public int getInt(NativeStruct struct, int index) {
+ return struct.handle.getInt(offset + index);
+ }
+
+ /**
+ * Performance shortcut to access "long" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public long getLong(NativeStruct struct, int index) {
+ return struct.handle.getLong(offset + index);
+ }
+
+ /**
+ * The type declaration of the slot.
+ *
+ * @return The type declaration of the slot.
+ */
+ protected INativeType getMemberType() {
+ return memberType;
+ }
+
+ /**
+ * The slots name.
+ *
+ * @return The slots name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Performance shortcut to access "INativeHandle" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public INativeHandle getNativeHandle(NativeStruct struct, int index) {
+ return struct.handle.getNativeHandle(offset + index);
+ }
+
+ synchronized public INativeObject getNativeObject(NativeStruct struct) {
+ if (struct.values == null) {
+ struct.values = new INativeObject[structType.getFieldsSize()];
+ }
+ INativeObject result = struct.values[index];
+ if (result == null) {
+ result = memberType.createNative(struct.getNativeHandle().offset(
+ offset));
+ struct.values[this.index] = result;
+ }
+ return result;
+ }
+
+ /**
+ * The offset of the slot relative to the StructDeclaration.
+ *
+ * @return The offset of the slot relative to the StructDeclaration.
+ */
+ protected int getOffset() {
+ return offset;
+ }
+
+ /**
+ * Performance shortcut to access "short" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public short getShort(NativeStruct struct, int index) {
+ return struct.handle.getShort(offset + index);
+ }
+
+ /**
+ * Performance shortcut to access "String" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public String getString(NativeStruct struct, int index) {
+ return struct.handle.getString(offset + index);
+ }
+
+ public Object getValue(NativeStruct struct) {
+ return getNativeObject(struct).getValue();
+ }
+
+ /**
+ * Performance shortcut to access "String" (from wide characters) in the
+ * struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public String getWideString(NativeStruct struct, int index) {
+ return struct.handle.getWideString(offset + index);
+ }
+
+ /**
+ * Performance shortcut to access "byte" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setByte(NativeStruct struct, int index, byte value) {
+ struct.handle.setByte(offset + index, value);
+ }
+
+ /**
+ * Performance shortcut to access "byte[]" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setByteArray(NativeStruct struct, int index, byte[] value,
+ int valueOffset, int valueCount) {
+ struct.handle.setByteArray(offset + index, value, valueOffset,
+ valueCount);
+ }
+
+ /**
+ * Performance shortcut to access "platform sized long" in the struct
+ * member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setCLong(NativeStruct struct, int index, long value) {
+ struct.handle.setCLong(offset + index, value);
+ }
+
+ /**
+ * Performance shortcut to access "int" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setInt(NativeStruct struct, int index, int value) {
+ struct.handle.setInt(offset + index, value);
+ }
+
+ /**
+ * Performance shortcut to access "long" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setLong(NativeStruct struct, int index, long value) {
+ struct.handle.setLong(offset + index, value);
+ }
+
+ /**
+ * Performance shortcut to access "INativeHandle" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setNativeHandle(NativeStruct struct, int index,
+ INativeHandle value) {
+ struct.handle.setNativeHandle(offset + index, value);
+ }
+
+ /**
+ * Performance shortcut to access "short" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setShort(NativeStruct struct, int index, short value) {
+ struct.handle.setShort(offset + index, value);
+ }
+
+ /**
+ * Performance shortcut to access "String" in the struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setString(NativeStruct struct, int index, String value) {
+ struct.handle.setString(offset + index, value);
+ }
+
+ public void setValue(NativeStruct struct, Object value) {
+ getNativeObject(struct).setValue(value);
+ }
+
+ /**
+ * Performance shortcut to access "String" (from wide characters) in the
+ * struct member.
+ *
+ * @param struct
+ * The container struct instance
+ * @param index
+ * The memory offset from the struct member base
+ * @return
+ */
+ public void setWideString(NativeStruct struct, int index, String value) {
+ struct.handle.setWideString(offset + index, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "[" + getName() + "]";
+ }
+}
diff --git a/src/de/intarsys/nativec/type/package.html b/src/de/intarsys/nativec/type/package.html
new file mode 100644
index 0000000..4158682
--- /dev/null
+++ b/src/de/intarsys/nativec/type/package.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+Here you find the data types and data structures for native c.
+</body>
+</html> \ No newline at end of file
diff --git a/src/overview.html b/src/overview.html
index 38c85c2..619b5c0 100644
--- a/src/overview.html
+++ b/src/overview.html
@@ -1,12 +1,12 @@
<html>
<body>
-This is a window toolkit and basic rendering abstraction layer.
+This is a generic native code wrapper.
<h2><a name="Content">Content</a></h2>
<ol type="a" >
<li><a href="#Overview">Overview</a></li>
- <li><a href="#Implementation">Implementation Details</a></li>
+ <li><a href="#Manual">Manual</a></li>
<li><a href="#License">License</a></li>
<li><a href="#Support">Service and support</a></li>
</ol>
@@ -16,8 +16,364 @@ This is a window toolkit and basic rendering abstraction layer.
<h2><a name="Overview">Overview</a></h2>
+This is "another" JNI wrapping library, but in some regards quite different.
+
+<p>
+The real memory / JNI access semantics is delegated to some concrete service implementation.
+Actually we dont'tprovide one of our own, the default implementation we use is JNA.
+
+<p>
+The real strength of this library is its high level model of JNI access, allowing more easy and
+understandable API's. We feel that at this point most of the candidates we reviewed
+are quite poor or hard to understand.
+
+<p>
+The design goals were as follows:
+
+<ul>
+<li>Provide access to all levels of a native interface. As we can not forsee what different libaries and
+systems will work together, access is provided from bottom up using the plain address as the least common
+denominator. </li>
+<li>Provide clean abstractions</li>
+<li>Differentiate between a "pointer" or "memory handle" and the data semantics. This allows to work
+as well using plain pointer arithmetics as object state access. </li>
+</ul>
+
+<p>
+The high level model provides the following abstractions:
+
+<ul>
+<li>Interface
+</li>
+The concrete implementation for accessing JNI. This interface is quite small and allows for
+the adaption of many JNI libraries out there. It should not be to hard to create one of your own.
+<li>Library
+</li>
+The loadable library providing state and behavior.
+<li>Function
+</li>
+The behavior part of the library, accepting parameters and return results.
+<li>Handle
+</li>
+An abstraction of a pointer, without any data specific features. This could be viewed
+as a plain wrapper around an address, another representation for "void *".
+<li>Object
+</li>
+The data referenced by a handle (or pointer). The object deals with the bytes referenced by the handle.
+
+The object defines the semantics of how to interpret the memory referenced by the handle.
+The handle defines "where" to find data, the object defines "what" data you will find there -
+it deals only with the "dereferenced" part of the handle.
+
+On the C side, the object is always represented by the handle / pointer. This means that an object
+is always used and forwarded by reference. Do not confuse this with the handling on primitive
+types. In this code snippet
+
+<pre>
+int a;
+NativeInt b = new NativeInt();
+...
+int result = function.invoke(Integer.class, a, b);
+...
+</pre>
+
+the function is called using the value of "a" and a pointer to "b".
+</li>
+
+</ul>
+
+<p>
+This library currently does not provide any convenience for some aspects of
+native calls, for example
+
+<ul>
+<li>primitive arrays</li>
+<li>float / double support</li>
+<li>String encodings</li>
+<li>callbacks</li>
+<li>maybe other features we didn't need until now and so are not aware of..</li>
+</ul>
+
+The underlying infrastructure (JNA) may handle such constructs, but as long as the
+semantics is not defined on this library level, you should expect unportable
+behavior.
+
+We propose, even if not convenient, to express all call semantics using documented
+features only. Feel free to ask for the inclusion of more library features.
+
+<h2><a name="Manual">Manual</a></h2>
+
+<h3>Common scenarios</h3>
+
+<h4>Call functions with primitive types</h4>
+
+The most simple calls use only primitive types. These are mapped by the "invoke" itself
+using builtin rules to target the C types.
+
+<p>
+The C part may look like this:
+
+<pre>
+int intValue;
+float floatValue;
+...
+int result = function(intValue, floatValue);
+...
+</pre>
+
+<p>
+An equivalent call from Java would look like:
+
+<pre>
+int intValue;
+float floatValue;
+...
+int result = function.invoke(Integer.class, intValue, floatValue);
+...
+...
+</pre>
+
+This seems straightforward....
+
+<h4>Call functions with String parameters</h4>
+
+The first problems are expected when dealing with strings or char* on the C side. But
+no problem here:
+
+<p>
+The C part may look like this:
+
+<pre>
+char* string = "test";
+...
+int result = function(string);
+...
+</pre>
+
+<p>
+An equivalent call from Java would look like:
+
+<pre>
+String string = "test";
+...
+int result = function.invoke(Integer.class, string);
+...
+</pre>
+
+String semantics are handled internally. Even the platform wide character features
+can be accessed quite easy - simply wrap the String in a "WideString" to indicate the
+special treatment on invocation marshalling.
+
+<pre>
+String string = "test";
+WideString wideString = new WideString(string);
+...
+int result = function.invoke(Integer.class, wideString);
+...
+</pre>
+
+In much the same way you can request a wide string conversion on the result.
+
+<pre>
+...
+WideString result = function.invoke(WideString.class);
+String string = result.toString();
+...
+</pre>
+
+<h4>Call with parameters "by reference" (out parameters)</h4>
+
+Other functions return values via "out" parameters, via references to C memory.
+
+<p>
+The C part may look like this:
+
+<pre>
+int value;
+
+...
+int result = function(&value);
+if (value == 42) {
+ ...
+}
+...
+</pre>
+
+<p>
+An equivalent call from Java would look like:
+
+<pre>
+NativeInt value = new NativeInt();
+
+int result = function.invoke(Integer.class, value);
+if (value.intValue() == 42) {
+ ...
+}
+...
+</pre>
+
+The NativeObject is allocated in C memory and forwarded "by reference".
+
+This call pattern stays the same regardless of the complexity of the NativeObject - so this is
+the call for your Java side definition of the C struct:
+
+<pre>
+// allocates memory for the struct in C
+MyStruct value = new MyStruct();
+
+// call function with a pointer to the new struct
+int result = function.invoke(Integer.class, value);
+...
+</pre>
+
+<h4>Wrapping pointers returned from out parameters</h4>
+
+With C you find quite often a pointer to a newly create memory chunk returned via
+an out parameter.
+
+<pre>
+my_struct *value;
+...
+function(&value);
+int a = value->a;
+...
+</pre>
+
+This is one of the rare occasions you will deal with the "NativeReference" directly.
+If we follow exactly the pattern we have used so far we get:
+
+<pre>
+// allocate memory for holding a pointer to a struct
+NativeReference ptrValue = new NativeReference(MyStruct.META);
+// call the function with the pointer to the pointer
+int result = function.invoke(Integer.class, ptrValue);
+// dereference the result...
+MyStruct value = (MyStruct)ptrValue.getValue();
+</pre>
+
+Here's a common pattern to manage "transparent" handles that do not designate data
+structures you should deal with - for sure you can declare a NativeVoid subclass
+of you own for better readability or to add methods.
+
+<pre>
+// allocate memory for holding a void pointer
+NativeReference ptrValue = new NativeReference(NativeVoid.META);
+// call the function with the pointer to the pointer
+int result = function.invoke(Integer.class, value);
+// dereference the result...
+NativeVoid value = (NativeVoid)ptrValue.getValue();
+</pre>
+
+<h4>Wrapping a pointer returned as function result</h4>
+
+Many functions return handles to newly created objects. Wrapping this result to the
+INativeObject framework is simply a matter of declaration:
+
+<pre>
+NativeVoid result = function.invoke(NativeVoid.class, ...);
+</pre>
+
+You have just wrapped a "void *" (void pointer)! Notice how you "hide" the C reference or pointer
+semantics. The less you think about it, the more it is intuitive :-). Using this code
+will return "null" in case of a "0" address.
+
+<p>
+NativeVoid is a "stateless" object, declaring to be of size "0". This is often the case with transparent handles
+to some proprietary / private information. Only the handle itself is used to manipulate state via the associated
+library functions.
+
+<p>
+In much the same way you can create a NativeStruct instances, holding public state information
+and allowing easy access to it.
+
+<p>
+Assume you have defined a NativeStruct subclass "MyStruct" of any memory layout. The above
+code sequence changes to
+
+<pre>
+MyStruct structObj = function.invoke(MyStruct.class, ...);
+</pre>
+
+Behind this code is a simple two step process. You can do it manually if the default is
+not exactly what you want, for example in some cases where an address of "-1" means failure.
+
+<ul>
+<li>Create the INativeHandle wrapper. This object represents a memory address and implements
+some access primitives</li>
+<li>Use the INativeHandle to build the INativeObject wrapper that is situated at this memory location.
+This can be any of the INativeObject subclasses, such as a primitive, composite or even void representation.</li>
+</ul>
+
+<pre>
+int address = function.invoke(Integer.class, ...);
+if (address == 0) {
+ return null;
+}
+INativeHandle handle = NativeInterface.get().createHandle(address);
+return NativeVoid.META.createNative(handle);
+</pre>
+
+<p>
+The pointer, represented by the INativeHandle is wrapped by a NativeObject which is
+what is referenced by the pointer.
+
+<h4>Primitive arrays and buffers</h4>
+
+You can call a native function using primitive arrays the same way as using plain primitives.
+The basic marshalling will map the values in both direction, so you see C side changes in the
+Java array directly.
+
+Conceptually you should treat such a call as follows:
+The memory is managed by the library. Upon entry, memory is allocated in C address space, the data is copied.
+The C function is called with the pointer to the newly allocated memory. After
+termination of the function, memory is copied back to Java address space, and the
+newly allocated memory is discarded. Access to the memory in C address space is no longer valid!
+
+So, if you want to provide a buffer to C for use even outside the function call this
+is not the correct way! You must use NativeObject instances, for example NativeBuffer,
+to force C memory allocation resident in memory (controlled by your application).
+
+To optimize the marshalling between Java and C you may use direct "ByteBuffer" objects. Using
+this objects marshalling MAY be optimized by the underlying implementation to share memory
+between Java and C.
+
+In any case you may use a NativeBuffer and access the memory allocated in heap space from both
+sides. NativeBuffer can be seen as an explicit equivalent to a DirectBuffer.
+
<h2><a name="License">License</a></h2>
+<pre>
+/*
+ * Copyright (c) 2008, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+</pre>
+
<h2><a name="Service & Support">Service & Support</a></h2>
If you need further support, feel free to contact us.