mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-13 18:48:18 +00:00
Font export (TTF)
jar path updated in libsrc projects
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
trunk/lib/ttf.jar
Normal file
BIN
trunk/lib/ttf.jar
Normal file
Binary file not shown.
@@ -51,8 +51,7 @@
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
@@ -54,6 +54,7 @@ is divided into following sections:
|
||||
<property file="nbproject/project.properties"/>
|
||||
</target>
|
||||
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
|
||||
<property name="platform.java" value="${java.home}/bin/java"/>
|
||||
<available file="${manifest.file}" property="manifest.available"/>
|
||||
<condition property="splashscreen.available">
|
||||
<and>
|
||||
@@ -71,10 +72,11 @@ is divided into following sections:
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="manifest.available+main.class">
|
||||
<condition property="profile.available">
|
||||
<and>
|
||||
<isset property="manifest.available"/>
|
||||
<isset property="main.class.available"/>
|
||||
<isset property="javac.profile"/>
|
||||
<length length="0" string="${javac.profile}" when="greater"/>
|
||||
<matches pattern="1\.[89](\..*)?" string="${javac.source}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="do.archive">
|
||||
@@ -91,12 +93,6 @@ is divided into following sections:
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="manifest.available+main.class+mkdist.available">
|
||||
<and>
|
||||
<istrue value="${manifest.available+main.class}"/>
|
||||
<isset property="do.mkdist"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="do.archive+manifest.available">
|
||||
<and>
|
||||
<isset property="manifest.available"/>
|
||||
@@ -115,24 +111,12 @@ is divided into following sections:
|
||||
<istrue value="${do.archive}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="do.archive+manifest.available+main.class">
|
||||
<condition property="do.archive+profile.available">
|
||||
<and>
|
||||
<istrue value="${manifest.available+main.class}"/>
|
||||
<isset property="profile.available"/>
|
||||
<istrue value="${do.archive}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="manifest.available-mkdist.available">
|
||||
<or>
|
||||
<istrue value="${manifest.available}"/>
|
||||
<isset property="do.mkdist"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="manifest.available+main.class-mkdist.available">
|
||||
<or>
|
||||
<istrue value="${manifest.available+main.class}"/>
|
||||
<isset property="do.mkdist"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="have.tests">
|
||||
<or>
|
||||
<available file="${test.src.dir}"/>
|
||||
@@ -186,7 +170,15 @@ is divided into following sections:
|
||||
</condition>
|
||||
<path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
|
||||
<condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
|
||||
<length length="0" string="${endorsed.classpath}" when="greater"/>
|
||||
<and>
|
||||
<isset property="endorsed.classpath"/>
|
||||
<not>
|
||||
<equals arg1="${endorsed.classpath}" arg2="" trim="true"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
|
||||
<isset property="profile.available"/>
|
||||
</condition>
|
||||
<condition else="false" property="jdkBug6558476">
|
||||
<and>
|
||||
@@ -275,6 +267,7 @@ is divided into following sections:
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||
<compilerarg line="${javac.profile.cmd.line.arg}"/>
|
||||
<compilerarg line="${javac.compilerargs}"/>
|
||||
<compilerarg value="-processorpath"/>
|
||||
<compilerarg path="@{processorpath}:${empty.dir}"/>
|
||||
@@ -314,6 +307,7 @@ is divided into following sections:
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||
<compilerarg line="${javac.profile.cmd.line.arg}"/>
|
||||
<compilerarg line="${javac.compilerargs}"/>
|
||||
<customize/>
|
||||
</javac>
|
||||
@@ -446,7 +440,7 @@ is divided into following sections:
|
||||
</fileset>
|
||||
</union>
|
||||
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
||||
<testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="LZMA" testname="TestNG tests" workingDir="${work.dir}">
|
||||
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="LZMA" testname="TestNG tests" workingDir="${work.dir}">
|
||||
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
||||
<propertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
@@ -837,8 +831,8 @@ is divided into following sections:
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
|
||||
<copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
<copylibs compress="${jar.compress}" excludeFromCopy="${copylibs.excludes}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
|
||||
<fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
|
||||
<manifest>
|
||||
<attribute name="Class-Path" value="${jar.classpath}"/>
|
||||
<customize/>
|
||||
@@ -850,7 +844,7 @@ is divided into following sections:
|
||||
<target name="-init-presetdef-jar">
|
||||
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}">
|
||||
<j2seproject1:fileset dir="${build.classes.dir}"/>
|
||||
<j2seproject1:fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
|
||||
</jar>
|
||||
</presetdef>
|
||||
</target>
|
||||
@@ -966,41 +960,25 @@ is divided into following sections:
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available-mkdist.available">
|
||||
<j2seproject1:jar/>
|
||||
</target>
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class-mkdist.available">
|
||||
<j2seproject1:jar manifest="${manifest.file}"/>
|
||||
</target>
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
|
||||
<j2seproject1:jar manifest="${manifest.file}">
|
||||
<j2seproject1:manifest>
|
||||
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
|
||||
</j2seproject1:manifest>
|
||||
</j2seproject1:jar>
|
||||
<echo level="info">To run this application from the command line without Ant, try:</echo>
|
||||
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
|
||||
<property location="${dist.jar}" name="dist.jar.resolved"/>
|
||||
<pathconvert property="run.classpath.with.dist.jar">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
|
||||
</pathconvert>
|
||||
<echo level="info">java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
|
||||
</target>
|
||||
<target depends="init" if="do.archive" name="-do-jar-with-libraries-create-manifest" unless="manifest.available">
|
||||
<target depends="init" if="do.archive" name="-do-jar-create-manifest" unless="manifest.available">
|
||||
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
|
||||
<touch file="${tmp.manifest.file}" verbose="false"/>
|
||||
</target>
|
||||
<target depends="init" if="do.archive+manifest.available" name="-do-jar-with-libraries-copy-manifest">
|
||||
<target depends="init" if="do.archive+manifest.available" name="-do-jar-copy-manifest">
|
||||
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
|
||||
<copy file="${manifest.file}" tofile="${tmp.manifest.file}"/>
|
||||
</target>
|
||||
<target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+main.class.available" name="-do-jar-with-libraries-set-main">
|
||||
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+main.class.available" name="-do-jar-set-mainclass">
|
||||
<manifest file="${tmp.manifest.file}" mode="update">
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
</manifest>
|
||||
</target>
|
||||
<target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-with-libraries-set-splashscreen">
|
||||
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+profile.available" name="-do-jar-set-profile">
|
||||
<manifest file="${tmp.manifest.file}" mode="update">
|
||||
<attribute name="Profile" value="${javac.profile}"/>
|
||||
</manifest>
|
||||
</target>
|
||||
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-set-splashscreen">
|
||||
<basename file="${application.splash}" property="splashscreen.basename"/>
|
||||
<mkdir dir="${build.classes.dir}/META-INF"/>
|
||||
<copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
|
||||
@@ -1008,23 +986,41 @@ is divided into following sections:
|
||||
<attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
|
||||
</manifest>
|
||||
</target>
|
||||
<target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen" if="do.mkdist" name="-do-jar-with-libraries-pack">
|
||||
<target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.mkdist" name="-do-jar-copylibs">
|
||||
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
|
||||
<echo level="info">To run this application from the command line without Ant, try:</echo>
|
||||
<property location="${dist.jar}" name="dist.jar.resolved"/>
|
||||
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
|
||||
</target>
|
||||
<target depends="-do-jar-with-libraries-pack" if="do.archive" name="-do-jar-with-libraries-delete-manifest">
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
|
||||
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
|
||||
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
|
||||
<property location="${dist.jar}" name="dist.jar.resolved"/>
|
||||
<pathconvert property="run.classpath.with.dist.jar">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
|
||||
</pathconvert>
|
||||
<condition else="" property="jar.usage.message" value="To run this application from the command line without Ant, try:${line.separator}${platform.java} -cp ${run.classpath.with.dist.jar} ${main.class}">
|
||||
<isset property="main.class.available"/>
|
||||
</condition>
|
||||
<condition else="debug" property="jar.usage.level" value="info">
|
||||
<isset property="main.class.available"/>
|
||||
</condition>
|
||||
<echo level="${jar.usage.level}" message="${jar.usage.message}"/>
|
||||
</target>
|
||||
<target depends="-do-jar-copylibs" if="do.archive" name="-do-jar-delete-manifest">
|
||||
<delete>
|
||||
<fileset file="${tmp.manifest.file}"/>
|
||||
</delete>
|
||||
</target>
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen,-do-jar-with-libraries-pack,-do-jar-with-libraries-delete-manifest" name="-do-jar-with-libraries"/>
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-do-jar-jar,-do-jar-delete-manifest" name="-do-jar-without-libraries"/>
|
||||
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-do-jar-copylibs,-do-jar-delete-manifest" name="-do-jar-with-libraries"/>
|
||||
<target name="-post-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
|
||||
<target depends="init,compile,-pre-jar,-do-jar-without-libraries,-do-jar-with-libraries,-post-jar" name="-do-jar"/>
|
||||
<target depends="init,compile,-pre-jar,-do-jar,-post-jar" description="Build JAR." name="jar"/>
|
||||
<!--
|
||||
=================
|
||||
EXECUTION SECTION
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
build.xml.data.CRC32=cf8fb9e4
|
||||
build.xml.script.CRC32=b8fc23fa
|
||||
build.xml.stylesheet.CRC32=28e38971@1.50.1.46
|
||||
build.xml.script.CRC32=0d82b5ac
|
||||
build.xml.stylesheet.CRC32=8064a381@1.68.1.46
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=cf8fb9e4
|
||||
nbproject/build-impl.xml.script.CRC32=04ff5368
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46
|
||||
nbproject/build-impl.xml.script.CRC32=35617b72
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=5a01deb7@1.68.1.46
|
||||
|
||||
@@ -22,7 +22,7 @@ debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/LZMA.jar
|
||||
dist.jar=../../lib/LZMA.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
excludes=
|
||||
includes=**
|
||||
|
||||
@@ -24,7 +24,7 @@ debug.test.classpath=\
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/avi.jar
|
||||
dist.jar=../../lib/avi.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
excludes=
|
||||
includes=**
|
||||
|
||||
@@ -24,7 +24,7 @@ debug.test.classpath=\
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/gif.jar
|
||||
dist.jar=../../lib/gif.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
excludes=
|
||||
includes=**
|
||||
|
||||
@@ -24,7 +24,7 @@ debug.test.classpath=\
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/nellymoser.jar
|
||||
dist.jar=../../lib/nellymoser.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
excludes=
|
||||
includes=**
|
||||
|
||||
73
trunk/libsrc/ttf/build.xml
Normal file
73
trunk/libsrc/ttf/build.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="ttf" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project ttf.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="ttf-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
3
trunk/libsrc/ttf/manifest.mf
Normal file
3
trunk/libsrc/ttf/manifest.mf
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
1407
trunk/libsrc/ttf/nbproject/build-impl.xml
Normal file
1407
trunk/libsrc/ttf/nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
trunk/libsrc/ttf/nbproject/genfiles.properties
Normal file
8
trunk/libsrc/ttf/nbproject/genfiles.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=ffc041f7
|
||||
build.xml.script.CRC32=9bce9219
|
||||
build.xml.stylesheet.CRC32=8064a381@1.68.1.46
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=ffc041f7
|
||||
nbproject/build-impl.xml.script.CRC32=b06e210e
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=5a01deb7@1.68.1.46
|
||||
75
trunk/libsrc/ttf/nbproject/project.properties
Normal file
75
trunk/libsrc/ttf/nbproject/project.properties
Normal file
@@ -0,0 +1,75 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=ttf
|
||||
application.vendor=Jindra
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=../../lib/ttf.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
||||
javac.deprecation=false
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.7
|
||||
javac.target=1.7
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=fontatest.FontaTest
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
15
trunk/libsrc/ttf/nbproject/project.xml
Normal file
15
trunk/libsrc/ttf/nbproject/project.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>ttf</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
86
trunk/libsrc/ttf/src/fontastic/FContour.java
Normal file
86
trunk/libsrc/ttf/src/fontastic/FContour.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package fontastic;
|
||||
|
||||
/**
|
||||
* Fontastic
|
||||
* A font file writer to create TTF and WOFF (Webfonts).
|
||||
* http://code.andreaskoller.com/libraries/fontastic
|
||||
*
|
||||
* Copyright (C) 2013 Andreas Koller http://andreaskoller.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @author Andreas Koller http://andreaskoller.com
|
||||
* @modified 06/19/2013
|
||||
* @version 0.4 (4)
|
||||
*/
|
||||
|
||||
import fontastic.FPoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class FContour
|
||||
*
|
||||
* Stores a contour (list of FPoint).
|
||||
*
|
||||
*/
|
||||
public class FContour {
|
||||
|
||||
List<FPoint> points;
|
||||
|
||||
FContour() {
|
||||
this.points = new ArrayList<>();
|
||||
}
|
||||
|
||||
FContour(PVector[] points) {
|
||||
this.points = new ArrayList<>();
|
||||
for (PVector p : points) {
|
||||
this.points.add(new FPoint(p));
|
||||
}
|
||||
}
|
||||
|
||||
FContour(PVector[] points, PVector[] controlpoints) {
|
||||
this.points = new ArrayList<>();
|
||||
for (int i=0; i<points.length; i++) {
|
||||
this.points.add(new FPoint(points[i], controlpoints[i] ));
|
||||
}
|
||||
}
|
||||
|
||||
FContour(FPoint[] points) {
|
||||
this.points = new ArrayList<>();
|
||||
for (int i=0; i<points.length; i++) {
|
||||
this.points.add(points[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public List<FPoint> getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public FPoint[] getPointsArray() {
|
||||
FPoint[] pointsArray = points.toArray(new FPoint[points.size()]);
|
||||
return pointsArray;
|
||||
}
|
||||
|
||||
public void setPoints(PVector[] points) {
|
||||
this.points = new ArrayList<>();
|
||||
for (PVector p : points) {
|
||||
this.points.add(new FPoint(p));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
116
trunk/libsrc/ttf/src/fontastic/FGlyph.java
Normal file
116
trunk/libsrc/ttf/src/fontastic/FGlyph.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package fontastic;
|
||||
|
||||
/**
|
||||
* Fontastic
|
||||
* A font file writer to create TTF and WOFF (Webfonts).
|
||||
* http://code.andreaskoller.com/libraries/fontastic
|
||||
*
|
||||
* Copyright (C) 2013 Andreas Koller http://andreaskoller.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @author Andreas Koller http://andreaskoller.com
|
||||
* @modified 06/19/2013
|
||||
* @version 0.4 (4)
|
||||
*/
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class FGlyph
|
||||
*
|
||||
* Stores a glyph with all its properties.
|
||||
*
|
||||
*/
|
||||
public class FGlyph {
|
||||
|
||||
private char glyphChar;
|
||||
private List<FContour> contours;
|
||||
private int advanceWidth = 512;
|
||||
|
||||
FGlyph(char c) {
|
||||
glyphChar = c;
|
||||
this.contours = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addContour() {
|
||||
contours.add(new FContour());
|
||||
}
|
||||
|
||||
public void addContour(PVector[] points) {
|
||||
contours.add(new FContour(points));
|
||||
}
|
||||
|
||||
public void addContour(FPoint[] points) {
|
||||
contours.add(new FContour(points));
|
||||
}
|
||||
|
||||
public void addContour(PVector[] points, PVector[] controlPoints) {
|
||||
contours.add(new FContour(points, controlPoints));
|
||||
}
|
||||
|
||||
public void addContour(FContour contour) {
|
||||
contours.add(contour);
|
||||
}
|
||||
|
||||
public void setAdvanceWidth(int advanceWidth) {
|
||||
this.advanceWidth = advanceWidth;
|
||||
}
|
||||
|
||||
public char getGlyphChar() {
|
||||
return glyphChar;
|
||||
}
|
||||
|
||||
public int getAdvanceWidth() {
|
||||
return advanceWidth;
|
||||
}
|
||||
|
||||
public List<FContour> getContours() {
|
||||
return contours;
|
||||
}
|
||||
|
||||
public FContour[] getContoursArray() {
|
||||
FContour[] contoursArray = contours.toArray(new FContour[contours.size()]);
|
||||
return contoursArray;
|
||||
}
|
||||
|
||||
public FContour getContour(int index) {
|
||||
return contours.get(index);
|
||||
}
|
||||
|
||||
public int getContourCount() {
|
||||
return contours.size();
|
||||
}
|
||||
|
||||
public void setContour(int index, PVector[] points) {
|
||||
contours.set(index, new FContour(points));
|
||||
}
|
||||
|
||||
public void setContour(int index, FPoint[] points) {
|
||||
contours.set(index, new FContour(points));
|
||||
}
|
||||
|
||||
public void setContour(int index, FContour contour) {
|
||||
contours.set(index, contour);
|
||||
}
|
||||
|
||||
public void clearContours() {
|
||||
this.contours.clear();
|
||||
}
|
||||
|
||||
}
|
||||
82
trunk/libsrc/ttf/src/fontastic/FPoint.java
Normal file
82
trunk/libsrc/ttf/src/fontastic/FPoint.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package fontastic;
|
||||
|
||||
/**
|
||||
* Fontastic
|
||||
* A font file writer to create TTF and WOFF (Webfonts).
|
||||
* http://code.andreaskoller.com/libraries/fontastic
|
||||
*
|
||||
* Copyright (C) 2013 Andreas Koller http://andreaskoller.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @author Andreas Koller http://andreaskoller.com
|
||||
* @modified 06/19/2013
|
||||
* @version 0.4 (4)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class FPoint extends PVector
|
||||
*
|
||||
* Stores a point with x and y coordinates and optional PVector controlPoint1 and controlPoint2.
|
||||
*
|
||||
*/
|
||||
public class FPoint extends PVector {
|
||||
|
||||
public PVector controlPoint;
|
||||
|
||||
private boolean hasControlPoint;
|
||||
|
||||
public FPoint() {
|
||||
}
|
||||
|
||||
public FPoint(PVector point) {
|
||||
this.x = point.x;
|
||||
this.y = point.y;
|
||||
this.hasControlPoint = false;
|
||||
}
|
||||
|
||||
public FPoint(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.hasControlPoint = false;
|
||||
}
|
||||
|
||||
|
||||
public FPoint(PVector point, PVector controlPoint) {
|
||||
this.x = point.x;
|
||||
this.y = point.y;
|
||||
this.controlPoint = controlPoint;
|
||||
this.hasControlPoint = true;
|
||||
}
|
||||
|
||||
public void setControlPoint(PVector controlPoint1) {
|
||||
this.controlPoint = controlPoint1;
|
||||
this.hasControlPoint = true;
|
||||
}
|
||||
|
||||
public void setControlPoint(float x, float y) {
|
||||
this.controlPoint = new PVector(x,y);
|
||||
this.hasControlPoint = true;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasControlPoint1() {
|
||||
return hasControlPoint;
|
||||
}
|
||||
|
||||
}
|
||||
518
trunk/libsrc/ttf/src/fontastic/Fontastic.java
Normal file
518
trunk/libsrc/ttf/src/fontastic/Fontastic.java
Normal file
@@ -0,0 +1,518 @@
|
||||
/**
|
||||
* Fontastic A font file writer to create TTF
|
||||
* http://code.andreaskoller.com/libraries/fontastic
|
||||
*
|
||||
* Copyright (C) 2013 Andreas Koller http://andreaskoller.com
|
||||
*
|
||||
* Uses: doubletype http://sourceforge.net/projects/doubletype/ for TTF creation
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation; either version 2.1 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @author Andreas Koller http://andreaskoller.com
|
||||
* @modified 03/16/2014 JPEXS - removed Woff
|
||||
* @version 0.4 (4)
|
||||
*/
|
||||
package fontastic;
|
||||
|
||||
import org.doubletype.ossa.*;
|
||||
import org.doubletype.ossa.module.*;
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* Fontastic A font file writer to create TTF and WOFF (Webfonts).
|
||||
* http://code.andreaskoller.com/libraries/fontastic
|
||||
*
|
||||
*/
|
||||
public class Fontastic {
|
||||
|
||||
private org.doubletype.ossa.module.TypefaceFile typeface;
|
||||
private org.doubletype.ossa.Engine m_engine;
|
||||
|
||||
private String fontname;
|
||||
|
||||
private List<FGlyph> glyphs;
|
||||
|
||||
private int advanceWidth = 512;
|
||||
|
||||
private File ttffile;
|
||||
private File outfile;
|
||||
private File tempDir;
|
||||
|
||||
public final static String VERSION = "0.4";
|
||||
|
||||
/**
|
||||
* Uppercase alphabet 26 characters *
|
||||
*/
|
||||
public final static char alphabet[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z'};
|
||||
/**
|
||||
* Lowercase alphabet 26 characters *
|
||||
*/
|
||||
public final static char alphabetLc[] = {'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
|
||||
't', 'u', 'v', 'w', 'x', 'y', 'z'};
|
||||
|
||||
/**
|
||||
* Return the version of the library.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String version() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @example Fontastic f = new Fontastic(this, "MyFont");
|
||||
*
|
||||
* @param theParent Your processing sketch (this).
|
||||
* @param fontname Font name
|
||||
*
|
||||
*/
|
||||
public Fontastic(String fontname, File outfile) throws IOException {
|
||||
this.fontname = fontname;
|
||||
this.outfile = outfile;
|
||||
intitialiseFont();
|
||||
this.glyphs = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the font name.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getFontname() {
|
||||
return fontname;
|
||||
}
|
||||
|
||||
private static File createTempDirectory()
|
||||
throws IOException {
|
||||
File temp;
|
||||
temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
|
||||
|
||||
|
||||
|
||||
if (!(temp.delete())) {
|
||||
throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (!(temp.mkdirs())) {
|
||||
throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
|
||||
}
|
||||
|
||||
return (temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initialises a new typeface. Font data is put into sketch
|
||||
* folder data/fontname.
|
||||
*/
|
||||
private void intitialiseFont() throws IOException {
|
||||
|
||||
tempDir = createTempDirectory();
|
||||
/*if (!tempDir.exists()) {
|
||||
if(!tempDir.mkdirs()){
|
||||
if (!tempDir.exists()) {
|
||||
throw new IOException("Cannot create temp dir");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//deleteFolderContents(tempDir, false);
|
||||
}*/
|
||||
|
||||
|
||||
m_engine = Engine.getSingletonInstance();
|
||||
m_engine.buildNewTypeface(fontname, tempDir);
|
||||
|
||||
this.setFontFamilyName(fontname);
|
||||
this.setVersion("CC BY-SA 3.0 http://creativecommons.org/licenses/by-sa/3.0/"); // default
|
||||
// license
|
||||
|
||||
String directoryName = tempDir + File.separator + "bin" + File.separator;
|
||||
|
||||
ttffile = new File(directoryName + fontname + ".ttf");
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the font and writes the .ttf and the .woff file as well as a HTML
|
||||
* template for previewing the WOFF. If debug is set (default is true) then
|
||||
* you'll see the .ttf and .woff file name in the console.
|
||||
*/
|
||||
public void buildFont() throws FileNotFoundException {
|
||||
// Create TTF file with doubletype
|
||||
m_engine.getTypeface().addRequiredGlyphs();
|
||||
//m_engine.fireAction();
|
||||
//m_engine.addDefaultGlyphs();
|
||||
|
||||
for (FGlyph glyph : glyphs) {
|
||||
|
||||
m_engine.checkUnicodeBlock(glyph.getGlyphChar());
|
||||
GlyphFile glyphFile = m_engine.addNewGlyph(glyph.getGlyphChar());
|
||||
glyphFile.setAdvanceWidth(glyph.getAdvanceWidth());
|
||||
|
||||
for (FContour contour : glyph.getContours()) {
|
||||
|
||||
EContour econtour = new EContour();
|
||||
econtour.setType(EContour.k_quadratic);
|
||||
|
||||
for (FPoint point : contour.points) {
|
||||
|
||||
EContourPoint e = new EContourPoint(point.x, point.y, true);
|
||||
if (point.hasControlPoint1()) {
|
||||
|
||||
econtour.addContourPoint(new EContourPoint(point.controlPoint.x, point.controlPoint.y, false));
|
||||
/*EControlPoint cp1 = new EControlPoint(true,
|
||||
point.controlPoint1.x, point.controlPoint1.y);
|
||||
e.setControlPoint1(cp1);
|
||||
*/
|
||||
}
|
||||
/*
|
||||
if (point.hasControlPoint2()) {
|
||||
EControlPoint cp2 = new EControlPoint(false,
|
||||
point.controlPoint2.x, point.controlPoint2.y);
|
||||
e.setControlPoint2(cp2);
|
||||
} */
|
||||
|
||||
econtour.addContourPoint(e);
|
||||
}
|
||||
|
||||
glyphFile.addContour(econtour);
|
||||
}
|
||||
glyphFile.saveGlyphFile();
|
||||
}
|
||||
|
||||
m_engine.buildTrueType(false);
|
||||
|
||||
// End TTF creation
|
||||
if(outfile.exists()){
|
||||
outfile.delete();
|
||||
}
|
||||
ttffile.renameTo(outfile);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all the glyph files created by doubletype in your data/fontname
|
||||
* folder.
|
||||
*/
|
||||
private void cleanup() {
|
||||
File[] filesToExclude = new File[0];
|
||||
|
||||
deleteFolderContents(tempDir, true, filesToExclude);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the author of the font.
|
||||
*/
|
||||
public void setAuthor(String author) throws FileNotFoundException {
|
||||
m_engine.setAuthor(author);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the copyright year of the font.
|
||||
*/
|
||||
public void setCopyrightYear(String copyrightYear) throws FileNotFoundException {
|
||||
m_engine.setCopyrightYear(copyrightYear);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version of the font (default is "0.1").
|
||||
*/
|
||||
public void setVersion(String version) {
|
||||
m_engine.getTypeface().getGlyph().getHead().setVersion(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the font family name of the font. Also called in the constructor. If
|
||||
* changed with setFontFamilyName() it won't affect folder the font is
|
||||
* stored in.
|
||||
*/
|
||||
public void setFontFamilyName(String fontFamilyName) throws FileNotFoundException {
|
||||
m_engine.setFontFamilyName(fontFamilyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sub family of the font.
|
||||
*/
|
||||
public void setSubFamily(String subFamily) throws FileNotFoundException {
|
||||
m_engine.getTypeface().setSubFamily(subFamily);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the license of the font (default is "CC BY-SA 3.0
|
||||
* http://creativecommons.org/licenses/by-sa/3.0/")
|
||||
*/
|
||||
public void setTypefaceLicense(String typefaceLicense) throws FileNotFoundException {
|
||||
m_engine.setTypefaceLicense(typefaceLicense);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the baseline of the font.
|
||||
*/
|
||||
public void setBaseline(float baseline) throws FileNotFoundException {
|
||||
m_engine.setBaseline(baseline);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the meanline of the font.
|
||||
*/
|
||||
public void setMeanline(float meanline) throws FileNotFoundException {
|
||||
m_engine.setMeanline(meanline);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the advanceWidth of the font. Can be changed for every glyph
|
||||
* individually. Won't affect already created glyphs.
|
||||
*/
|
||||
public void setAdvanceWidth(int advanceWidth) {
|
||||
m_engine.setAdvanceWidth(advanceWidth);
|
||||
this.advanceWidth = advanceWidth;
|
||||
}
|
||||
|
||||
public void setTopSideBearing(float topSideBearing) throws FileNotFoundException {
|
||||
try {
|
||||
m_engine.getTypeface().setTopSideBearing(topSideBearing);
|
||||
} catch (OutOfRangeException e) {
|
||||
System.out
|
||||
.println("Error while setting aopSideBearing (must be within range "
|
||||
+ m_engine.getTypeface().getEm());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setBottomSideBearing(float bottomSideBearing) throws FileNotFoundException {
|
||||
try {
|
||||
m_engine.getTypeface().setBottomSideBearing(bottomSideBearing);
|
||||
} catch (OutOfRangeException e) {
|
||||
System.out
|
||||
.println("Error while setting bottomSideBearing (must be within range "
|
||||
+ m_engine.getTypeface().getEm());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAscender(float ascender) throws FileNotFoundException {
|
||||
try {
|
||||
m_engine.getTypeface().setAscender(ascender);
|
||||
} catch (OutOfRangeException e) {
|
||||
System.out
|
||||
.println("Error while setting ascender (must be within range 0 to "
|
||||
+ m_engine.getTypeface().getEm() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDescender(float descender) throws FileNotFoundException {
|
||||
try {
|
||||
m_engine.getTypeface().setDescender(descender);
|
||||
} catch (OutOfRangeException e) {
|
||||
System.out
|
||||
.println("Error while setting descender (must be within range 0 to "
|
||||
+ m_engine.getTypeface().getEm() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setXHeight(float xHeight) throws FileNotFoundException {
|
||||
try {
|
||||
m_engine.getTypeface().setXHeight(xHeight);
|
||||
} catch (OutOfRangeException e) {
|
||||
System.out
|
||||
.println("Error while setting xHeight (must be within range 0 to "
|
||||
+ m_engine.getTypeface().getEm()
|
||||
+ " as well as lower than the ascender "
|
||||
+ m_engine.getTypeface().getAscender() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default metrics for the typeface: setTopSideBearing(170); // 2
|
||||
* px setAscender(683); // 8 px setXHeight(424); // 5 px setDescender(171);
|
||||
* // 2 px setBottomSideBearing(0); // 0px
|
||||
*
|
||||
*/
|
||||
public void setDefaultMetrics() throws FileNotFoundException {
|
||||
m_engine.getTypeface().setDefaultMetrics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a glyph
|
||||
*
|
||||
* @param c Character of the glyph.
|
||||
*
|
||||
* @return FGlyph that has been created.
|
||||
*
|
||||
*/
|
||||
public FGlyph addGlyph(char c) {
|
||||
|
||||
FGlyph glyph = new FGlyph(c);
|
||||
glyph.setAdvanceWidth(advanceWidth);
|
||||
glyphs.add(glyph);
|
||||
return glyph;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a glyph and its one contour
|
||||
*
|
||||
* @param c Character of the glyph.
|
||||
*
|
||||
* @param FContour Shape of the glyph as FContour.
|
||||
*
|
||||
* @return The glyph FGlyph that has been created. You can use this to store
|
||||
* the glyph and add contours afterwards. Alternatively, you can call
|
||||
* getGlyph(char c) to retrieve it.
|
||||
*/
|
||||
public FGlyph addGlyph(char c, FContour contour) {
|
||||
|
||||
FGlyph glyph = new FGlyph(c);
|
||||
glyphs.add(glyph);
|
||||
glyph.addContour(contour);
|
||||
|
||||
glyph.setAdvanceWidth(advanceWidth);
|
||||
return glyph;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a glyph and its contours
|
||||
*
|
||||
* @param c Character of the glyph.
|
||||
*
|
||||
* @param FContour [] Shape of the glyph in an array of FContour.
|
||||
*
|
||||
* @return The FGlyph that has been created. You can use this to store the
|
||||
* glyph and add contours afterwards. Alternatively, you can call
|
||||
* getGlyph(char c) to retrieve it.
|
||||
*/
|
||||
public FGlyph addGlyph(char c, FContour[] contours) {
|
||||
|
||||
FGlyph glyph = new FGlyph(c);
|
||||
glyphs.add(glyph);
|
||||
|
||||
for (FContour contour : contours) {
|
||||
// if (debug) System.out.println(p.x + " - " + p.y);
|
||||
glyph.addContour(contour);
|
||||
}
|
||||
glyph.setAdvanceWidth(advanceWidth);
|
||||
return glyph;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get glyph by character
|
||||
*
|
||||
* @param c The character of the glyph
|
||||
*
|
||||
* @return The glyph
|
||||
*/
|
||||
public FGlyph getGlyph(char c) {
|
||||
|
||||
FGlyph glyph = null;
|
||||
for (int i = 0; i < glyphs.size(); i++) {
|
||||
if (glyphs.get(i).getGlyphChar() == c) {
|
||||
glyph = glyphs.get(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return glyph;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Engine getter
|
||||
*
|
||||
* @return The doubletype Engine used for font creation, so that you can
|
||||
* access all functions of doubletype in case you need them.
|
||||
*/
|
||||
public Engine getEngine() {
|
||||
return m_engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TypefaceFile
|
||||
*
|
||||
* @return The doubletype TypefaceFile used for font creation, so that you
|
||||
* can access functions of doubletype in case you need them.
|
||||
*/
|
||||
public TypefaceFile getTypefaceFile() {
|
||||
return m_engine.getTypeface();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the .ttf file name
|
||||
*
|
||||
* @return The .ttf file name, which is being created when you call build()
|
||||
*/
|
||||
public String getTTFfilename() {
|
||||
return ttffile.toString();
|
||||
}
|
||||
|
||||
private static void deleteFolderContents(File folder,
|
||||
boolean deleteFolderItself) {
|
||||
File[] files = folder.listFiles();
|
||||
if (files != null) { // some JVMs return null for empty dirs
|
||||
for (File f : files) {
|
||||
if (f.isDirectory()) {
|
||||
deleteFolderContents(f, true);
|
||||
f.delete();
|
||||
} else {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deleteFolderItself) {
|
||||
folder.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteFolderContents(File folder,
|
||||
boolean deleteFolderItself, File[] exceptions) {
|
||||
File[] files = folder.listFiles();
|
||||
if (files != null) { // some JVMs return null for empty dirs
|
||||
for (File f : files) {
|
||||
boolean deleteFile = true;
|
||||
for (File exceptfile : exceptions) {
|
||||
if (f.equals(exceptfile)) {
|
||||
deleteFile = false;
|
||||
}
|
||||
}
|
||||
if (deleteFile) {
|
||||
if (f.isDirectory()) {
|
||||
deleteFolderContents(f, true, exceptions);
|
||||
f.delete();
|
||||
} else {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deleteFolderItself) {
|
||||
folder.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
trunk/libsrc/ttf/src/fontastic/PVector.java
Normal file
27
trunk/libsrc/ttf/src/fontastic/PVector.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package fontastic;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class PVector {
|
||||
public double x;
|
||||
public double y;
|
||||
|
||||
public PVector() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public PVector(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}
|
||||
31
trunk/libsrc/ttf/src/fontatest/FontaTest.java
Normal file
31
trunk/libsrc/ttf/src/fontatest/FontaTest.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package fontatest;
|
||||
|
||||
import fontastic.FPoint;
|
||||
import fontastic.Fontastic;
|
||||
import fontastic.PVector;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class FontaTest {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) throws IOException {
|
||||
File file=new File("example.ttf");
|
||||
file.delete();
|
||||
Fontastic f = new Fontastic("ExampleFont",file);
|
||||
f.setAuthor("Nobody");
|
||||
FPoint[] points = new FPoint[]{ // Define a PVector array containing the points of the shape
|
||||
new FPoint(0, 0),
|
||||
new FPoint(512,0),
|
||||
//new FPoint(256, 1024),
|
||||
new FPoint(new PVector(256,1024), new PVector(512,512)),
|
||||
new FPoint(0, 0)
|
||||
};
|
||||
f.addGlyph('P').addContour(points); // Assign contour to character A
|
||||
f.buildFont();
|
||||
}
|
||||
|
||||
}
|
||||
199
trunk/libsrc/ttf/src/org/doubletype/ossa/ActiveList.java
Normal file
199
trunk/libsrc/ttf/src/org/doubletype/ossa/ActiveList.java
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* $Id: ActiveList.java,v 1.7 2004/11/15 03:39:38 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class ActiveList {
|
||||
private static ActiveList s_actives = null;
|
||||
|
||||
public static ActiveList getSingletonInstance() {
|
||||
if (s_actives == null)
|
||||
s_actives = new ActiveList();
|
||||
|
||||
return s_actives;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public ArrayList<GlyphObject> m_activeObjects = new ArrayList<>();
|
||||
|
||||
public void unselectAll() {
|
||||
m_activeObjects.clear();
|
||||
}
|
||||
|
||||
public boolean hasSelected() {
|
||||
return size() > 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return m_activeObjects.size();
|
||||
}
|
||||
|
||||
public GlyphObject get(int a_index) {
|
||||
return m_activeObjects.get(a_index);
|
||||
}
|
||||
|
||||
public boolean isSelected(Object a_value) {
|
||||
int i;
|
||||
|
||||
// use equal method to compare this will catch XContour etc...
|
||||
for (i = 0; i < size(); i++) {
|
||||
if (get(i) == a_value) {
|
||||
return true;
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addActive(GlyphObject a_object) {
|
||||
if (isSelected(a_object)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_activeObjects.add(a_object);
|
||||
}
|
||||
|
||||
public void setActives(ActiveList a_actives) {
|
||||
unselectAll();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < a_actives.size(); i++) {
|
||||
addActive(a_actives.get(i));
|
||||
} // for i
|
||||
}
|
||||
|
||||
private GlyphObject getTheActive() {
|
||||
GlyphObject retval = null;
|
||||
|
||||
if (m_activeObjects.size() == 1) {
|
||||
retval = get(0);
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public boolean hasActiveModule() {
|
||||
return (getTheActive() instanceof EModuleInvoke);
|
||||
}
|
||||
|
||||
public EModuleInvoke getActiveModule() {
|
||||
if (hasActiveModule()) {
|
||||
return (EModuleInvoke) getTheActive();
|
||||
} else {
|
||||
return null;
|
||||
} // if-else
|
||||
}
|
||||
|
||||
public boolean hasActiveContour() {
|
||||
return (getTheActive() instanceof EContour);
|
||||
}
|
||||
|
||||
public EContour getActiveContour() {
|
||||
if (getTheActive() instanceof EContour) {
|
||||
return (EContour) getTheActive();
|
||||
} else {
|
||||
return null;
|
||||
} // if-else
|
||||
}
|
||||
|
||||
public boolean hasActiveInclude() {
|
||||
return (getTheActive() instanceof EIncludeInvoke);
|
||||
}
|
||||
|
||||
public EIncludeInvoke getActiveInclude() {
|
||||
if (hasActiveInclude()) {
|
||||
return (EIncludeInvoke) getTheActive();
|
||||
} // if
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasActiveControlPoint() {
|
||||
return (getTheActive() instanceof EControlPoint);
|
||||
}
|
||||
|
||||
public EControlPoint getActiveControlPoint() {
|
||||
if (hasActiveControlPoint()) {
|
||||
return (EControlPoint) getTheActive();
|
||||
} // if
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasActivePoint() {
|
||||
return (getTheActive() instanceof EContourPoint);
|
||||
}
|
||||
|
||||
public EContourPoint getActivePoint() {
|
||||
if (hasActivePoint()) {
|
||||
return (EContourPoint) getTheActive();
|
||||
} else {
|
||||
return null;
|
||||
} // if
|
||||
}
|
||||
|
||||
public boolean hasActiveHint() {
|
||||
return (getTheActive() instanceof EHint);
|
||||
}
|
||||
|
||||
public String getSelectedAsString() {
|
||||
String retval = "";
|
||||
|
||||
if (!hasSelected()) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
retval = "<clipboard>";
|
||||
|
||||
int i;
|
||||
for (i = 0; i < size(); i++) {
|
||||
GlyphObject active = get(i);
|
||||
retval += active.toString();
|
||||
} // for i
|
||||
|
||||
retval += "</clipboard>";
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
||||
55
trunk/libsrc/ttf/src/org/doubletype/ossa/AppSettings.java
Normal file
55
trunk/libsrc/ttf/src/org/doubletype/ossa/AppSettings.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
*/
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class AppSettings extends Object {
|
||||
private static String k_lastTypefaceFile = "lastTypefaceFile";
|
||||
|
||||
private static File s_fileName = new File("./.properties");
|
||||
private static Properties s_properties;
|
||||
|
||||
public static String getLastTypefaceDir() {
|
||||
loadPropertyFile();
|
||||
return s_properties.getProperty(k_lastTypefaceFile, "./");
|
||||
}
|
||||
|
||||
public static void setLastTypefaceDir(String a_value) {
|
||||
loadPropertyFile();
|
||||
s_properties.setProperty(k_lastTypefaceFile, a_value);
|
||||
savePropertyFile();
|
||||
}
|
||||
|
||||
private static void loadPropertyFile() {
|
||||
if (s_properties != null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
s_properties = new Properties();
|
||||
if (s_fileName.exists()) {
|
||||
try {
|
||||
s_properties.load(new FileInputStream(s_fileName));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
} // if
|
||||
}
|
||||
|
||||
private static void savePropertyFile() {
|
||||
if (s_properties == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
try {
|
||||
s_properties.store(new FileOutputStream(s_fileName),
|
||||
"DoubleType AppSetting File");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
}
|
||||
}
|
||||
762
trunk/libsrc/ttf/src/org/doubletype/ossa/Engine.java
Normal file
762
trunk/libsrc/ttf/src/org/doubletype/ossa/Engine.java
Normal file
@@ -0,0 +1,762 @@
|
||||
/*
|
||||
* $Id: Engine.java,v 1.84 2004/12/27 04:56:03 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.geom.*;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
import org.doubletype.ossa.module.*;
|
||||
import org.doubletype.ossa.truetype.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class Engine {
|
||||
// --------------------------------------------------------------
|
||||
|
||||
// used by findFile
|
||||
public static final int USER_CANCELLED = -1;
|
||||
public static final int FILE_NOT_FOUND = 0;
|
||||
public static final int FILE_FOUND = 1;
|
||||
|
||||
// used by Find
|
||||
public static final int SEARCH_BY_EXAMPLE = 0;
|
||||
public static final int SEARCH_UNICODE = 1;
|
||||
public static final int SEARCH_JIS_CODE = 2;
|
||||
|
||||
// public static final double k_fontSizes [] = {9, 10, 11, 12, 14, 18, 24, 36, 72};
|
||||
public static final int k_defaultPixelSize = 16;
|
||||
public static final int k_resolutions [] = {96, 72, 75, 100};
|
||||
public static final int k_defaultResolution = 96;
|
||||
public static final int k_zooms [] = {25, 50, 100};
|
||||
public static final int k_defaultZoom = 100;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
private static int s_em = 1024;
|
||||
private static Engine s_singleton = null;
|
||||
|
||||
public static Engine getSingletonInstance() {
|
||||
if (s_singleton == null)
|
||||
s_singleton = new Engine();
|
||||
return s_singleton;
|
||||
}
|
||||
|
||||
public static int getEm() {
|
||||
return TTPixelSize.getEm();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
private UiBridge m_ui;
|
||||
|
||||
private TypefaceFile m_typeface;
|
||||
private GlyphFile m_root;
|
||||
private ActiveList m_actives;
|
||||
private ArrayList<ActionListener> m_listeners = new ArrayList<>();
|
||||
|
||||
private String m_foundFileName;
|
||||
private Clipboard m_clipboard;
|
||||
private JFileChooser m_gifChooser;
|
||||
private JFileChooser m_chooser;
|
||||
|
||||
private Action m_deleteAction;
|
||||
private Action m_addPointAction;
|
||||
private Action m_toggleAction;
|
||||
private Action m_hintAction;
|
||||
private Action m_contourAction;
|
||||
private Action m_moduleAction;
|
||||
private Action m_includeAction;
|
||||
private Action m_selectNextAction;
|
||||
private Action m_roundAction;
|
||||
private Action m_propertyAction;
|
||||
private Action m_convertControlPointAction;
|
||||
private Action m_convertContourAction;
|
||||
|
||||
private String m_msgAlreadyExists = " already exists!";
|
||||
private String m_msgNoTypeface = "no typeface";
|
||||
private String m_msgEmptyGlyphTitle = "glyph title is empty";
|
||||
private String m_msgGlyphName = "glyph name?";
|
||||
private String m_msgCircular = "circular include!";
|
||||
private String m_msgNoJis = "Charset ISO-2022-JP is not supported.\n"
|
||||
+ "Please include charsets.jar in classpath.";
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
private Engine() {
|
||||
//GlyphFactory.setFactory(new EGlyphFactory());
|
||||
|
||||
|
||||
|
||||
m_typeface = null;
|
||||
m_root = null;
|
||||
|
||||
m_clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
m_actives = ActiveList.getSingletonInstance();
|
||||
|
||||
initActions();
|
||||
}
|
||||
|
||||
private void initActions() {
|
||||
|
||||
}
|
||||
|
||||
public Action [] buildCommands() {
|
||||
ArrayList actions = buildCommandsArrayList();
|
||||
Action [] retval = new Action[actions.size()];
|
||||
int i;
|
||||
for (i = 0; i < actions.size(); i++) {
|
||||
retval[i] = (Action) actions.get(i);
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private ArrayList buildCommandsArrayList() {
|
||||
ArrayList<Action> retval = new ArrayList<>();
|
||||
|
||||
if (m_root == null) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
if (m_actives.hasActiveContour()) {
|
||||
retval.add(m_convertContourAction);
|
||||
}
|
||||
|
||||
if (m_actives.hasActiveControlPoint()) {
|
||||
EControlPoint controlPoint = m_actives.getActiveControlPoint();
|
||||
retval.add(m_convertControlPointAction);
|
||||
}
|
||||
|
||||
if (m_actives.hasActivePoint()) {
|
||||
EContourPoint point = m_actives.getActivePoint();
|
||||
|
||||
retval.add(m_toggleAction);
|
||||
|
||||
if (!point.isRounded()) {
|
||||
retval.add(m_hintAction);
|
||||
} // if
|
||||
|
||||
if (!point.hasHintForCurrentPpem()) {
|
||||
retval.add(m_roundAction);
|
||||
} // if
|
||||
} // if
|
||||
|
||||
if (m_actives.size() > 0) {
|
||||
// retval.add(m_propertyAction);
|
||||
retval.add(m_deleteAction);
|
||||
} // if
|
||||
|
||||
if (m_actives.hasActivePoint()) {
|
||||
retval.add(m_addPointAction);
|
||||
} // if
|
||||
|
||||
/*if (!GlyphAction.isPointVisible()) {
|
||||
retval.add(m_moduleAction);
|
||||
retval.add(m_contourAction);
|
||||
retval.add(m_includeAction);
|
||||
} // if*/
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void localize(ResourceBundle a_bundle) {
|
||||
m_msgAlreadyExists = a_bundle.getString("msgAlreadyExists");
|
||||
m_msgNoTypeface = a_bundle.getString("msgNoTypeface");
|
||||
m_msgEmptyGlyphTitle = a_bundle.getString("msgEmptyGlyphTitle");
|
||||
m_msgGlyphName = a_bundle.getString("msgGlyphName");
|
||||
m_msgCircular = a_bundle.getString("msgCircular");
|
||||
}
|
||||
|
||||
private void showPropertyDialog() {
|
||||
if (m_actives.size() != 1) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_ui.showPropertyDialog(m_actives.get(0));
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setUi(UiBridge a_ui) {
|
||||
m_ui = a_ui;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void selectNext() {
|
||||
if (m_root == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_root.selectNext();
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if (m_root == null)
|
||||
return;
|
||||
if (!m_actives.hasSelected()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_root.remove();
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void cutToClipboard() {
|
||||
if (m_root == null)
|
||||
return;
|
||||
if (!m_actives.hasSelected()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
copyToClipboard();
|
||||
delete();
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void copyToClipboard() {
|
||||
if (m_root == null)
|
||||
return;
|
||||
if (!m_actives.hasSelected()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
String s = m_actives.getSelectedAsString();
|
||||
if (s.equals("")) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
StringSelection selection = new StringSelection(s);
|
||||
|
||||
try {
|
||||
m_clipboard.setContents(selection, selection);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void pasteFromClipboard() {
|
||||
if (m_root == null)
|
||||
return;
|
||||
Transferable content = null;
|
||||
String s = "";
|
||||
|
||||
try {
|
||||
content = m_clipboard.getContents(this);
|
||||
if (content == null)
|
||||
return;
|
||||
s = (String) content.getTransferData(DataFlavor.stringFlavor);
|
||||
if (s.equals("")) {
|
||||
return;
|
||||
} // if
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} // try-catch
|
||||
|
||||
try {
|
||||
m_root.addObjectFromClipboard(s);
|
||||
} catch (GlyphFile.CircularIncludeException e) {
|
||||
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, m_msgCircular, e);
|
||||
}
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void undo() {
|
||||
if (m_root == null)
|
||||
return;
|
||||
|
||||
m_root.undo();
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void redo() {
|
||||
if (m_root == null)
|
||||
return;
|
||||
|
||||
m_root.redo();
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setAdvanceWidth(int a_value) {
|
||||
if (m_root == null)
|
||||
return;
|
||||
|
||||
m_root.setAdvanceWidth(a_value);
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void moveLeft() {
|
||||
move(new Point2D.Double(-1, 0));
|
||||
}
|
||||
|
||||
public void moveUp() {
|
||||
move(new Point2D.Double(0, 1));
|
||||
}
|
||||
|
||||
public void moveDown() {
|
||||
move(new Point2D.Double(0, -1));
|
||||
}
|
||||
|
||||
public void moveRight() {
|
||||
move(new Point2D.Double(1, 0));
|
||||
}
|
||||
|
||||
private void move(Point2D a_delta) {
|
||||
if (m_root == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_root.move(a_delta);
|
||||
}
|
||||
|
||||
public void buildNewTypeface(String a_name, File a_dir) throws FileNotFoundException {
|
||||
if (a_name == null || a_name.equals("")) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
TypefaceFile typeface = new TypefaceFile(a_name, a_dir);
|
||||
typeface.setAuthor("no body");
|
||||
DateFormat format = new SimpleDateFormat("yyyy");
|
||||
typeface.setCopyrightYear(format.format(new Date()));
|
||||
typeface.setFontFamilyName(a_name);
|
||||
typeface.setSubFamily("Regular");
|
||||
typeface.addCodePage(TTCodePage.US_ASCII.toString());
|
||||
typeface.addCodePage(TTCodePage.Latin_1.toString());
|
||||
|
||||
setTypeface(typeface);
|
||||
}
|
||||
|
||||
public void addDefaultGlyphs() throws FileNotFoundException {
|
||||
m_typeface.addRequiredGlyphs();
|
||||
m_typeface.addBasicLatinGlyphs();
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void openTypeface() throws FileNotFoundException {
|
||||
if (m_chooser == null) {
|
||||
m_chooser = new JFileChooser(new File(AppSettings.getLastTypefaceDir()));
|
||||
} // if
|
||||
|
||||
m_chooser.setFileFilter(new TypefaceFileFilter());
|
||||
int returnVal = m_chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal != JFileChooser.APPROVE_OPTION) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
AppSettings.setLastTypefaceDir(m_chooser.getSelectedFile().toString());
|
||||
openTypeface(m_chooser.getSelectedFile());
|
||||
}
|
||||
|
||||
private void openTypeface(File a_file) throws FileNotFoundException {
|
||||
setTypeface(new TypefaceFile(a_file));
|
||||
|
||||
if (m_typeface.addRequiredGlyphs()) {
|
||||
fireAction();
|
||||
} // if
|
||||
}
|
||||
|
||||
public void setTypeface(TypefaceFile a_typeface) {
|
||||
m_typeface = a_typeface;
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void changeUnicode(long a_unicode) throws FileNotFoundException {
|
||||
if (m_typeface == null || m_root == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_typeface.setGlyphUnicode(m_root, a_unicode);
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public int findFile(long a_unicode) {
|
||||
if (m_typeface == null)
|
||||
return USER_CANCELLED;
|
||||
|
||||
m_foundFileName = m_typeface.unicodeToFileName(a_unicode);
|
||||
if (m_foundFileName != null) {
|
||||
return FILE_FOUND;
|
||||
} // if
|
||||
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
public String getFoundFileName() {
|
||||
return m_foundFileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create glyph out of given unicode, and add it to the typeface.
|
||||
* @param a_unicode
|
||||
*/
|
||||
public GlyphFile addNewGlyph(long a_unicode) throws FileNotFoundException {
|
||||
GlyphFile retval;
|
||||
|
||||
retval = m_typeface.createGlyph(a_unicode);
|
||||
addGlyphToTypeface(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void checkUnicodeBlock(long a_unicode) throws FileNotFoundException {
|
||||
TTUnicodeRange range = TTUnicodeRange.of(a_unicode);
|
||||
if (range == null){
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_typeface.containsUnicodeRange(range.toString())){
|
||||
return;
|
||||
}
|
||||
m_typeface.addUnicodeRange(range.toString());
|
||||
}
|
||||
|
||||
private void addGlyphToTypeface(GlyphFile a_file) throws FileNotFoundException {
|
||||
m_typeface.addGlyph(a_file);
|
||||
m_typeface.saveGlyphFile();
|
||||
|
||||
setRoot(a_file);
|
||||
}
|
||||
|
||||
public GlyphFile openGlyphFile(String a_fileName) {
|
||||
ModuleManager manager = ModuleManager.getSingletonInstance();
|
||||
GlyphFile retval = manager.getReloadedGlyphFile(a_fileName);
|
||||
setRoot(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void removeGlyphFromTypeface(String a_fileName) {
|
||||
if (m_typeface == null)
|
||||
return;
|
||||
|
||||
m_typeface.removeGlyph(a_fileName);
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public Font buildTrueType(boolean a_isDebug) {
|
||||
Font retval = null;
|
||||
|
||||
if (m_typeface == null)
|
||||
return retval;
|
||||
|
||||
|
||||
|
||||
try {
|
||||
m_typeface.buildTTF(a_isDebug);
|
||||
retval = m_typeface.getFont();
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null,e);
|
||||
} // try-catch
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void saveGlyph() throws FileNotFoundException {
|
||||
if (m_root == null)
|
||||
return;
|
||||
|
||||
if (m_root.getGlyphTitle().equals("")) {
|
||||
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, m_msgEmptyGlyphTitle);
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_root.saveGlyphFile();
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public TypefaceFile getTypeface() {
|
||||
return m_typeface;
|
||||
}
|
||||
|
||||
public File getGlyphPath() {
|
||||
return m_typeface.getGlyphPath();
|
||||
}
|
||||
|
||||
|
||||
public GlyphFile getRoot() {
|
||||
return m_root;
|
||||
}
|
||||
|
||||
public void setRoot(GlyphFile a_file) {
|
||||
m_root = a_file;
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void addActionListener(ActionListener a_listener) {
|
||||
m_listeners.add(a_listener);
|
||||
}
|
||||
|
||||
public void fireAction() {
|
||||
ActionEvent e = new ActionEvent(this, Event.ACTION_EVENT, "foo");
|
||||
|
||||
for (ActionListener listener: m_listeners) {
|
||||
listener.actionPerformed(e);
|
||||
} // for listener
|
||||
}
|
||||
|
||||
public String includeFileName() {
|
||||
String retval = "";
|
||||
|
||||
JFileChooser chooser = new JFileChooser(getGlyphPath());
|
||||
chooser.setFileFilter(new GlyphFileFilter());
|
||||
|
||||
int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
retval = chooser.getSelectedFile().getName().toString();
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void addCodePage(String a_codePage) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_typeface.addCodePage(a_codePage);
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void removeCodePage(String a_codePage) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_typeface.removeCodePage(a_codePage);
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setAuthor(String a_value) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_typeface.setAuthor(a_value);
|
||||
m_typeface.saveGlyphFile();
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setCopyrightYear(String a_value) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_typeface.setCopyrightYear(a_value);
|
||||
m_typeface.saveGlyphFile();
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setFontFamilyName(String a_value) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_typeface.setFontFamilyName(a_value);
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setTypefaceLicense(String a_value) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_typeface.setLicense(a_value);
|
||||
m_typeface.saveGlyphFile();
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setBaseline(double a_value) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
double min = m_typeface.getBottomSideBearing();
|
||||
double max = m_typeface.getMeanline();
|
||||
|
||||
if (a_value < min) {
|
||||
a_value = min;
|
||||
} // if
|
||||
|
||||
if (a_value > max) {
|
||||
a_value = max;
|
||||
} // if
|
||||
|
||||
try {
|
||||
m_typeface.setDescender(a_value - min);
|
||||
m_typeface.setAscender(m_typeface.getEm()
|
||||
- m_typeface.getTopSideBearing() - a_value);
|
||||
m_typeface.setXHeight(max - a_value);
|
||||
}
|
||||
catch (OutOfRangeException e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void setMeanline(double a_value) throws FileNotFoundException {
|
||||
if (m_typeface == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
double min = m_typeface.getBaseline();
|
||||
double max = m_typeface.getEm()
|
||||
- m_typeface.getTopSideBearing();
|
||||
|
||||
if (a_value < min) {
|
||||
a_value = min;
|
||||
} // if
|
||||
|
||||
if (a_value > max) {
|
||||
a_value = max;
|
||||
} // if
|
||||
|
||||
try {
|
||||
m_typeface.setXHeight(a_value - min);
|
||||
}
|
||||
catch (OutOfRangeException e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent a_event) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void mouseDragged(MouseEvent a_event) {
|
||||
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent a_event) {
|
||||
|
||||
}
|
||||
|
||||
public void setAction(String a_key) {
|
||||
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent a_event) {
|
||||
if (a_event.getModifiers() == 0) {
|
||||
if (a_event.getKeyCode() == KeyEvent.VK_TAB) {
|
||||
|
||||
m_selectNextAction.actionPerformed(null);
|
||||
} // if
|
||||
} else if (a_event.getModifiers() == KeyEvent.SHIFT_MASK) {
|
||||
|
||||
} // if
|
||||
|
||||
fireAction();
|
||||
}
|
||||
|
||||
private JFileChooser createImageChooser() {
|
||||
JFileChooser retval;
|
||||
|
||||
retval = new JFileChooser(new File(AppSettings.getLastTypefaceDir()));
|
||||
retval.setFileFilter(new javax.swing.filechooser.FileFilter() {
|
||||
public boolean accept(File a_file) {
|
||||
if (a_file.isDirectory())
|
||||
return true;
|
||||
|
||||
String s = a_file.toString().toLowerCase();
|
||||
if (s.endsWith(".gif")
|
||||
|| s.endsWith(".jpg")
|
||||
|| s.endsWith(".jpeg")
|
||||
|| s.endsWith(".png"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//The description of this filter
|
||||
public String getDescription() {
|
||||
return "Image Files";
|
||||
}
|
||||
});
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ArrayList<TTPixelSize> getPixelSizes() {
|
||||
return TTPixelSize.getList();
|
||||
}
|
||||
|
||||
class MyTreeListener implements TreeSelectionListener {
|
||||
public void valueChanged(TreeSelectionEvent a_event) {
|
||||
TreePath path = a_event.getPath();
|
||||
Object obj = path.getLastPathComponent();
|
||||
String s = obj.toString();
|
||||
|
||||
TreePath parent = path.getParentPath();
|
||||
if (parent != null) {
|
||||
obj = parent.getLastPathComponent();
|
||||
s = obj.toString() + "->" + s;
|
||||
} // if
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
67
trunk/libsrc/ttf/src/org/doubletype/ossa/GlyphColor.java
Normal file
67
trunk/libsrc/ttf/src/org/doubletype/ossa/GlyphColor.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* $Id: GlyphColor.java,v 1.6 2004/07/11 06:25:11 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class GlyphColor {
|
||||
public static Color MAROON = new Color(120, 21, 11);
|
||||
public static Color ORANGE = new Color(231, 113, 18); // (238, 176, 55);
|
||||
public static Color OLIVE = new Color(98, 106, 7);
|
||||
public static Color INDIGO = new Color(22, 16, 149);
|
||||
public static Color GREEN = new Color(21, 142, 5);
|
||||
public static Color RED = new Color(250, 0, 0);
|
||||
public static Color GRAY = new Color(0x33, 0x33, 0x33);
|
||||
public static Color CYAN = new Color(15, 187, 157); // 15, 108, 140
|
||||
public static Color AZURE = new Color(0x00, 0x66, 0xcc);
|
||||
public static Color TAN = new Color(0xcc, 0x99, 0x66);
|
||||
public static Color SILVER = new Color(0xe0, 0xdf, 0xe3);
|
||||
|
||||
|
||||
public static Color BACKGROUND = Color.WHITE;
|
||||
public static Color CROSS = Color.LIGHT_GRAY;
|
||||
public static Color POINT = ORANGE;
|
||||
public static Color NUMBER = Color.GRAY;
|
||||
public static Color SELECTED = RED;
|
||||
public static Color CONTOUR = AZURE;
|
||||
public static Color HINT = OLIVE;
|
||||
public static Color INCLUDE = OLIVE;
|
||||
public static Color MODULE = MAROON;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* $Id: GlyphFileFilter.java,v 1.2 2004/01/20 03:35:27 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.io.File;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class GlyphFileFilter extends FileFilter {
|
||||
public boolean accept(File a_file) {
|
||||
if (a_file.isDirectory()) {
|
||||
return false;
|
||||
} // if
|
||||
|
||||
if (! (a_file.toString().toLowerCase().endsWith(".glyph")))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//The description of this filter
|
||||
public String getDescription() {
|
||||
return "glyph files";
|
||||
}
|
||||
}
|
||||
104
trunk/libsrc/ttf/src/org/doubletype/ossa/HistoryList.java
Normal file
104
trunk/libsrc/ttf/src/org/doubletype/ossa/HistoryList.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* $Id: HistoryList.java,v 1.1 2004/09/05 17:08:03 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.util.*;
|
||||
import org.doubletype.ossa.module.GlyphFile;
|
||||
|
||||
/** Caretaker of MementoPattern.
|
||||
* @author e.e
|
||||
*/
|
||||
public class HistoryList {
|
||||
private GlyphFile m_file;
|
||||
private ArrayList<Memento> m_list = new ArrayList<>();
|
||||
private int m_index = -1;
|
||||
|
||||
|
||||
public HistoryList(GlyphFile a_file) {
|
||||
m_file = a_file;
|
||||
}
|
||||
|
||||
private void printHistoryArray() {
|
||||
int i;
|
||||
for (i = 0; i <= m_index; i++) {
|
||||
Memento memento = m_list.get(i);
|
||||
System.out.println(memento.toString());
|
||||
} // for i
|
||||
}
|
||||
|
||||
/**
|
||||
* Records snapshot into history queue.
|
||||
* Takes place after each action.
|
||||
* Updates modified time with the current system time.
|
||||
* @param a_description
|
||||
*/
|
||||
public void record(String a_description) {
|
||||
add(m_file.createMemento(a_description));
|
||||
}
|
||||
|
||||
private void add(Memento a_memento) {
|
||||
while (m_list.size() - 1 > m_index) {
|
||||
m_list.remove(m_list.size() - 1);
|
||||
} // if
|
||||
|
||||
m_list.add(a_memento);
|
||||
m_index = m_list.size() - 1;
|
||||
}
|
||||
|
||||
public void undo() {
|
||||
if (m_list.size() == 0
|
||||
|| m_index <= 0) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_index--;
|
||||
m_file.restore(get(m_index));
|
||||
}
|
||||
|
||||
public void redo() {
|
||||
if (m_list.size() == 0
|
||||
|| m_index >= m_list.size() - 1) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_index++;
|
||||
m_file.restore(get(m_index));
|
||||
}
|
||||
|
||||
private Memento get(int a_index) {
|
||||
return m_list.get(a_index);
|
||||
}
|
||||
}
|
||||
91
trunk/libsrc/ttf/src/org/doubletype/ossa/ImageSizer.java
Normal file
91
trunk/libsrc/ttf/src/org/doubletype/ossa/ImageSizer.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* $Id: ImageSizer.java,v 1.1 2004/03/04 12:52:50 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class ImageSizer {
|
||||
private Dimension m_size = new Dimension(-1, -1);
|
||||
private boolean m_isImcomplete;
|
||||
|
||||
private ImageObserver m_observer = new ImageObserver() {
|
||||
public synchronized boolean imageUpdate(
|
||||
Image a_image,
|
||||
int a_flag,
|
||||
int a_x,
|
||||
int a_y,
|
||||
int a_width,
|
||||
int a_height) {
|
||||
if ((a_flag & WIDTH) != 0)
|
||||
m_size.width = a_width;
|
||||
if ((a_flag & HEIGHT) != 0)
|
||||
m_size.height = a_height;
|
||||
if ((a_flag & (ERROR | ABORT)) != 0)
|
||||
m_isImcomplete = true;
|
||||
|
||||
boolean retval = !resultKnown();
|
||||
if (!retval) {
|
||||
notifyAll();
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
};
|
||||
|
||||
public ImageSizer(Image a_image) {
|
||||
m_size.width = a_image.getWidth(m_observer);
|
||||
m_size.height = a_image.getHeight(m_observer);
|
||||
}
|
||||
|
||||
private boolean resultKnown() {
|
||||
return m_size.width != -1
|
||||
&& m_size.height != -1
|
||||
|| m_isImcomplete;
|
||||
}
|
||||
|
||||
//returns null iff error or abort
|
||||
public Dimension getImageSize() throws InterruptedException {
|
||||
synchronized (m_observer) {
|
||||
while (!resultKnown())
|
||||
m_observer.wait();
|
||||
return m_isImcomplete ? null : new Dimension(m_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
89
trunk/libsrc/ttf/src/org/doubletype/ossa/Memento.java
Normal file
89
trunk/libsrc/ttf/src/org/doubletype/ossa/Memento.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* $Id: Memento.java,v 1.1 2004/09/05 17:08:03 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003 - 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class Memento {
|
||||
private String m_description;
|
||||
private byte [] m_compressed;
|
||||
private int m_originalSize;
|
||||
private long m_entryTime;
|
||||
|
||||
public Memento(String a_description, byte [] a_data) {
|
||||
m_description = a_description;
|
||||
m_originalSize = a_data.length;
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(out);
|
||||
|
||||
try {
|
||||
zip.putNextEntry(new ZipEntry(a_description));
|
||||
zip.write(a_data);
|
||||
zip.closeEntry();
|
||||
zip.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
|
||||
m_compressed = out.toByteArray();
|
||||
m_entryTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public InputStream getData() {
|
||||
ZipInputStream zip = null;
|
||||
|
||||
try {
|
||||
zip = new ZipInputStream(
|
||||
new ByteArrayInputStream(m_compressed));
|
||||
ZipEntry entry = zip.getNextEntry();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
|
||||
return zip;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return m_description;
|
||||
}
|
||||
}
|
||||
96
trunk/libsrc/ttf/src/org/doubletype/ossa/ModuleManager.java
Normal file
96
trunk/libsrc/ttf/src/org/doubletype/ossa/ModuleManager.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* $Id: ModuleManager.java,v 1.5 2004/01/14 06:49:39 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.util.*;
|
||||
import org.doubletype.ossa.module.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class ModuleManager {
|
||||
private static ModuleManager s_singleton = null;
|
||||
|
||||
public static ModuleManager getSingletonInstance() {
|
||||
if (s_singleton == null)
|
||||
s_singleton = new ModuleManager();
|
||||
return s_singleton;
|
||||
}
|
||||
|
||||
|
||||
private Hashtable<String,GlyphModule> m_modules = new Hashtable<>();
|
||||
private Hashtable<String,GlyphFile> m_files = new Hashtable<>();
|
||||
|
||||
private ModuleManager() {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
m_modules.clear();
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
public GlyphModule getModule(String a_name) throws Exception {
|
||||
if (m_modules.containsKey(a_name)) {
|
||||
return (GlyphModule) m_modules.get(a_name);
|
||||
} // if
|
||||
|
||||
GlyphModule retval;
|
||||
|
||||
retval = (GlyphModule) Class.forName(a_name).newInstance();
|
||||
m_modules.put(a_name, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public GlyphFile getGlyphFile(String a_name) {
|
||||
if (m_files.containsKey(a_name)) {
|
||||
return (GlyphFile) m_files.get(a_name);
|
||||
} // if
|
||||
|
||||
return getReloadedGlyphFile(a_name);
|
||||
}
|
||||
|
||||
public GlyphFile getReloadedGlyphFile(String a_name) {
|
||||
GlyphFile retval;
|
||||
|
||||
Engine engine = Engine.getSingletonInstance();
|
||||
retval = new GlyphFile(new File(engine.getGlyphPath(), a_name));
|
||||
m_files.put(a_name, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
73
trunk/libsrc/ttf/src/org/doubletype/ossa/MyTableModel.java
Normal file
73
trunk/libsrc/ttf/src/org/doubletype/ossa/MyTableModel.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* $Id: MyTableModel.java,v 1.1 2004/02/09 05:34:17 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import javax.swing.table.*;
|
||||
import org.doubletype.ossa.module.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class MyTableModel extends AbstractTableModel {
|
||||
protected Engine m_engine;
|
||||
protected GlyphFile m_file = null;
|
||||
|
||||
protected MyTableModel(Engine a_engine) {
|
||||
m_engine = a_engine;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
reset();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object getValueAt(int a_row, int a_column) {
|
||||
reset();
|
||||
|
||||
Object retval = null;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
protected void reset() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* $Id: OutOfRangeException.java,v 1.1 2004/02/23 14:19:30 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class OutOfRangeException extends Exception {
|
||||
private double m_value;
|
||||
|
||||
public OutOfRangeException(double a_value) {
|
||||
super();
|
||||
|
||||
m_value = a_value;
|
||||
}
|
||||
}
|
||||
44
trunk/libsrc/ttf/src/org/doubletype/ossa/Renderer.java
Normal file
44
trunk/libsrc/ttf/src/org/doubletype/ossa/Renderer.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* $Id: Renderer.java,v 1.1 2004/06/18 09:14:01 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public interface Renderer {
|
||||
boolean isRenderNeeded();
|
||||
void render(java.awt.Graphics2D a_graphics);
|
||||
}
|
||||
5
trunk/libsrc/ttf/src/org/doubletype/ossa/Tabbable.java
Normal file
5
trunk/libsrc/ttf/src/org/doubletype/ossa/Tabbable.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package org.doubletype.ossa;
|
||||
|
||||
public interface Tabbable {
|
||||
boolean isClosable();
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
// http://forums.sun.com/thread.jspa?forumID=257&threadID=453521
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.plaf.basic.BasicTabbedPaneUI;
|
||||
|
||||
public class TabbedPaneCloseButtonUI extends BasicTabbedPaneUI {
|
||||
private final int k_xButtonOffset = 19;
|
||||
private final int k_yButtonOffset = 4;
|
||||
private final int k_wButton = 14; // was 13
|
||||
private final int k_hButton = 13; // was 12
|
||||
|
||||
private int m_lastKnownSelected = -1;
|
||||
private Color m_red = new Color(217, 76, 74);
|
||||
private Color m_selectedColor = Color.white;
|
||||
private Color m_unselectedColor = new Color(160, 197, 241);
|
||||
|
||||
public TabbedPaneCloseButtonUI() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected)
|
||||
{
|
||||
if (isSelected)
|
||||
{
|
||||
g.setColor(m_selectedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.setColor(m_unselectedColor);
|
||||
}
|
||||
|
||||
g.fillRect(x, y, w, h);
|
||||
}
|
||||
|
||||
protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight)
|
||||
{
|
||||
return fontHeight + 4;
|
||||
}
|
||||
|
||||
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected)
|
||||
{
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(x, y + h - 2, x, y);
|
||||
g.drawLine(x, y, x + w, y);
|
||||
g.drawLine(x + w, y + h - 2, x + w, y);
|
||||
}
|
||||
|
||||
protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects,
|
||||
int tabIndex, Rectangle iconRect, Rectangle textRect) {
|
||||
|
||||
super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect);
|
||||
}
|
||||
|
||||
protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected)
|
||||
{
|
||||
}
|
||||
|
||||
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
|
||||
{
|
||||
if (selectedIndex < 0) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
Rectangle rect = getTabBounds(selectedIndex, calcRect);
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(x, y, rect.x, y);
|
||||
g.drawLine(rect.x + rect.width, y, x + w, y);
|
||||
g.setColor(m_selectedColor);
|
||||
g.drawLine(rect.x + 1, y, rect.x + rect.width -1, y);
|
||||
}
|
||||
|
||||
protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
|
||||
{
|
||||
}
|
||||
|
||||
protected void paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
|
||||
{
|
||||
}
|
||||
|
||||
protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h)
|
||||
{
|
||||
}
|
||||
|
||||
protected void paintText(Graphics g, int tabPlacement, java.awt.Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected)
|
||||
{
|
||||
if (tabPane.getComponentAt(tabIndex) instanceof Tabbable) {
|
||||
Tabbable tabbable = (Tabbable) tabPane.getComponentAt(tabIndex);
|
||||
if (!tabbable.isClosable()) {
|
||||
super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
|
||||
return;
|
||||
} // if
|
||||
} // if
|
||||
|
||||
if (isSelected) // isSelected
|
||||
{
|
||||
super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
|
||||
Rectangle rect = rects[tabIndex];
|
||||
g.setColor(m_red);
|
||||
int xButton = rect.x + rect.width - k_xButtonOffset; // -19
|
||||
int yButton = rect.y + k_yButtonOffset; // +4
|
||||
g.fillRect(xButton, yButton, k_wButton, k_hButton);
|
||||
g.setColor(Color.white);
|
||||
g.drawLine(xButton + 3, rect.y + 7, xButton + 9, rect.y + 13);
|
||||
g.drawLine(xButton + 9, rect.y + 7, xButton + 3, rect.y + 13);
|
||||
g.drawLine(xButton + 4, rect.y + 7, xButton + 10, rect.y + 13);
|
||||
g.drawLine(xButton + 10, rect.y + 7, xButton + 4, rect.y + 13);
|
||||
|
||||
m_lastKnownSelected = tabIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
|
||||
}
|
||||
}
|
||||
|
||||
protected int calculateTabWidth(int tabPlacement, int tabIndex,
|
||||
FontMetrics metrics) {
|
||||
if (tabPane.getComponentAt(tabIndex) instanceof Tabbable) {
|
||||
Tabbable tabbable = (Tabbable) tabPane.getComponentAt(tabIndex);
|
||||
if (!tabbable.isClosable()) {
|
||||
return super.calculateTabWidth(tabPlacement, tabIndex, metrics);
|
||||
} // if
|
||||
} // if
|
||||
|
||||
return super.calculateTabWidth(tabPlacement, tabIndex, metrics) + 34; // +24
|
||||
}
|
||||
|
||||
protected MouseListener createMouseListener() {
|
||||
return new MyMouseHandler();
|
||||
}
|
||||
|
||||
class MyMouseHandler extends MouseHandler {
|
||||
private int m_selectedOnPressed = -1;
|
||||
|
||||
public MyMouseHandler() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
m_selectedOnPressed = m_lastKnownSelected;
|
||||
super.mousePressed(e);
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
int x = e.getX();
|
||||
int y = e.getY();
|
||||
int tabIndex = -1;
|
||||
int tabCount = tabPane.getTabCount();
|
||||
for (int i = 0; i < tabCount; i++) {
|
||||
if (rects[i].contains(x, y)) {
|
||||
tabIndex = i;
|
||||
break;
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
// skip if this is not current.
|
||||
if (tabPane.getSelectedIndex() != tabIndex) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
if (m_selectedOnPressed != tabIndex) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
if (tabIndex >= 0 && !e.isPopupTrigger()) {
|
||||
Rectangle tabRect = rects[tabIndex];
|
||||
y = y - tabRect.y;
|
||||
|
||||
int xButton = tabRect.x + tabRect.width - k_xButtonOffset;
|
||||
if ((x >= xButton + 1)
|
||||
&& (x <= xButton + k_wButton - 2)
|
||||
&& (y >= k_yButtonOffset + 1)
|
||||
&& (y <= k_yButtonOffset + k_hButton - 2)) {
|
||||
tabPane.remove(tabIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* $Id: TypefaceFileFilter.java,v 1.1 2004/01/20 03:35:27 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.io.File;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class TypefaceFileFilter extends FileFilter {
|
||||
public boolean accept(File a_file) {
|
||||
if (a_file.isDirectory())
|
||||
return true;
|
||||
|
||||
if (! (a_file.toString().toLowerCase().endsWith(".dtyp")))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//The description of this filter
|
||||
public String getDescription() {
|
||||
return "typeface files";
|
||||
}
|
||||
}
|
||||
12
trunk/libsrc/ttf/src/org/doubletype/ossa/UiBridge.java
Normal file
12
trunk/libsrc/ttf/src/org/doubletype/ossa/UiBridge.java
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
*/
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public interface UiBridge {
|
||||
void showPropertyDialog(GlyphObject a_object);
|
||||
}
|
||||
184
trunk/libsrc/ttf/src/org/doubletype/ossa/UnicodeBuilder.java
Normal file
184
trunk/libsrc/ttf/src/org/doubletype/ossa/UnicodeBuilder.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* $Id: UnicodeBuilder.java,v 1.1 2004/09/11 10:09:07 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class UnicodeBuilder {
|
||||
public static final String k_jisCharset = "ISO-2022-JP";
|
||||
|
||||
/**
|
||||
* pops dialog and asks user for unicode.
|
||||
* @return true on success, false otherwise.
|
||||
*/
|
||||
public static Long askUnicode() {
|
||||
Engine engine = Engine.getSingletonInstance();
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static Long build(String a_value, int a_option) {
|
||||
if (a_value == null
|
||||
|| a_value.length() == 0) {
|
||||
return null;
|
||||
} // if
|
||||
|
||||
switch (a_option) {
|
||||
case Engine.SEARCH_BY_EXAMPLE: {
|
||||
return buildByExample(a_value);
|
||||
} // case
|
||||
|
||||
case Engine.SEARCH_UNICODE: {
|
||||
return buildByUnicode(a_value);
|
||||
} // case
|
||||
|
||||
case Engine.SEARCH_JIS_CODE: {
|
||||
return buildByJisCode(a_value);
|
||||
} // case
|
||||
} // switch
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Long buildByExample(String a_value) {
|
||||
if (a_value.length() > 1) {
|
||||
return null;
|
||||
} // if
|
||||
|
||||
return new Long((long) a_value.charAt(0));
|
||||
}
|
||||
|
||||
private static Long buildByUnicode(String a_value) {
|
||||
if (a_value.length() == 1) {
|
||||
return buildByExample(a_value);
|
||||
} // if
|
||||
|
||||
try {
|
||||
return new Long(Long.parseLong(a_value, 16));
|
||||
} catch (NumberFormatException e) {
|
||||
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null,e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Long buildByJisCode(String a_value) {
|
||||
if (a_value.length() == 1) {
|
||||
return buildByExample(a_value);
|
||||
} // if
|
||||
|
||||
try {
|
||||
Long retval = jisX0208ToUnicode(Long.parseLong(a_value, 16));
|
||||
|
||||
if (retval == null) {
|
||||
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, "Bad JIS Code.");
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
} catch (NumberFormatException e) {
|
||||
Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null, e);
|
||||
} // try
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts JIS X0208 code into unicode using ISO-2022-JP decoder.
|
||||
* @param a_value JIS code
|
||||
* @return unicode
|
||||
*/
|
||||
public static Long jisX0208ToUnicode(long a_value) {
|
||||
if (!isJisSupported()) {
|
||||
return null;
|
||||
} // if
|
||||
|
||||
Charset jis = Charset.forName(k_jisCharset);
|
||||
ByteBuffer in = ByteBuffer.allocate(5);
|
||||
CharsetDecoder jisDecoder;
|
||||
jisDecoder = jis.newDecoder();
|
||||
|
||||
long high = (0xff00 & a_value) >> 8;
|
||||
long low = 0x00ff & a_value;
|
||||
|
||||
if (high < 0x21 || high > 0x7e || low < 0x21 || high > 0x7e) {
|
||||
return null;
|
||||
} // if
|
||||
|
||||
char c = (char) a_value;
|
||||
|
||||
in.rewind();
|
||||
in.put((byte) 0x1b);
|
||||
in.put((byte) 0x24);
|
||||
in.put((byte) 0x40);
|
||||
|
||||
in.putChar(c);
|
||||
in.position(0);
|
||||
|
||||
try {
|
||||
CharBuffer out = jisDecoder.decode(in);
|
||||
if (out.length() > 0) {
|
||||
return new Long(out.get(0));
|
||||
} // if
|
||||
} catch (CharacterCodingException e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isJisSupported() {
|
||||
return Charset.isSupported(k_jisCharset);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public UnicodeBuilder() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* $Id: CubicSegment.java,v 1.2 2004/12/27 04:56:02 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.util.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
import org.doubletype.ossa.xml.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class CubicSegment {
|
||||
public static final int LINE = 0;
|
||||
public static final int CURVE = 1;
|
||||
|
||||
private static final double k_tolerance = 5;
|
||||
private static final double k_minTolerance = 10;
|
||||
private static final int k_maxTrial = 3;
|
||||
|
||||
/**
|
||||
* converts cubic contour into cubic segments.
|
||||
* @param a_contour
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<CubicSegment> toSegments(EContour a_contour) {
|
||||
ArrayList<CubicSegment> retval = new ArrayList<>();
|
||||
XContourPoint [] points = a_contour.getContourPoint();
|
||||
if (points.length < 2) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
EContourPoint startPoint = (EContourPoint) points[points.length - 1];
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
EContourPoint endPoint = (EContourPoint) points[i];
|
||||
retval.add(new CubicSegment(startPoint, endPoint));
|
||||
startPoint = endPoint;
|
||||
} // for
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts cubic segments into cubic contour.
|
||||
* @param a_segments
|
||||
* @return
|
||||
*/
|
||||
public static EContour toContour(ArrayList a_segments) {
|
||||
EContour retval = new EContour();
|
||||
retval.setType(EContour.k_cubic);
|
||||
|
||||
EControlPoint controlPoint1 = null;
|
||||
for (int i = 0; i < a_segments.size(); i++) {
|
||||
CubicSegment segment = (CubicSegment) a_segments.get(i);
|
||||
EContourPoint startPoint = (EContourPoint) segment.m_startPoint.clone();
|
||||
|
||||
if (controlPoint1 != null) {
|
||||
startPoint.setControlPoint1(controlPoint1);
|
||||
controlPoint1 = null;
|
||||
} // if
|
||||
|
||||
if (segment.m_controlPoint1 != null) {
|
||||
EControlPoint controlPoint2 = new EControlPoint(false,
|
||||
segment.m_controlPoint1.getX(),
|
||||
segment.m_controlPoint1.getY());
|
||||
startPoint.setControlPoint2(controlPoint2);
|
||||
} // if
|
||||
|
||||
retval.addContourPoint(startPoint);
|
||||
|
||||
if (segment.m_controlPoint2 != null) {
|
||||
controlPoint1 = new EControlPoint(true,
|
||||
segment.m_controlPoint2.getX(),
|
||||
segment.m_controlPoint2.getY());
|
||||
}
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private EContourPoint m_startPoint = null;
|
||||
private EContourPoint m_controlPoint1 = null;
|
||||
private EContourPoint m_controlPoint2 = null;
|
||||
private EContourPoint m_endPoint = null;
|
||||
|
||||
private int m_type = LINE;
|
||||
|
||||
|
||||
public CubicSegment(EContourPoint a_startPoint, EContourPoint a_endPoint) {
|
||||
m_startPoint = a_startPoint;
|
||||
m_endPoint = a_endPoint;
|
||||
|
||||
if ((!a_startPoint.hasControlPoint2()) && (!a_endPoint.hasControlPoint1())) {
|
||||
m_type = LINE;
|
||||
return;
|
||||
} // if
|
||||
|
||||
if (a_startPoint.hasControlPoint2() || a_endPoint.hasControlPoint1()) {
|
||||
m_type = CURVE;
|
||||
|
||||
if (a_startPoint.hasControlPoint2()) {
|
||||
m_controlPoint1 = (EContourPoint) a_startPoint.getControlPoint2().getContourPoint();
|
||||
} else {
|
||||
m_controlPoint1 = a_startPoint;
|
||||
} // if-else
|
||||
|
||||
if (a_endPoint.hasControlPoint1()) {
|
||||
m_controlPoint2 = (EContourPoint) a_endPoint.getControlPoint1().getContourPoint();
|
||||
} else {
|
||||
m_controlPoint2 = a_endPoint;
|
||||
} // if-else
|
||||
} // if
|
||||
}
|
||||
|
||||
public CubicSegment(EContourPoint a_startPoint, EContourPoint a_controlPoint1,
|
||||
EContourPoint a_controlPoint2, EContourPoint a_endPoint) {
|
||||
m_startPoint = a_startPoint;
|
||||
m_controlPoint1 = a_controlPoint1;
|
||||
m_controlPoint2 = a_controlPoint2;
|
||||
m_endPoint = a_endPoint;
|
||||
m_type = CURVE;
|
||||
}
|
||||
|
||||
public ArrayList<QuadraticSegment> toQuadraticSegments() {
|
||||
ArrayList<QuadraticSegment> retval = new ArrayList<>();
|
||||
|
||||
if (m_type == LINE) {
|
||||
retval.add(new QuadraticSegment(m_startPoint, null, m_endPoint));
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
return toQuadraticSegments(0);
|
||||
}
|
||||
|
||||
//JPEXS start
|
||||
private static Point2D.Double movePoint(Point2D point, double dx, double dy) {
|
||||
return new Point2D.Double(point.getX() + dx, point.getY() + dy);
|
||||
}
|
||||
|
||||
private static Point2D getMidPoint(Point2D p0, Point2D p1) {
|
||||
return getPointOnSegment(p0, p1, 0.5);
|
||||
}
|
||||
|
||||
private static Point2D getPointOnSegment(Point2D p0, Point2D p1, double ratio) {
|
||||
double x = p0.getX() + ((p1.getX() - p0.getX()) * ratio);
|
||||
double y = p0.getY() + ((p1.getY() - p0.getY()) * ratio);
|
||||
return new Point2D.Double(x, y);
|
||||
}
|
||||
private static double[][] approximateCubic(double[] cubicControlPointCoords) {
|
||||
if (cubicControlPointCoords.length < 8) {
|
||||
throw new IllegalArgumentException("Must have at least 8 coordinates");
|
||||
}
|
||||
|
||||
//extract point objects from source array
|
||||
Point2D p0 = new Point2D.Double(cubicControlPointCoords[0], cubicControlPointCoords[1]);
|
||||
Point2D p1 = new Point2D.Double(cubicControlPointCoords[2], cubicControlPointCoords[3]);
|
||||
Point2D p2 = new Point2D.Double(cubicControlPointCoords[4], cubicControlPointCoords[5]);
|
||||
Point2D p3 = new Point2D.Double(cubicControlPointCoords[6], cubicControlPointCoords[7]);
|
||||
|
||||
//calculates the useful base points
|
||||
Point2D pa = getPointOnSegment(p0, p1, 3.0 / 4.0);
|
||||
Point2D pb = getPointOnSegment(p3, p2, 3.0 / 4.0);
|
||||
|
||||
//get 1/16 of the [P3, P0] segment
|
||||
double dx = (p3.getX() - p0.getX()) / 16.0;
|
||||
double dy = (p3.getY() - p0.getY()) / 16.0;
|
||||
|
||||
//calculates control point 1
|
||||
Point2D pc1 = getPointOnSegment(p0, p1, 3.0 / 8.0);
|
||||
|
||||
//calculates control point 2
|
||||
Point2D pc2 = getPointOnSegment(pa, pb, 3.0 / 8.0);
|
||||
pc2 = movePoint(pc2, -dx, -dy);
|
||||
|
||||
//calculates control point 3
|
||||
Point2D pc3 = getPointOnSegment(pb, pa, 3.0 / 8.0);
|
||||
pc3 = movePoint(pc3, dx, dy);
|
||||
|
||||
//calculates control point 4
|
||||
Point2D pc4 = getPointOnSegment(p3, p2, 3.0 / 8.0);
|
||||
|
||||
//calculates the 3 anchor points
|
||||
Point2D pa1 = getMidPoint(pc1, pc2);
|
||||
Point2D pa2 = getMidPoint(pa, pb);
|
||||
Point2D pa3 = getMidPoint(pc3, pc4);
|
||||
|
||||
//return the points for the four quadratic curves
|
||||
return new double[][]{
|
||||
{pc1.getX(), pc1.getY(), pa1.getX(), pa1.getY()},
|
||||
{pc2.getX(), pc2.getY(), pa2.getX(), pa2.getY()},
|
||||
{pc3.getX(), pc3.getY(), pa3.getX(), pa3.getY()},
|
||||
{pc4.getX(), pc4.getY(), p3.getX(), p3.getY()}};
|
||||
}
|
||||
|
||||
//JPEXS end
|
||||
|
||||
private ArrayList<QuadraticSegment> toQuadraticSegments(int a_trial) {
|
||||
ArrayList<QuadraticSegment> retval = new ArrayList<>();
|
||||
|
||||
a_trial++;
|
||||
|
||||
double[][] quadCoords =approximateCubic(new double[]{m_startPoint.getX(),m_startPoint.getY(),m_controlPoint1.getX(),m_controlPoint1.getY(),m_controlPoint2.getX(),m_controlPoint2.getY(),m_endPoint.getX(),m_endPoint.getY()});
|
||||
EContourPoint lastPoint=m_startPoint;
|
||||
for (int i = 0; i < quadCoords.length; i++) {
|
||||
retval.add(new QuadraticSegment(
|
||||
lastPoint,
|
||||
new EContourPoint(quadCoords[i][0], quadCoords[i][1], true),
|
||||
new EContourPoint(quadCoords[i][2], quadCoords[i][3], false)));
|
||||
lastPoint = new EContourPoint(quadCoords[i][2],quadCoords[i][3],true);
|
||||
}
|
||||
/*EContourPoint intersection = calculateIntersection();
|
||||
|
||||
double deltaX = 0.125 * (m_startPoint.getX() + m_endPoint.getX() + 4 * intersection.getX()
|
||||
- 3 * (m_controlPoint1.getX() + m_controlPoint2.getX()));
|
||||
double deltaY = 0.125 * (m_startPoint.getY() + m_endPoint.getY() + 4 * intersection.getY()
|
||||
- 3 * (m_controlPoint1.getY() + m_controlPoint2.getY()));
|
||||
double deltaSqr = (deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
if (deltaSqr > (k_minTolerance * k_minTolerance)
|
||||
|| ((a_trial < k_maxTrial) && (deltaSqr > (k_tolerance * k_tolerance)))) {
|
||||
return toSplitQuadraticSegments(a_trial);
|
||||
} // if
|
||||
|
||||
retval.add(new QuadraticSegment(m_startPoint, intersection, m_endPoint));*/
|
||||
return retval;
|
||||
}
|
||||
|
||||
private ArrayList<QuadraticSegment> toSplitQuadraticSegments(int a_trial) {
|
||||
EContourPoint p01 = midPoint(m_startPoint, m_controlPoint1);
|
||||
EContourPoint p12 = midPoint(m_controlPoint1, m_controlPoint2);
|
||||
EContourPoint p23 = midPoint(m_controlPoint2, m_endPoint);
|
||||
|
||||
EContourPoint pA = midPoint(p01, p12);
|
||||
EContourPoint pB = midPoint(p12, p23);
|
||||
|
||||
EContourPoint pAB = midPoint(pA, pB);
|
||||
|
||||
CubicSegment firstCubicSegment = new CubicSegment(m_startPoint, p01, pA, pAB);
|
||||
CubicSegment secondCubicSegment = new CubicSegment(pAB, pB, p23, m_endPoint);
|
||||
|
||||
ArrayList<QuadraticSegment> firstHalf = firstCubicSegment.toQuadraticSegments(a_trial);
|
||||
ArrayList<QuadraticSegment> secondHalf = secondCubicSegment.toQuadraticSegments(a_trial);
|
||||
|
||||
firstHalf.addAll(secondHalf);
|
||||
|
||||
return firstHalf;
|
||||
}
|
||||
|
||||
private EContourPoint midPoint(EContourPoint a_start, EContourPoint a_end) {
|
||||
Point2D p = calculateMidPoint(a_start, a_end);
|
||||
EContourPoint retval = new EContourPoint(p.getX(), p.getY(), true);
|
||||
|
||||
ArrayList ppems = getPpems(a_start, a_end);
|
||||
EPoint startPoint, endPoint;
|
||||
for (int i = 0; i < ppems.size(); i++) {
|
||||
Long ppemObject = (Long) ppems.get(i);
|
||||
long ppem = ppemObject.longValue();
|
||||
|
||||
if (retval.hasHintForPpem(ppem)) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
startPoint = a_start.getHintIfPossible(ppem);
|
||||
endPoint = a_end.getHintIfPossible(ppem);
|
||||
|
||||
p = calculateMidPoint(startPoint, endPoint);
|
||||
EHint hint = new EHint(p.getX(), p.getY(), ppem);
|
||||
retval.addHint(hint);
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private Point2D calculateMidPoint(EPoint a_p1, EPoint a_p2) {
|
||||
Point2D retval = new Point2D.Double((a_p1.getX() + a_p2.getX()) / 2.0,
|
||||
(a_p1.getY() + a_p2.getY()) / 2.0);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* calculate intersection of line (a_start, a_controlPoint1) and
|
||||
* line (a_end, a_controlPoint2)
|
||||
* @return
|
||||
*/
|
||||
private EContourPoint calculateIntersection() {
|
||||
EContourPoint retval = new EContourPoint(m_startPoint.getX(), m_startPoint.getY(), false);
|
||||
Point2D intersection = calculateIntersection(m_startPoint, m_controlPoint1, m_controlPoint2, m_endPoint);
|
||||
retval.getPoint2d().setX(intersection.getX());
|
||||
retval.getPoint2d().setY(intersection.getY());
|
||||
|
||||
EPoint startPoint, controlPoint1, controlPoint2, endPoint;
|
||||
ArrayList ppems = getPpems(m_startPoint, m_controlPoint1, m_controlPoint2, m_endPoint);
|
||||
for (int i = 0; i < ppems.size(); i++) {
|
||||
Long ppemObject = (Long) ppems.get(i);
|
||||
long ppem = ppemObject.longValue();
|
||||
|
||||
if (retval.hasHintForPpem(ppem)) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
startPoint = m_startPoint.getHintIfPossible(ppem);
|
||||
controlPoint1 = m_controlPoint1.getHintIfPossible(ppem);
|
||||
controlPoint2 = m_controlPoint2.getHintIfPossible(ppem);
|
||||
endPoint = m_endPoint.getHintIfPossible(ppem);
|
||||
|
||||
Point2D p = calculateIntersection(startPoint, controlPoint1, controlPoint2, endPoint);
|
||||
EHint hint = new EHint(p.getX(), p.getY(), ppem);
|
||||
retval.addHint(hint);
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private Point2D calculateIntersection(EPoint a_p1, EPoint a_p2, EPoint a_p3, EPoint a_p4) {
|
||||
Point2D retval = new Point2D.Double(a_p1.getX(), a_p1.getY());
|
||||
|
||||
double deltaX1 = a_p2.getX() - a_p1.getX();
|
||||
double deltaX2 = a_p3.getX() - a_p4.getX();
|
||||
if (deltaX1 == 0) {
|
||||
deltaX1 = 0.1;
|
||||
} // if
|
||||
if (deltaX2 == 0) {
|
||||
deltaX2 = 0.2;
|
||||
} // if
|
||||
|
||||
double incline1 = (a_p2.getY() - a_p1.getY()) / deltaX1;
|
||||
double incline2 = (a_p3.getY() - a_p4.getY()) / deltaX2;
|
||||
if (incline1 == incline2) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
double x = (-incline2 * a_p4.getX() + a_p4.getY()
|
||||
+incline1 * a_p1.getX() - a_p1.getY()) / (incline1 - incline2);
|
||||
double y = incline1 * (x - a_p1.getX()) + a_p1.getY();
|
||||
|
||||
retval.setLocation(x, y);
|
||||
return retval;
|
||||
}
|
||||
|
||||
private ArrayList<Long> getPpems(EContourPoint a_start, EContourPoint a_end) {
|
||||
ArrayList<Long> retval = new ArrayList<>();
|
||||
collectPpemsFromHints(retval, a_start.getHint());
|
||||
collectPpemsFromHints(retval, a_end.getHint());
|
||||
return retval;
|
||||
}
|
||||
|
||||
private void collectPpemsFromHints(ArrayList<Long> a_ppems, XHint[] a_hints) {
|
||||
for (XHint hint: a_hints) {
|
||||
if (!a_ppems.contains(hint.getPpem())) {
|
||||
a_ppems.add(hint.getPpem());
|
||||
} // if
|
||||
} // for i
|
||||
}
|
||||
|
||||
private ArrayList<Long> getPpems(EContourPoint a_start, EContourPoint a_controlPoint1,
|
||||
EContourPoint a_controlPoint2, EContourPoint a_end) {
|
||||
ArrayList<Long> retval = new ArrayList<>();
|
||||
collectPpemsFromHints(retval, a_start.getHint());
|
||||
collectPpemsFromHints(retval, a_controlPoint1.getHint());
|
||||
collectPpemsFromHints(retval, a_controlPoint2.getHint());
|
||||
collectPpemsFromHints(retval, a_end.getHint());
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
||||
243
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EContour.java
Normal file
243
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EContour.java
Normal file
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* $Id: EContour.java,v 1.11 2004/12/17 04:13:17 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import org.doubletype.ossa.*;
|
||||
import org.doubletype.ossa.module.Rectangle;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class EContour extends XContour implements GlyphObject, PointAggregate {
|
||||
public static final String k_quadratic = "quadratic";
|
||||
public static final String k_cubic = "cubic";
|
||||
public static final int k_defaultPixelSize = 16;
|
||||
|
||||
public static EContour createAt(Point2D a_point) {
|
||||
EContour retval = new EContour();
|
||||
retval.setType(k_cubic);
|
||||
|
||||
EContourPoint point;
|
||||
double x, y;
|
||||
|
||||
x = a_point.getX();
|
||||
y = a_point.getY();
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
|
||||
x += Rectangle.k_defaultPen;
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
y += Rectangle.k_defaultPen;
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
x -= Rectangle.k_defaultPen;
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public EContour() {
|
||||
initDefaults();
|
||||
}
|
||||
|
||||
public EContour(RStack a_stack) {
|
||||
super(a_stack);
|
||||
initDefaults();
|
||||
}
|
||||
|
||||
/** set default values
|
||||
*/
|
||||
private void initDefaults() {
|
||||
if (getType() == null) {
|
||||
setType(k_quadratic);
|
||||
} // if
|
||||
}
|
||||
|
||||
public boolean isCubic() {
|
||||
return getType().equals(k_cubic);
|
||||
}
|
||||
|
||||
public EContour transpose(AffineTransform a_trans) {
|
||||
EContour retval = new EContour();
|
||||
retval.setType(this.getType());
|
||||
|
||||
XContourPoint[] points = getContourPoint();
|
||||
int i;
|
||||
for (i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
retval.addContourPoint(point.transpose(a_trans));
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public void display(Graphics2D g, AffineTransform a_trans) {
|
||||
g.setColor(GlyphColor.CONTOUR);
|
||||
|
||||
if (isSelected()) {
|
||||
g.setColor(GlyphColor.SELECTED);
|
||||
} // if
|
||||
|
||||
int ppem =EContour.k_defaultPixelSize;
|
||||
g.draw(toShape(a_trans, ppem));
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return EObject.getActives().isSelected(this);
|
||||
}
|
||||
|
||||
public Shape toShape(AffineTransform a_trans, int a_ppem) {
|
||||
return transpose(a_trans).toShape(a_ppem);
|
||||
}
|
||||
|
||||
private Shape toShape(int a_ppem) {
|
||||
Emulator emulator = Emulator.getInstance();
|
||||
|
||||
return emulator.createShape(this, a_ppem);
|
||||
}
|
||||
|
||||
public void move(Point2D a_delta) {
|
||||
movePoints(getContourPoint(), a_delta);
|
||||
}
|
||||
|
||||
private void movePoints(XContourPoint [] a_points, Point2D a_delta) {
|
||||
int i;
|
||||
for (i = 0; i < a_points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) a_points[i];
|
||||
EObject.movePoint(point, a_delta);
|
||||
} // for i
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
XBody parent = (XBody) rGetParentRNode();
|
||||
parent.removeContour(this);
|
||||
}
|
||||
|
||||
// PointAggregate
|
||||
public void removePoint(EContourPoint a_point) {
|
||||
removeContourPoint(a_point);
|
||||
|
||||
if (getContourPoint().length < 2) {
|
||||
remove();
|
||||
} // if
|
||||
}
|
||||
|
||||
// PointAggregate
|
||||
public void movePoint(EContourPoint a_point, Point2D a_delta) {
|
||||
EObject.movePoint(a_point, a_delta);
|
||||
}
|
||||
|
||||
// PointAggregate
|
||||
public GlyphObject insertPoint(EContourPoint a_point) {
|
||||
int i;
|
||||
int len = getContourPoint().length;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (getContourPoint(i) == a_point) {
|
||||
break;
|
||||
} // if
|
||||
} // for
|
||||
|
||||
EContourPoint nextPoint;
|
||||
nextPoint = (EContourPoint) getContourPoint((i + 1) % len);
|
||||
|
||||
double x = (a_point.getX() + nextPoint.getX()) / 2;
|
||||
double y = (a_point.getY() + nextPoint.getY()) / 2;
|
||||
|
||||
EContourPoint retval = new EContourPoint(x, y, true);
|
||||
addContourPoint(i + 1, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
return EObject.hit(this, a_rect, a_trans);
|
||||
}
|
||||
|
||||
public void convert() {
|
||||
XBody parent = (XBody) rGetParentRNode();
|
||||
|
||||
if (isCubic()) {
|
||||
parent.addContour(toQuadratic());
|
||||
} else {
|
||||
parent.addContour(toCubic());
|
||||
} // else
|
||||
|
||||
remove();
|
||||
}
|
||||
|
||||
public EContour toQuadratic() {
|
||||
if (!isCubic()) {
|
||||
return this;
|
||||
} // if
|
||||
|
||||
ArrayList<QuadraticSegment> quadraticSegments = new ArrayList<>();
|
||||
for (CubicSegment segment: CubicSegment.toSegments(this)) {
|
||||
quadraticSegments.addAll(segment.toQuadraticSegments());
|
||||
} // for i
|
||||
|
||||
return QuadraticSegment.toContour(quadraticSegments);
|
||||
}
|
||||
|
||||
public EContour toCubic() {
|
||||
if (isCubic()) {
|
||||
return this;
|
||||
} // if
|
||||
|
||||
ArrayList quadraticSegments = QuadraticSegment.toSegments(this);
|
||||
ArrayList<CubicSegment> cubicSegments = new ArrayList<>();
|
||||
for (int i = 0; i < quadraticSegments.size(); i++) {
|
||||
QuadraticSegment quadraticSegment = (QuadraticSegment) quadraticSegments.get(i);
|
||||
cubicSegments.add(quadraticSegment.toCubicSegment());
|
||||
} // for i
|
||||
|
||||
return CubicSegment.toContour(cubicSegments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
* $Id: EContourPoint.java,v 1.10 2004/12/27 04:56:02 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import org.doubletype.ossa.*;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class EContourPoint extends XContourPoint implements GlyphObject, EPoint {
|
||||
public static String k_on = "on";
|
||||
public static String k_off = "off";
|
||||
public static String k_true = "true";
|
||||
public static String k_false = "false";
|
||||
|
||||
private int m_number = 0;
|
||||
|
||||
/** offset of this from the global coord.
|
||||
* For contours, it will be 0.
|
||||
* For module invoke, it will be pos.x.
|
||||
*/
|
||||
private double m_xOffset = 0;
|
||||
private double m_yOffset = 0;
|
||||
|
||||
private Point2D m_adjusted;
|
||||
|
||||
public EContourPoint() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EContourPoint(RStack a_stack) {
|
||||
super(a_stack);
|
||||
correctControlPoint();
|
||||
}
|
||||
|
||||
public EContourPoint(double a_x, double a_y, boolean a_isOn) {
|
||||
setPoint2d(new XPoint2d());
|
||||
getPoint2d().setX(a_x);
|
||||
getPoint2d().setY(a_y);
|
||||
|
||||
setOn(a_isOn);
|
||||
}
|
||||
|
||||
/** Move the second control point if it was incorrectly set to the first one.
|
||||
*
|
||||
*/
|
||||
private void correctControlPoint() {
|
||||
if (!hasControlPoint1()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
EControlPoint controlPoint = (EControlPoint) getControlPoint1();
|
||||
if (controlPoint.isFirst()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
setControlPoint2(controlPoint);
|
||||
setControlPoint1(null);
|
||||
}
|
||||
|
||||
public EContourPoint transpose(AffineTransform a_trans) {
|
||||
EContourPoint retval = new EContourPoint();
|
||||
|
||||
retval.setPoint2d(EObject.createTransform(getPoint2d(), a_trans));
|
||||
retval.setOn(isOn());
|
||||
retval.setRounded(isRounded());
|
||||
|
||||
if (hasControlPoint1()) {
|
||||
EControlPoint controlPoint = (EControlPoint) getControlPoint1();
|
||||
retval.setControlPoint1(controlPoint.transpose(a_trans));
|
||||
} // if
|
||||
if (hasControlPoint2()) {
|
||||
EControlPoint controlPoint = (EControlPoint) getControlPoint2();
|
||||
retval.setControlPoint2(controlPoint.transpose(a_trans));
|
||||
} // if
|
||||
|
||||
int i;
|
||||
XHint [] hints = getHint();
|
||||
for (i = 0; i < hints.length; i++) {
|
||||
EHint hint = (EHint) hints[i];
|
||||
retval.addHint(hint.createTransform(a_trans));
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void setNumber(int a_number) {
|
||||
m_number = a_number;
|
||||
}
|
||||
|
||||
public void setOffset(double a_x, double a_y) {
|
||||
m_xOffset = a_x;
|
||||
m_yOffset = a_y;
|
||||
}
|
||||
|
||||
private AffineTransform buildOffsetTrans(AffineTransform a_trans) {
|
||||
if (m_xOffset == 0 && m_yOffset == 0) {
|
||||
return a_trans;
|
||||
} // if
|
||||
|
||||
AffineTransform retval = (AffineTransform) a_trans.clone();
|
||||
retval.translate(m_xOffset, m_yOffset);
|
||||
|
||||
return retval;
|
||||
}
|
||||
public static final int k_defaultPixelSize = 16;
|
||||
|
||||
public void display(Graphics2D g, AffineTransform a_trans) {
|
||||
AffineTransform trans = buildOffsetTrans(a_trans);
|
||||
|
||||
int ppem = k_defaultPixelSize;
|
||||
Shape rect = toShape(trans, ppem);
|
||||
g.setColor(GlyphColor.POINT);
|
||||
if (isRounded()) {
|
||||
g.setColor(GlyphColor.GRAY);
|
||||
} // if
|
||||
|
||||
if (isSelected()) {
|
||||
g.setColor(GlyphColor.SELECTED);
|
||||
} // if
|
||||
|
||||
if (isOn())
|
||||
g.fill(rect);
|
||||
else
|
||||
g.draw(rect);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isSelected() {
|
||||
return EObject.getActives().isSelected(this);
|
||||
}
|
||||
|
||||
public void resetAdjusted() {
|
||||
setAdjusted(getX(), getY());
|
||||
}
|
||||
|
||||
public void roundAdjusted(int a_ppem) {
|
||||
if (!isRounded()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
setAdjusted(round(getX(), a_ppem),
|
||||
round(getY(), a_ppem));
|
||||
}
|
||||
|
||||
public void hintAdjusted(int a_ppem) {
|
||||
if (!hasHintForPpem(a_ppem)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
EHint hint = getHintForPpem(a_ppem);
|
||||
setAdjusted(hint.getX(), hint.getY());
|
||||
}
|
||||
|
||||
public void setAdjusted(double a_x, double a_y) {
|
||||
m_adjusted = new Point2D.Double(a_x, a_y);
|
||||
}
|
||||
|
||||
public Point2D getAdjusted() {
|
||||
return m_adjusted;
|
||||
}
|
||||
|
||||
public Shape toShape(AffineTransform a_trans, int a_ppem) {
|
||||
return EObject.toShape(getPoint2d(), a_trans);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return getPoint2d().getX();
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return getPoint2d().getY();
|
||||
}
|
||||
|
||||
public boolean isOn() {
|
||||
return getType().equals(k_on);
|
||||
}
|
||||
|
||||
public boolean isRounded() {
|
||||
return getRounded();
|
||||
}
|
||||
|
||||
public void toggleRounded() {
|
||||
if (hasHintForCurrentPpem()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
setRounded(!isRounded());
|
||||
}
|
||||
|
||||
public Point2D toPoint2D() {
|
||||
return new Point2D.Double(getX(), getY());
|
||||
}
|
||||
|
||||
public boolean hasHint() {
|
||||
return (getHint().length > 0);
|
||||
}
|
||||
|
||||
public boolean hasHintForCurrentPpem() {
|
||||
return hasHintForPpem(EContour.k_defaultPixelSize);
|
||||
}
|
||||
|
||||
public boolean hasHintForPpem(long a_ppem) {
|
||||
return getHintForPpem(a_ppem) != null;
|
||||
}
|
||||
|
||||
public EPoint getHintIfPossible(long a_ppem) {
|
||||
if (hasHintForPpem(a_ppem)) {
|
||||
return getHintForPpem(a_ppem);
|
||||
} // if
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public EHint getCurrentHint() {
|
||||
return getHintForPpem(EContour.k_defaultPixelSize);
|
||||
}
|
||||
|
||||
public EHint getHintForPpem(long a_ppem) {
|
||||
int i;
|
||||
XHint[] hints = getHint();
|
||||
for (i = 0; i < hints.length; i++) {
|
||||
EHint hint = (EHint) hints[i];
|
||||
if (hint.getPpem() == a_ppem) {
|
||||
return hint;
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public EHint addHint(int a_ppem) {
|
||||
if (hasHintForPpem(a_ppem)) {
|
||||
return getHintForPpem(a_ppem);
|
||||
} // if
|
||||
|
||||
EHint retval = new EHint(getX() + Engine.getEm() / a_ppem, getY(), a_ppem);
|
||||
addHint(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
public GlyphObject add() {
|
||||
return getParent().insertPoint(this);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
getParent().removePoint(this);
|
||||
}
|
||||
|
||||
public PointAggregate getParent() {
|
||||
if (rGetParentRNode() instanceof EControlPoint) {
|
||||
EControlPoint controlPoint = (EControlPoint) rGetParentRNode();
|
||||
return controlPoint.getParent().getParent();
|
||||
}
|
||||
|
||||
if (rGetParentRNode() instanceof PointAggregate) {
|
||||
return (PointAggregate) rGetParentRNode();
|
||||
} // if
|
||||
|
||||
return (PointAggregate) rGetParentRNode();
|
||||
}
|
||||
|
||||
public XContourPoint cloneAt(Point2D a_point) {
|
||||
EContourPoint retval = (EContourPoint) clone();
|
||||
Point2D delta = new Point2D.Double(a_point.getX() - this.getX(), a_point.getY() - this.getY());
|
||||
EObject.movePoint(retval, delta);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** Moves point by the specified delta. A GlyphObject method.
|
||||
* Delegates the implementation to the host since a point
|
||||
* moves differently depending on the host.
|
||||
* For example the first point hosted by a module invoke would
|
||||
* always be (0, 0) so the invoke position would move instead.
|
||||
*/
|
||||
public void move(Point2D a_delta) {
|
||||
PointAggregate parent = (PointAggregate) rGetParentRNode();
|
||||
parent.movePoint(this, a_delta);
|
||||
}
|
||||
|
||||
public void toggleOnCurve() {
|
||||
if (isControlPoint()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
if (getParent() instanceof EContour) {
|
||||
EContour contour = (EContour) getParent();
|
||||
if (contour.isCubic()) {
|
||||
toggleCubicControlPoint();
|
||||
return;
|
||||
} // if
|
||||
} // if
|
||||
|
||||
setOn(!isOn());
|
||||
}
|
||||
|
||||
public boolean isControlPoint() {
|
||||
return (getParent() instanceof EContourPoint);
|
||||
}
|
||||
|
||||
private void toggleCubicControlPoint() {
|
||||
if (hasControlPoint1() || hasControlPoint2()) {
|
||||
setControlPoint1(null);
|
||||
setControlPoint2(null);
|
||||
} else {
|
||||
setControlPoint1(new EControlPoint(true, getX() + 100, getY()));
|
||||
setControlPoint2(new EControlPoint(false, getX() - 100, getY()));
|
||||
} // if
|
||||
}
|
||||
|
||||
public boolean hasControlPoint1() {
|
||||
return (getControlPoint1() != null);
|
||||
}
|
||||
|
||||
public boolean hasControlPoint2() {
|
||||
return (getControlPoint2() != null);
|
||||
}
|
||||
|
||||
public void setOn(boolean a_isOnCurve) {
|
||||
if (a_isOnCurve) {
|
||||
setType(k_on);
|
||||
} else {
|
||||
setType(k_off);
|
||||
} // if
|
||||
}
|
||||
|
||||
public boolean hitHint(Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
int ppem = EContour.k_defaultPixelSize;
|
||||
if (!hasHintForPpem(ppem))
|
||||
return false;
|
||||
|
||||
EHint hint = getHintForPpem(ppem);
|
||||
|
||||
Shape hitArea = hint.toShape(a_trans, ppem);
|
||||
if (!hitArea.intersects(a_rect)) {
|
||||
return false;
|
||||
} // if
|
||||
|
||||
EObject.getActives().addActive(hint);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
return EObject.hit(this, a_rect, buildOffsetTrans(a_trans));
|
||||
}
|
||||
|
||||
/** Round the value after converting to pixel coordinate system.
|
||||
*/
|
||||
private double round(double a_value, long a_ppem) {
|
||||
double em = Engine.getEm();
|
||||
double funitInGrid = em / a_ppem;
|
||||
|
||||
double pixelValue = a_value / funitInGrid;
|
||||
return funitInGrid * roundSymetric(pixelValue);
|
||||
}
|
||||
|
||||
/** round symetrically about zero.
|
||||
* Math.round(0.5) returns 1. Math.round(-0.5) returns 0,
|
||||
* since it's Math.floor(a_value + -0.5).
|
||||
* -0.5 should round to -1 if it's symetric about zero.
|
||||
* @param a_value number to be rounded.
|
||||
* @return round value.
|
||||
*/
|
||||
private int roundSymetric(double a_value) {
|
||||
if (a_value < 0) {
|
||||
int retval = (int) Math.round(-a_value);
|
||||
return -retval;
|
||||
} else {
|
||||
return (int) Math.round(a_value);
|
||||
} // if-else
|
||||
}
|
||||
|
||||
public void removeControlPoint(EControlPoint a_point) {
|
||||
if (hasControlPoint1() && (getControlPoint1() == a_point)) {
|
||||
setControlPoint1(null);
|
||||
} // if
|
||||
|
||||
if (hasControlPoint2() && (getControlPoint2() == a_point)) {
|
||||
setControlPoint2(null);
|
||||
} // if
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* $Id: EControlPoint.java,v 1.6 2004/12/27 04:56:02 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.doubletype.ossa.GlyphColor;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class EControlPoint extends XControlPoint implements GlyphObject, EPoint {
|
||||
private static final String k_true = "true";
|
||||
|
||||
private double m_xOffset = 0;
|
||||
private double m_yOffset = 0;
|
||||
|
||||
public EControlPoint(boolean a_isFirst, double a_x, double a_y) {
|
||||
setSmooth(true);
|
||||
setFirst(a_isFirst);
|
||||
setContourPoint(new EContourPoint(a_x, a_y, false));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public EControlPoint() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack
|
||||
*/
|
||||
public EControlPoint(RStack stack) {
|
||||
super(stack);
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return EObject.getActives().isSelected(this);
|
||||
}
|
||||
|
||||
/** toggle smooth-ness
|
||||
*/
|
||||
public void convert() {
|
||||
EContourPoint parent = getParent();
|
||||
boolean value = !getSmooth();
|
||||
parent.getControlPoint1().setSmooth(value);
|
||||
parent.getControlPoint2().setSmooth(value);
|
||||
move(new Point2D.Double(0, 0));
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return getFirst();
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
return EObject.hit(this, a_rect, buildOffsetTrans(a_trans));
|
||||
}
|
||||
|
||||
public void setOffset(double a_x, double a_y) {
|
||||
m_xOffset = a_x;
|
||||
m_yOffset = a_y;
|
||||
}
|
||||
|
||||
private AffineTransform buildOffsetTrans(AffineTransform a_trans) {
|
||||
if (m_xOffset == 0 && m_yOffset == 0) {
|
||||
return a_trans;
|
||||
} // if
|
||||
|
||||
AffineTransform retval = (AffineTransform) a_trans.clone();
|
||||
retval.translate(m_xOffset, m_yOffset);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
getParent().removeControlPoint(this);
|
||||
}
|
||||
|
||||
public EContourPoint getParent() {
|
||||
return (EContourPoint) rGetParentRNode();
|
||||
}
|
||||
|
||||
public Shape toShape(AffineTransform a_trans, int a_ppem) {
|
||||
return EObject.toShape(getContourPoint().getPoint2d(), a_trans);
|
||||
}
|
||||
|
||||
public void move(Point2D a_delta) {
|
||||
// if the parent is active, she will move this.
|
||||
if (getParent().isSelected()) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
EObject.movePoint((EContourPoint) getContourPoint(), a_delta);
|
||||
|
||||
if (isSmooth() && hasSibling()) {
|
||||
smoothSibling();
|
||||
} // if
|
||||
}
|
||||
|
||||
public void rotateTo45() {
|
||||
double theta = getTheta() + Math.PI / 8;
|
||||
theta = Math.PI / 4 * Math.floor(theta / (Math.PI / 4));
|
||||
|
||||
rotateToTheta(theta);
|
||||
if (isSmooth() && hasSibling()) {
|
||||
smoothSibling();
|
||||
} // if
|
||||
}
|
||||
|
||||
private void smoothSibling() {
|
||||
getSibling().rotateToTheta(getTheta() + Math.PI);
|
||||
}
|
||||
|
||||
private double getTheta() {
|
||||
EContourPoint parent = getParent();
|
||||
return Math.atan2(getY() - parent.getY(),
|
||||
getX() - parent.getX());
|
||||
}
|
||||
|
||||
private void rotateToTheta(double a_theta) {
|
||||
EContourPoint parent = getParent();
|
||||
double d = parent.toPoint2D().distance(toPoint2D());
|
||||
double x = parent.getX() + Math.cos(a_theta) * d;
|
||||
double y = parent.getY() + Math.sin(a_theta) * d;
|
||||
Point2D delta = new Point2D.Double(x - getX(), y - getY());
|
||||
EObject.movePoint((EContourPoint) getContourPoint(), delta);
|
||||
}
|
||||
|
||||
public Point2D toPoint2D() {
|
||||
EContourPoint point = (EContourPoint) getContourPoint();
|
||||
return point.toPoint2D();
|
||||
}
|
||||
|
||||
public boolean isSmooth() {
|
||||
return getSmooth();
|
||||
}
|
||||
|
||||
public boolean hasSibling() {
|
||||
EContourPoint parent = getParent();
|
||||
if (parent.getControlPoint1() == this) {
|
||||
return parent.hasControlPoint2();
|
||||
} else {
|
||||
return parent.hasControlPoint1();
|
||||
} // if
|
||||
}
|
||||
|
||||
public EControlPoint getSibling() {
|
||||
EContourPoint parent = getParent();
|
||||
if (parent.getControlPoint1() == this) {
|
||||
return (EControlPoint) parent.getControlPoint2();
|
||||
} else {
|
||||
return (EControlPoint) parent.getControlPoint1();
|
||||
} // if
|
||||
}
|
||||
|
||||
public void display(Graphics2D g, AffineTransform a_trans) {
|
||||
AffineTransform trans = buildOffsetTrans(a_trans);
|
||||
displayLine(g, trans);
|
||||
|
||||
Shape rect = toShape(trans, EContour.k_defaultPixelSize);
|
||||
g.setColor(GlyphColor.POINT);
|
||||
if (isSelected()) {
|
||||
g.setColor(GlyphColor.SELECTED);
|
||||
} // if
|
||||
|
||||
g.draw(rect);
|
||||
}
|
||||
|
||||
private void displayLine(Graphics2D g, AffineTransform a_trans) {
|
||||
EContourPoint parent = getParent();
|
||||
Line2D line = new Line2D.Double(parent.getX(),
|
||||
parent.getY(),
|
||||
getX(),
|
||||
getY());
|
||||
AffineTransform oldTrans = g.getTransform();
|
||||
|
||||
g.transform(a_trans);
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(line);
|
||||
g.setTransform(oldTrans);
|
||||
}
|
||||
|
||||
public EControlPoint transpose(AffineTransform a_trans) {
|
||||
EControlPoint retval = new EControlPoint();
|
||||
EContourPoint point = (EContourPoint) getContourPoint();
|
||||
retval.setContourPoint(point.transpose(a_trans));
|
||||
retval.setSmooth(getSmooth());
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
public double getX() {
|
||||
EContourPoint point = (EContourPoint) getContourPoint();
|
||||
return point.getX();
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
EContourPoint point = (EContourPoint) getContourPoint();
|
||||
return point.getY();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* $Id: EGlyphFactory.java,v 1.3 2004/11/10 01:49:49 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import org.doubletype.ossa.xml.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class EGlyphFactory extends DefaultGlyphFactory {
|
||||
public static IGlyphFactory s_factory = null;
|
||||
|
||||
public static IGlyphFactory getFactory() {
|
||||
if (s_factory == null) {
|
||||
s_factory = new EGlyphFactory();
|
||||
} // if
|
||||
|
||||
return s_factory;
|
||||
}
|
||||
|
||||
public EGlyphFactory() {
|
||||
}
|
||||
|
||||
public XModule createXModule() {
|
||||
return new EModuleInvoke();
|
||||
}
|
||||
|
||||
public Class getXModuleClass() {
|
||||
return (EModuleInvoke.class);
|
||||
}
|
||||
|
||||
public XContour createXContour() {
|
||||
return new EContour();
|
||||
}
|
||||
|
||||
public Class getXContourClass() {
|
||||
return (EContour.class);
|
||||
}
|
||||
|
||||
public XInclude createXInclude() {
|
||||
return new EIncludeInvoke();
|
||||
}
|
||||
|
||||
public Class getXIncludeClass() {
|
||||
return (EIncludeInvoke.class);
|
||||
}
|
||||
|
||||
public XHint createXHint() {
|
||||
return new EHint();
|
||||
}
|
||||
|
||||
public Class getXHintClass() {
|
||||
return (EHint.class);
|
||||
}
|
||||
|
||||
public XContourPoint createXContourPoint() {
|
||||
return new EContourPoint();
|
||||
}
|
||||
|
||||
public XContourPoint createXContourPoint(RStack a_stack) {
|
||||
return new EContourPoint(a_stack);
|
||||
}
|
||||
|
||||
public Class getXContourPointClass() {
|
||||
return (EContourPoint.class);
|
||||
}
|
||||
|
||||
public XControlPoint createXControlPoint() {
|
||||
return new EControlPoint();
|
||||
}
|
||||
|
||||
|
||||
public Class getXControlPointClass() {
|
||||
return (EControlPoint.class);
|
||||
}
|
||||
}
|
||||
195
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EHint.java
Normal file
195
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EHint.java
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* $Id: EHint.java,v 1.4 2004/12/27 04:56:03 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import org.doubletype.ossa.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class EHint extends XHint implements GlyphObject, EPoint {
|
||||
/** offset of this from the global coord.
|
||||
* For contours, it will be 0.
|
||||
* For module invoke, it will be pos.x.
|
||||
* @see EContourPoint
|
||||
*/
|
||||
private double m_xOffset = 0;
|
||||
private double m_yOffset = 0;
|
||||
|
||||
public EHint() {
|
||||
}
|
||||
|
||||
public EHint(double a_x, double a_y, long a_ppem) {
|
||||
XPoint2d point = new XPoint2d();
|
||||
point.setX(a_x);
|
||||
point.setY(a_y);
|
||||
|
||||
setPoint2d(point);
|
||||
setPpem(a_ppem);
|
||||
}
|
||||
|
||||
public void setOffset(double a_x, double a_y) {
|
||||
m_xOffset = a_x;
|
||||
m_yOffset = a_y;
|
||||
}
|
||||
|
||||
private AffineTransform buildOffsetTrans(AffineTransform a_trans) {
|
||||
if (m_xOffset == 0 && m_yOffset == 0) {
|
||||
return a_trans;
|
||||
} // if
|
||||
|
||||
AffineTransform retval = (AffineTransform) a_trans.clone();
|
||||
retval.translate(m_xOffset, m_yOffset);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void display(Graphics2D g, AffineTransform a_trans) {
|
||||
AffineTransform trans = buildOffsetTrans(a_trans);
|
||||
|
||||
EContourPoint point = (EContourPoint) rGetParentRNode();
|
||||
|
||||
Shape rect = toShape(trans, EContour.k_defaultPixelSize);
|
||||
Line2D line = new Line2D.Double(point.getX(),
|
||||
point.getY(),
|
||||
getX(),
|
||||
getY());
|
||||
|
||||
AffineTransform oldTrans = g.getTransform();
|
||||
|
||||
g.transform(trans);
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(line);
|
||||
g.setTransform(oldTrans);
|
||||
|
||||
g.setColor(GlyphColor.HINT);
|
||||
if (isSelected()) {
|
||||
g.setColor(GlyphColor.SELECTED);
|
||||
} // if
|
||||
|
||||
if (point.isOn())
|
||||
g.fill(rect);
|
||||
else
|
||||
g.draw(rect);
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return EObject.getActives().isSelected(this);
|
||||
}
|
||||
|
||||
public Shape toShape(AffineTransform a_trans, int a_ppem) {
|
||||
return EObject.toShape(getPoint2d(), a_trans);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return getPoint2d().getX();
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return getPoint2d().getY();
|
||||
}
|
||||
|
||||
public Point2D toPoint2D() {
|
||||
return new Point2D.Double(getX(), getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.doubletype.ossa.adapter.DObject#move(java.awt.geom.Point2D)
|
||||
*/
|
||||
public void move(Point2D a_delta) {
|
||||
EObject.movePoint(getPoint2d(), a_delta);
|
||||
|
||||
double gridWidth = ((double) Engine.getEm()) / getPpem();
|
||||
EContourPoint point = (EContourPoint) rGetParentRNode();
|
||||
|
||||
XPoint2d posHint = getPoint2d();
|
||||
XPoint2d posPoint = point.getPoint2d();
|
||||
double xDelta = posHint.getX() - posPoint.getX();
|
||||
double yDelta = posHint.getY() - posPoint.getY();
|
||||
|
||||
xDelta = correctDelta(xDelta, gridWidth);
|
||||
yDelta = correctDelta(yDelta, gridWidth);
|
||||
|
||||
posHint.setX(posPoint.getX() + xDelta);
|
||||
posHint.setY(posPoint.getY() + yDelta);
|
||||
}
|
||||
|
||||
private double correctDelta(double a_delta, double a_width) {
|
||||
double retval = a_delta;
|
||||
|
||||
if (retval > a_width) {
|
||||
retval = a_width;
|
||||
} // if
|
||||
|
||||
if (retval < -a_width) {
|
||||
retval = -a_width;
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.doubletype.ossa.adapter.DObject#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
getParent().removeHint(this);
|
||||
}
|
||||
|
||||
public EContourPoint getParent() {
|
||||
return (EContourPoint) rGetParentRNode();
|
||||
}
|
||||
|
||||
public PointAggregate getPointHost() {
|
||||
return getParent().getParent();
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
return EObject.hit(this, a_rect, buildOffsetTrans(a_trans));
|
||||
}
|
||||
|
||||
public EHint createTransform(AffineTransform a_trans) {
|
||||
EHint retval = new EHint();
|
||||
|
||||
retval.setPpem(getPpem());
|
||||
retval.setPoint2d(EObject.createTransform(getPoint2d(), a_trans));
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* $Id: EIncludeInvoke.java,v 1.1 2004/09/04 21:54:07 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import org.doubletype.ossa.*;
|
||||
import org.doubletype.ossa.module.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class EIncludeInvoke extends XInclude implements VarStackFrame, GlyphObject {
|
||||
public static EIncludeInvoke create(String a_fileName) {
|
||||
EIncludeInvoke retval = new EIncludeInvoke();
|
||||
retval.setHref(a_fileName);
|
||||
retval.setInvoke(EObject.createInvoke(new Point2D.Double()));
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/** environment with invoke args. */
|
||||
private Hashtable<String,Double> m_augmented = new Hashtable<>();
|
||||
private VarStack m_stack = VarStack.getSingletonInstance();
|
||||
|
||||
public EIncludeInvoke() {
|
||||
}
|
||||
|
||||
public EIncludeInvoke(RStack a_stack) {
|
||||
setup(a_stack);
|
||||
}
|
||||
|
||||
public void display(Graphics2D g, AffineTransform a_trans) {
|
||||
g.setColor(GlyphColor.INCLUDE);
|
||||
if (isSelected()) {
|
||||
g.setColor(GlyphColor.SELECTED);
|
||||
} // if
|
||||
|
||||
g.draw(toShape(a_trans,EContour.k_defaultPixelSize));
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return EObject.getActives().isSelected(this);
|
||||
}
|
||||
|
||||
public Shape toShape(AffineTransform a_trans, int a_ppem) {
|
||||
Shape retval;
|
||||
|
||||
ModuleManager manager = ModuleManager.getSingletonInstance();
|
||||
GlyphFile file = manager.getGlyphFile(getHref());
|
||||
|
||||
XPoint2d pos = getInvoke().getInvokePos().getPoint2d();
|
||||
|
||||
AffineTransform trans = new AffineTransform();
|
||||
trans.setTransform(a_trans);
|
||||
trans.translate(pos.getX(), pos.getY());
|
||||
|
||||
m_stack.push(this);
|
||||
retval = file.toShape(trans);
|
||||
m_stack.pop();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public GlyphModule getModule() {
|
||||
ModuleManager manager = ModuleManager.getSingletonInstance();
|
||||
return manager.getGlyphFile(getHref());
|
||||
}
|
||||
|
||||
// for var stack frame
|
||||
public boolean hasVariable(String a_name) {
|
||||
return m_augmented.containsKey(a_name);
|
||||
}
|
||||
|
||||
// for var stack frame.
|
||||
public double getValue(String a_name) {
|
||||
Double d = (Double) m_augmented.get(a_name);
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
// for var stack frame.
|
||||
public void beforePush() {
|
||||
getModule().beforePush();
|
||||
loadInvoke(getInvoke());
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
XBody parent = (XBody) rGetParentRNode();
|
||||
parent.removeInclude(this);
|
||||
}
|
||||
|
||||
public void move(Point2D a_delta) {
|
||||
XPoint2d point = getInvoke().getInvokePos().getPoint2d();
|
||||
EObject.movePoint(point, a_delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* loads invoke arguments into this module to build augmented environment.
|
||||
* @param a_invoke
|
||||
*/
|
||||
private void loadInvoke(XInvoke a_invoke) {
|
||||
copyVarsToAug();
|
||||
|
||||
int i;
|
||||
XInvokeVarg [] vargs = a_invoke.getInvokeVarg();
|
||||
for (i = 0; i < vargs.length; i++) {
|
||||
loadVarg(vargs[i]);
|
||||
} // for i
|
||||
}
|
||||
|
||||
private void loadVarg(XInvokeVarg a_varg) {
|
||||
String name = a_varg.getName();
|
||||
String src = a_varg.getSrc();
|
||||
GlyphModule module = getModule();
|
||||
|
||||
if (!module.hasVariable(name)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
double value = m_stack.get(src);
|
||||
m_augmented.put(name, new Double(value));
|
||||
}
|
||||
|
||||
private void copyVarsToAug() {
|
||||
m_augmented.clear();
|
||||
m_augmented.putAll(getModule().getVars());
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
return EObject.hit(this, a_rect, a_trans);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* $Id: EModuleInvoke.java,v 1.4 2004/11/08 06:29:51 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import org.doubletype.ossa.*;
|
||||
import org.doubletype.ossa.module.*;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class EModuleInvoke extends XModule implements VarStackFrame, GlyphObject, PointAggregate {
|
||||
public static EModuleInvoke create() {
|
||||
return createAt(new Point2D.Double(0, 254.0));
|
||||
}
|
||||
|
||||
public static EModuleInvoke createAt(Point2D a_point) {
|
||||
EModuleInvoke retval = new EModuleInvoke();
|
||||
|
||||
retval.setName(org.doubletype.ossa.module.Rectangle.class.getName());
|
||||
retval.setInvoke(EObject.createInvoke(a_point));
|
||||
|
||||
double x, y;
|
||||
XContourPoint point;
|
||||
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
|
||||
x += 426.0;
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
y -= 254.0;
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
x -= 426.0;
|
||||
point = new EContourPoint(x, y, true);
|
||||
retval.addContourPoint(point);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/** environment with invoke args. */
|
||||
private Hashtable<String,Double> m_augmented = new Hashtable<>();
|
||||
private VarStack m_stack = VarStack.getSingletonInstance();
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public EModuleInvoke() {
|
||||
}
|
||||
|
||||
public EModuleInvoke(RStack a_stack) {
|
||||
setup(a_stack);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public void display(Graphics2D g, AffineTransform a_trans) {
|
||||
if (isSelected()) {
|
||||
g.setColor(GlyphColor.SELECTED);
|
||||
} else {
|
||||
g.setColor(GlyphColor.MODULE);
|
||||
} // if
|
||||
|
||||
g.draw(toShape(a_trans, EContour.k_defaultPixelSize));
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return EObject.getActives().isSelected(this);
|
||||
}
|
||||
|
||||
public Shape toShape(AffineTransform a_trans, int a_ppem) {
|
||||
EContour contour = toContour(a_trans);
|
||||
return contour.toShape(new AffineTransform(), a_ppem);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public EContour toContour(AffineTransform a_trans) {
|
||||
EContour retval;
|
||||
|
||||
GlyphModule module = getModule();
|
||||
|
||||
m_stack.push(this);
|
||||
EContour untransContour = module.toContour(this);
|
||||
m_stack.pop();
|
||||
|
||||
XPoint2d pos = getInvoke().getInvokePos().getPoint2d();
|
||||
AffineTransform trans = (AffineTransform) a_trans.clone();
|
||||
trans.translate(pos.getX(), pos.getY());
|
||||
|
||||
retval = untransContour.transpose(trans);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public GlyphModule getModule() {
|
||||
return getModuleForName(getName());
|
||||
}
|
||||
|
||||
private GlyphModule getModuleForName(String a_name) {
|
||||
GlyphModule retval = null;
|
||||
|
||||
try {
|
||||
ModuleManager manager = ModuleManager.getSingletonInstance();
|
||||
retval = manager.getModule(a_name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
XBody parent = (XBody) rGetParentRNode();
|
||||
parent.removeModule(this);
|
||||
}
|
||||
|
||||
public void move(Point2D a_delta) {
|
||||
XPoint2d point = getInvoke().getInvokePos().getPoint2d();
|
||||
EObject.movePoint(point, a_delta);
|
||||
}
|
||||
|
||||
// PointAggregate
|
||||
public void removePoint(EContourPoint a_point) {
|
||||
boolean isFirst = (a_point == getContourPoint(0));
|
||||
removeContourPoint(a_point);
|
||||
|
||||
GlyphModule module = getModuleForName(getName());
|
||||
|
||||
if (getContourPoint().length < module.getMinimumPointCount())
|
||||
{
|
||||
remove();
|
||||
return;
|
||||
} // if
|
||||
|
||||
if (!isFirst) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
EContourPoint newFirst = (EContourPoint) getContourPoint(0);
|
||||
Point2D pos = newFirst.toPoint2D();
|
||||
Point2D delta = new Point2D.Double(-pos.getX(), -pos.getY());
|
||||
moveModulePoints(delta);
|
||||
move(pos);
|
||||
}
|
||||
|
||||
public void moveModulePoints(Point2D a_delta) {
|
||||
XContourPoint [] points = getContourPoint();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
EObject.movePoint(point, a_delta);
|
||||
} // for i
|
||||
}
|
||||
|
||||
// for var stack frame
|
||||
public boolean hasVariable(String a_name) {
|
||||
return m_augmented.containsKey(a_name);
|
||||
}
|
||||
|
||||
// for var stack frame.
|
||||
public double getValue(String a_name) {
|
||||
Double d = (Double) m_augmented.get(a_name);
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
// for var stack frame.
|
||||
public void beforePush() {
|
||||
loadInvoke(getInvoke());
|
||||
}
|
||||
|
||||
/**
|
||||
* loads invoke arguments into this module to build augmented environment.
|
||||
* @param a_invoke
|
||||
*/
|
||||
private void loadInvoke(XInvoke a_invoke) {
|
||||
copyVarsToAug();
|
||||
|
||||
// load varg
|
||||
int i;
|
||||
XInvokeVarg [] vargs = a_invoke.getInvokeVarg();
|
||||
for (i = 0; i < vargs.length; i++) {
|
||||
loadVarg(vargs[i]);
|
||||
} // for i
|
||||
}
|
||||
|
||||
private void loadVarg(XInvokeVarg a_varg) {
|
||||
String name = a_varg.getName();
|
||||
String src = a_varg.getSrc();
|
||||
GlyphModule module = getModule();
|
||||
|
||||
if (!module.hasVariable(name)) {
|
||||
System.out.println(name + " does not exist in "
|
||||
+ module.toString());
|
||||
|
||||
return;
|
||||
} // if
|
||||
|
||||
double value = m_stack.get(src);
|
||||
m_augmented.put(name, new Double(value));
|
||||
}
|
||||
|
||||
private void copyVarsToAug() {
|
||||
m_augmented.clear();
|
||||
m_augmented.putAll(getModule().getVars());
|
||||
}
|
||||
|
||||
public void movePoint(EContourPoint a_point, Point2D a_delta) {
|
||||
EObject.movePoint(a_point, a_delta);
|
||||
|
||||
if (a_point != getContourPoint(0)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
Point2D negative = new Point2D.Double(-a_delta.getX(), -a_delta.getY());
|
||||
moveModulePoints(negative);
|
||||
move(a_delta);
|
||||
}
|
||||
|
||||
public GlyphObject insertPoint(EContourPoint a_point) {
|
||||
int i;
|
||||
int len = getContourPoint().length;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (getContourPoint(i) == a_point) {
|
||||
break;
|
||||
} // if
|
||||
} // for
|
||||
|
||||
EContourPoint nextPoint;
|
||||
nextPoint = (EContourPoint) getContourPoint((i + 1) % len);
|
||||
|
||||
double x = (a_point.getX() + nextPoint.getX()) / 2;
|
||||
double y = (a_point.getY() + nextPoint.getY()) / 2;
|
||||
|
||||
EContourPoint retval = new EContourPoint(x, y, true);
|
||||
addContourPoint(i + 1, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
return EObject.hit(this, a_rect, a_trans);
|
||||
}
|
||||
}
|
||||
158
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EObject.java
Normal file
158
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EObject.java
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* $Id: EObject.java,v 1.2 2004/11/08 06:29:51 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.geom.*;
|
||||
import java.awt.*;
|
||||
|
||||
import org.doubletype.ossa.*;
|
||||
import org.doubletype.ossa.truetype.TTPixelSize;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
|
||||
/** Decorator class of xml objects.
|
||||
* @author e.e
|
||||
*/
|
||||
public abstract class EObject {
|
||||
public static final String k_on = "on";
|
||||
public static final String k_off = "off";
|
||||
|
||||
private static ActiveList s_actives = null;
|
||||
|
||||
|
||||
static ActiveList getActives() {
|
||||
if (s_actives == null) {
|
||||
s_actives = ActiveList.getSingletonInstance();
|
||||
} // if
|
||||
|
||||
return s_actives;
|
||||
}
|
||||
|
||||
static Shape toShape(XPoint2d a_point, AffineTransform a_trans) {
|
||||
|
||||
double ratio= EContour.k_defaultPixelSize/TTPixelSize.getEm();
|
||||
|
||||
double x = a_point.getX();
|
||||
double y = a_point.getY();
|
||||
double e = 3 / ratio;
|
||||
Point2D source, dest;
|
||||
source = new Point2D.Double(x, y);
|
||||
dest = new Point2D.Double();
|
||||
dest = a_trans.transform(source, dest);
|
||||
x = dest.getX();
|
||||
y = dest.getY();
|
||||
|
||||
return new Rectangle2D.Double(x - e, y - e, 2 * e + 1, 2 * e + 1);
|
||||
}
|
||||
|
||||
static void movePoint(XPoint2d a_point, Point2D a_delta) {
|
||||
double x = a_point.getX() + a_delta.getX();
|
||||
double y = a_point.getY() + a_delta.getY();
|
||||
|
||||
a_point.setX(x);
|
||||
a_point.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* move the point and hint
|
||||
* @param a_point
|
||||
* @param a_delta
|
||||
*/
|
||||
public static void movePoint(EContourPoint a_point, Point2D a_delta) {
|
||||
movePoint(a_point.getPoint2d(), a_delta);
|
||||
|
||||
XHint [] hints = a_point.getHint();
|
||||
for (int i = 0; i < hints.length; i++) {
|
||||
XHint hint = hints[i];
|
||||
movePoint(hint.getPoint2d(), a_delta);
|
||||
} // for i
|
||||
|
||||
if (a_point.hasControlPoint1()) {
|
||||
EContourPoint point = (EContourPoint) a_point.getControlPoint1().getContourPoint();
|
||||
movePoint(point, a_delta);
|
||||
} // if
|
||||
if (a_point.hasControlPoint2()) {
|
||||
EContourPoint point = (EContourPoint) a_point.getControlPoint2().getContourPoint();
|
||||
movePoint(point, a_delta);
|
||||
} // if
|
||||
}
|
||||
|
||||
public static boolean hit(GlyphObject a_object, Rectangle2D a_rect, AffineTransform a_trans) {
|
||||
int ppem = EContour.k_defaultPixelSize;
|
||||
Shape hitArea = a_object.toShape(a_trans, ppem);
|
||||
if (!hitArea.intersects(a_rect)) {
|
||||
return false;
|
||||
} // if
|
||||
|
||||
EObject.getActives().addActive(a_object);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static XInvoke createInvoke(Point2D a_point) {
|
||||
XInvoke retval = new XInvoke();
|
||||
retval.setInvokePos(createInvokePos(a_point.getX(), a_point.getY()));
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static XPoint2d createTransform(XPoint2d a_point, AffineTransform a_trans) {
|
||||
XPoint2d retval = new XPoint2d();
|
||||
|
||||
double x = a_point.getX();
|
||||
double y = a_point.getY();
|
||||
Point2D source = new Point2D.Double(x, y);
|
||||
Point2D dest = new Point2D.Double();
|
||||
a_trans.transform(source, dest);
|
||||
|
||||
retval.setX(dest.getX());
|
||||
retval.setY(dest.getY());
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private static XInvokePos createInvokePos(double a_x, double a_y) {
|
||||
XInvokePos retval = new XInvokePos();
|
||||
retval.setPoint2d(createPoint2d(a_x, a_y));
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
private static XPoint2d createPoint2d(double a_x, double a_y) {
|
||||
XPoint2d retval = new XPoint2d();
|
||||
retval.setX(a_x);
|
||||
retval.setY(a_y);
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
||||
44
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EPoint.java
Normal file
44
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/EPoint.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* $Id: EPoint.java,v 1.1 2004/12/27 04:56:02 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public interface EPoint {
|
||||
double getX();
|
||||
double getY();
|
||||
}
|
||||
360
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/Emulator.java
Normal file
360
trunk/libsrc/ttf/src/org/doubletype/ossa/adapter/Emulator.java
Normal file
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* $Id: Emulator.java,v 1.6 2004/12/27 04:56:02 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
import java.util.*;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
|
||||
/** Emulator emulates font engine.
|
||||
* @author e.e
|
||||
*/
|
||||
public class Emulator {
|
||||
private static Emulator s_instance = null;
|
||||
|
||||
// singleton pattern
|
||||
public static Emulator getInstance() {
|
||||
if (s_instance == null) {
|
||||
s_instance = new Emulator();
|
||||
} // if
|
||||
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
private Emulator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Shape createShape(EContour a_contour, int a_ppem) {
|
||||
if (a_contour.isCubic()) {
|
||||
// return createBezierCurve(a_contour);
|
||||
EContour contour = a_contour.toQuadratic();
|
||||
return createShape(contour, a_ppem);
|
||||
} // if
|
||||
|
||||
return concretePointsToShape(createConcretePoints(
|
||||
createAdjustedPoints(a_contour, a_ppem)));
|
||||
}
|
||||
|
||||
private Shape createBezierCurve(EContour a_contour) {
|
||||
GeneralPath retval = new GeneralPath();
|
||||
XContourPoint [] points = a_contour.getContourPoint();
|
||||
|
||||
if (points.length < 2) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
EContourPoint startPoint = (EContourPoint) points[points.length - 1];
|
||||
retval.moveTo((float) startPoint.getX(), (float) startPoint.getY());
|
||||
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
EContourPoint toPoint = (EContourPoint) points[i];
|
||||
EControlPoint controlPoint1 = (EControlPoint) startPoint.getControlPoint2();
|
||||
EControlPoint controlPoint2 = (EControlPoint) toPoint.getControlPoint1();
|
||||
|
||||
// line segment
|
||||
if ((controlPoint1 == null) && (controlPoint2 == null)) {
|
||||
retval.lineTo((float) toPoint.getX(), (float) toPoint.getY());
|
||||
|
||||
} // if
|
||||
|
||||
if ((controlPoint1 != null) && (controlPoint2 == null)) {
|
||||
retval.curveTo((float) controlPoint1.getX(), (float) controlPoint1.getY(),
|
||||
(float) toPoint.getX(), (float) toPoint.getY(),
|
||||
(float) toPoint.getX(), (float) toPoint.getY());
|
||||
} // if
|
||||
|
||||
if ((controlPoint1 == null) && (controlPoint2 != null)) {
|
||||
retval.curveTo((float) startPoint.getX(), (float) startPoint.getY(),
|
||||
(float) controlPoint2.getX(), (float) controlPoint2.getY(),
|
||||
(float) toPoint.getX(), (float) toPoint.getY());
|
||||
} // if
|
||||
|
||||
if ((controlPoint1 != null) && (controlPoint2 != null)) {
|
||||
retval.curveTo((float) controlPoint1.getX(), (float) controlPoint1.getY(),
|
||||
(float) controlPoint2.getX(), (float) controlPoint2.getY(),
|
||||
(float) toPoint.getX(), (float) toPoint.getY());
|
||||
} // if
|
||||
|
||||
startPoint = toPoint;
|
||||
} // for
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private Shape concretePointsToShape(java.util.List a_listOfPoints) {
|
||||
GeneralPath retval = new GeneralPath();
|
||||
EContourPoint p;
|
||||
|
||||
if (a_listOfPoints.size() < 3)
|
||||
return retval;
|
||||
|
||||
p = (EContourPoint) a_listOfPoints.get(0);
|
||||
retval.moveTo((float) p.getX(), (float) p.getY());
|
||||
|
||||
int i = 0;
|
||||
while (i < a_listOfPoints.size() - 1) {
|
||||
i++;
|
||||
EContourPoint nextPoint = (EContourPoint) a_listOfPoints.get(i);
|
||||
|
||||
if (nextPoint.isOn()) {
|
||||
retval.lineTo((float) nextPoint.getX(), (float) nextPoint.getY());
|
||||
} else {
|
||||
EContourPoint controlPoint = nextPoint;
|
||||
i++;
|
||||
EContourPoint toPoint = (EContourPoint) a_listOfPoints.get(i);
|
||||
|
||||
retval.quadTo((float) controlPoint.getX(),
|
||||
(float) controlPoint.getY(),
|
||||
(float) toPoint.getX(), (float) toPoint.getY());
|
||||
} // if-else
|
||||
} // for
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private java.util.List<EContourPoint> createConcretePoints(java.util.List a_points) {
|
||||
java.util.List<EContourPoint> retval = new ArrayList<>();
|
||||
|
||||
if (a_points.size() < 3)
|
||||
return retval;
|
||||
|
||||
EContourPoint lastPoint = (EContourPoint) a_points.get(a_points.size() - 1);
|
||||
for (int i = 0; i < a_points.size(); i++) {
|
||||
EContourPoint point = (EContourPoint) a_points.get(i);
|
||||
|
||||
if (!point.isOn() && !lastPoint.isOn()) {
|
||||
double xMidpoint = (point.getX() + lastPoint.getX()) / 2;
|
||||
double yMidpoint = (point.getY() + lastPoint.getY()) / 2;
|
||||
retval.add(new EContourPoint(xMidpoint, yMidpoint, true));
|
||||
} // if
|
||||
|
||||
retval.add(new EContourPoint(point.getX(), point.getY(), point.isOn()));
|
||||
lastPoint = point;
|
||||
} // for i
|
||||
|
||||
// all contours should start with on-curve point
|
||||
// move off-curve point to the end if a contour starts with one.
|
||||
EContourPoint point = (EContourPoint) retval.get(0);
|
||||
if (!point.isOn()) {
|
||||
retval.remove(0);
|
||||
retval.add(point);
|
||||
} // if
|
||||
|
||||
point = (EContourPoint) retval.get(0);
|
||||
retval.add(point);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private java.util.List<EContourPoint> createAdjustedPoints(EContour a_contour, int a_ppem) {
|
||||
java.util.List<EContourPoint> retval = new ArrayList<>();
|
||||
|
||||
XContourPoint [] points = a_contour.getContourPoint();
|
||||
if (points.length < 3) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
boolean isRounded = false;
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
point.resetAdjusted();
|
||||
|
||||
if (point.isRounded()) {
|
||||
isRounded = true;
|
||||
point.roundAdjusted(a_ppem);
|
||||
} // if
|
||||
|
||||
retval.add(point);
|
||||
} // for i
|
||||
|
||||
if (isRounded) {
|
||||
interpolate(retval, true);
|
||||
interpolate(retval, false);
|
||||
} // if
|
||||
|
||||
for (int i = 0; i < retval.size(); i++) {
|
||||
EContourPoint point = (EContourPoint) retval.get(i);
|
||||
if (point.hasHintForPpem(a_ppem)) {
|
||||
point.hintAdjusted(a_ppem);
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return promoteAdjustedToMain(retval);
|
||||
}
|
||||
|
||||
private java.util.List<EContourPoint> promoteAdjustedToMain(java.util.List<EContourPoint> a_points) {
|
||||
java.util.List<EContourPoint> retval = new ArrayList<>();
|
||||
for (int i = 0; i < a_points.size(); i++) {
|
||||
EContourPoint original = (EContourPoint) a_points.get(i);
|
||||
EContourPoint adjusted = new EContourPoint(original.getAdjusted().getX(),
|
||||
original.getAdjusted().getY(),
|
||||
original.isOn());
|
||||
|
||||
retval.add(adjusted);
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private void interpolate(java.util.List<EContourPoint> a_points, boolean a_isX) {
|
||||
Collection<EContourPoint> sorted = sortPoints(a_points, a_isX);
|
||||
|
||||
Iterator itr = sorted.iterator();
|
||||
|
||||
EContourPoint first = (EContourPoint) itr.next();
|
||||
if (!first.isRounded()) {
|
||||
shiftPoint(first, a_points, a_isX);
|
||||
} // if
|
||||
|
||||
EContourPoint second = (EContourPoint) itr.next();
|
||||
EContourPoint third = null;
|
||||
while (itr.hasNext()) {
|
||||
third = (EContourPoint) itr.next();
|
||||
|
||||
if (!second.isRounded()) {
|
||||
if (first.isRounded()
|
||||
&& third.isRounded()) {
|
||||
interpolate(first, second, third, a_isX);
|
||||
} else {
|
||||
shiftPoint(second, a_points, a_isX);
|
||||
} // if-else
|
||||
} // if
|
||||
|
||||
first = second;
|
||||
second = third;
|
||||
} // while
|
||||
|
||||
EContourPoint last = third;
|
||||
if (!last.isRounded()) {
|
||||
shiftPoint(last, a_points, a_isX);
|
||||
} // if
|
||||
}
|
||||
|
||||
private Collection<EContourPoint> sortPoints(java.util.List<EContourPoint> a_points, boolean a_isX) {
|
||||
Map<Double,EContourPoint> sorted = new TreeMap<>();
|
||||
|
||||
for (int i = 0; i < a_points.size(); i++) {
|
||||
EContourPoint original = (EContourPoint) a_points.get(i);
|
||||
Double value = new Double(getPointValue(original, a_isX));
|
||||
|
||||
while (sorted.containsKey(value)) {
|
||||
value = new Double(value.doubleValue() + 0.01);
|
||||
} // while
|
||||
sorted.put(value, original);
|
||||
} // for i
|
||||
|
||||
return sorted.values();
|
||||
}
|
||||
|
||||
private void interpolate(EContourPoint a_first, EContourPoint a_second, EContourPoint a_third, boolean a_isX) {
|
||||
double firstValue = getPointValue(a_first, a_isX);
|
||||
double secondValue = getPointValue(a_second, a_isX);
|
||||
double thirdValue = getPointValue(a_third, a_isX);
|
||||
double adjustedFirst = getAdjustedValue(a_first, a_isX);
|
||||
double adjustedThird = getAdjustedValue(a_third, a_isX);
|
||||
|
||||
double ratio = (secondValue - firstValue) / (thirdValue - firstValue);
|
||||
|
||||
secondValue = adjustedFirst + ratio * (adjustedThird - adjustedFirst);
|
||||
setAdjusted(a_second, secondValue, a_isX);
|
||||
}
|
||||
|
||||
private void shiftPoint(EContourPoint a_point, java.util.List<EContourPoint> a_points, boolean a_isX) {
|
||||
EContourPoint closest = closestTouchedPoint(a_point, a_points);
|
||||
if (closest == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
double delta = getAdjustedValue(closest, a_isX) - getPointValue(closest, a_isX);
|
||||
double value = getPointValue(a_point, a_isX) + delta;
|
||||
setAdjusted(a_point, value, a_isX);
|
||||
}
|
||||
|
||||
private void setAdjusted(EContourPoint a_point, double a_value, boolean a_isX) {
|
||||
double x = a_point.getX();
|
||||
double y = a_point.getY();
|
||||
|
||||
if (a_isX) {
|
||||
x = a_value;
|
||||
} else {
|
||||
y = a_value;
|
||||
} // if-else
|
||||
|
||||
a_point.setAdjusted(x, y);
|
||||
}
|
||||
|
||||
private double getPointValue(EContourPoint a_point, boolean a_isX) {
|
||||
if (a_isX) {
|
||||
return a_point.getX();
|
||||
} else {
|
||||
return a_point.getY();
|
||||
} // if-else
|
||||
}
|
||||
|
||||
private double getAdjustedValue(EContourPoint a_point, boolean a_isX) {
|
||||
if (a_isX) {
|
||||
return a_point.getAdjusted().getX();
|
||||
} else {
|
||||
return a_point.getAdjusted().getY();
|
||||
} // if-else
|
||||
}
|
||||
|
||||
private EContourPoint closestTouchedPoint(EContourPoint a_point, java.util.List<EContourPoint> a_points) {
|
||||
EContourPoint retval = null;
|
||||
double min = Double.MAX_VALUE;
|
||||
for (int i = 0; i < a_points.size(); i++) {
|
||||
EContourPoint target = (EContourPoint) a_points.get(i);
|
||||
if (target == a_point) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
if (!target.isRounded()) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
double d = a_point.toPoint2D().distance(target.toPoint2D());
|
||||
if (d < min) {
|
||||
min = d;
|
||||
retval = target;
|
||||
} // if
|
||||
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* $Id: GlyphObject.java,v 1.1 2004/09/04 21:54:06 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public interface GlyphObject {
|
||||
void move(Point2D a_delta);
|
||||
void remove();
|
||||
Shape toShape(AffineTransform a_trans, int a_ppem);
|
||||
boolean isSelected();
|
||||
void display(Graphics2D g, AffineTransform a_trans);
|
||||
boolean hit(Rectangle2D a_rect, AffineTransform a_trans);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* $Id: PointAggregate.java,v 1.2 2004/09/18 07:30:44 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.awt.geom.*;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public interface PointAggregate {
|
||||
void removePoint(EContourPoint a_point);
|
||||
void movePoint(EContourPoint a_point, Point2D a_delta);
|
||||
GlyphObject insertPoint(EContourPoint a_point);
|
||||
XContourPoint[] getContourPoint();
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* $Id: QuadraticSegment.java,v 1.1 2004/12/15 11:54:18 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.adapter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.doubletype.ossa.xml.XContourPoint;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class QuadraticSegment {
|
||||
public static final int LINE = 0;
|
||||
public static final int CURVE = 1;
|
||||
|
||||
/**
|
||||
* converts quadratic contour into a list of quadratic segments.
|
||||
* @param a_contour
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<QuadraticSegment> toSegments(EContour a_contour) {
|
||||
ArrayList<QuadraticSegment> retval = new ArrayList<>();
|
||||
|
||||
ArrayList points = toConcreatePoints(a_contour);
|
||||
if (points.size() < 3) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
EContourPoint startPoint = (EContourPoint) points.get(i);
|
||||
EContourPoint nextPoint = (EContourPoint) points.get(i + 1);
|
||||
|
||||
// if this is a line segment
|
||||
if (nextPoint.isOn()) {
|
||||
retval.add(new QuadraticSegment(startPoint, null, nextPoint));
|
||||
} else {
|
||||
EContourPoint offCurvePoint = nextPoint;
|
||||
i++;
|
||||
nextPoint = (EContourPoint) points.get(i + 1);
|
||||
retval.add(new QuadraticSegment(startPoint, offCurvePoint, nextPoint));
|
||||
} // if-else
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts a list of quadratic segments into a quadratic contour.
|
||||
* @param a_segments
|
||||
* @return
|
||||
*/
|
||||
public static EContour toContour(ArrayList<QuadraticSegment> a_segments) {
|
||||
EContour retval = new EContour();
|
||||
retval.setType(EContour.k_quadratic);
|
||||
|
||||
for (QuadraticSegment segment: a_segments) {
|
||||
EContourPoint startPoint = (EContourPoint) segment.m_startPoint.clone();
|
||||
startPoint.setControlPoint1(null);
|
||||
startPoint.setControlPoint2(null);
|
||||
|
||||
if (segment.m_type == LINE) {
|
||||
retval.addContourPoint(startPoint);
|
||||
|
||||
} else {
|
||||
retval.addContourPoint(startPoint);
|
||||
retval.addContourPoint(segment.m_offCurvePoint);
|
||||
}
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts quadratic contour to concreate points by inserting
|
||||
* on-curve point between off-curve points.
|
||||
* @param a_contour
|
||||
* @return
|
||||
*/
|
||||
private static ArrayList<EContourPoint> toConcreatePoints(EContour a_contour) {
|
||||
ArrayList<EContourPoint> retval = new ArrayList<>();
|
||||
|
||||
XContourPoint [] points = a_contour.getContourPoint();
|
||||
if (points.length < 3)
|
||||
return retval;
|
||||
|
||||
EContourPoint fromPoint = (EContourPoint) points[points.length - 1];
|
||||
for (XContourPoint point: points) {
|
||||
EContourPoint toPoint = (EContourPoint) point;
|
||||
if (!toPoint.isOn() && !fromPoint.isOn()) {
|
||||
double xMidpoint = (toPoint.getX() + fromPoint.getX()) / 2;
|
||||
double yMidpoint = (toPoint.getY() + fromPoint.getY()) / 2;
|
||||
retval.add(new EContourPoint(xMidpoint, yMidpoint, true));
|
||||
} // if
|
||||
|
||||
retval.add(toPoint);
|
||||
fromPoint = toPoint;
|
||||
} // for i
|
||||
|
||||
// all contours should start with on-curve point
|
||||
// move off-curve point to the end if a contour starts with one.
|
||||
EContourPoint firstPoint = (EContourPoint) retval.get(0);
|
||||
if (!firstPoint.isOn()) {
|
||||
retval.remove(0);
|
||||
retval.add(firstPoint);
|
||||
} // if
|
||||
|
||||
retval.add(retval.get(0));
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private EContourPoint m_startPoint;
|
||||
private EContourPoint m_offCurvePoint;
|
||||
private EContourPoint m_endPoint;
|
||||
|
||||
private int m_type = LINE;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public QuadraticSegment(EContourPoint a_startPoint, EContourPoint a_offCurvePoint,
|
||||
EContourPoint a_endPoint) {
|
||||
m_startPoint = a_startPoint;
|
||||
m_offCurvePoint = a_offCurvePoint;
|
||||
m_endPoint = a_endPoint;
|
||||
|
||||
if (m_offCurvePoint != null) {
|
||||
m_type = CURVE;
|
||||
} // if
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert quadratic segment to cubic.
|
||||
* @param a_segment
|
||||
* @return
|
||||
*/
|
||||
public CubicSegment toCubicSegment() {
|
||||
// if the segment is a line
|
||||
if (m_type == LINE) {
|
||||
return new CubicSegment(m_startPoint, m_endPoint);
|
||||
} // if
|
||||
|
||||
double x, y;
|
||||
x = m_startPoint.getX() + 2.0 / 3.0 * (m_offCurvePoint.getX() - m_startPoint.getX());
|
||||
y = m_startPoint.getY() + 2.0 / 3.0 * (m_offCurvePoint.getY() - m_startPoint.getY());
|
||||
EContourPoint controlPoint1 = new EContourPoint(x, y, false);
|
||||
|
||||
x = m_offCurvePoint.getX() + 1.0 / 3.0 * (m_endPoint.getX() - m_offCurvePoint.getX());
|
||||
y = m_offCurvePoint.getY() + 1.0 / 3.0 * (m_endPoint.getY() - m_offCurvePoint.getY());
|
||||
EContourPoint controlPoint2 = new EContourPoint(x, y, false);
|
||||
|
||||
return new CubicSegment(m_startPoint, controlPoint1, controlPoint2, m_endPoint);
|
||||
}
|
||||
|
||||
}
|
||||
1141
trunk/libsrc/ttf/src/org/doubletype/ossa/module/GlyphFile.java
Normal file
1141
trunk/libsrc/ttf/src/org/doubletype/ossa/module/GlyphFile.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* $Id: GlyphIterator.java,v 1.11 2004/12/27 04:56:03 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.module;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
|
||||
/** Iterates through contours, module invokes, then include invokes.
|
||||
* Used in GlyphFile display
|
||||
* @author e.e
|
||||
*/
|
||||
public class GlyphIterator implements Iterator {
|
||||
protected GlyphFile m_file;
|
||||
private int m_index = 0;
|
||||
protected java.util.List<IRNode> m_list = new ArrayList<>();
|
||||
|
||||
public GlyphIterator(GlyphFile a_file) {
|
||||
m_file = a_file;
|
||||
buildList();
|
||||
}
|
||||
|
||||
protected void buildList() {
|
||||
addIncludes();
|
||||
addContours();
|
||||
addModules();
|
||||
|
||||
}
|
||||
|
||||
protected void addContours() {
|
||||
XContour [] contours = m_file.getGlyph().getBody().getContour();
|
||||
for (int i = 0; i < contours.length; i++) {
|
||||
m_list.add(contours[i]);
|
||||
} // for i
|
||||
}
|
||||
|
||||
protected void addControlPoints() {
|
||||
XContour [] contours = m_file.getGlyph().getBody().getContour();
|
||||
for (int i = 0; i < contours.length; i++) {
|
||||
EContour contour = (EContour) contours[i];
|
||||
if (!contour.isCubic()) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
addControlPoints(contour, 0, 0);
|
||||
} // for i
|
||||
}
|
||||
|
||||
private void addControlPoints(PointAggregate a_object, double a_x, double a_y) {
|
||||
XContourPoint [] points = a_object.getContourPoint();
|
||||
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
|
||||
if (!isPointVisible(point)) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
if (point.hasControlPoint1()) {
|
||||
EControlPoint controlPoint = (EControlPoint) point.getControlPoint1();
|
||||
controlPoint.setOffset(a_x, a_y);
|
||||
m_list.add(controlPoint);
|
||||
} // if
|
||||
|
||||
if (point.hasControlPoint2()) {
|
||||
EControlPoint controlPoint = (EControlPoint) point.getControlPoint2();
|
||||
controlPoint.setOffset(a_x, a_y);
|
||||
m_list.add(controlPoint);
|
||||
} // if
|
||||
} // for j
|
||||
}
|
||||
|
||||
protected void addHints() {
|
||||
XContour [] contours = m_file.getGlyph().getBody().getContour();
|
||||
for (int i = 0; i < contours.length; i++) {
|
||||
addHints((EContour) contours[i], 0, 0);
|
||||
} // for i
|
||||
|
||||
XModule [] modules = m_file.getGlyph().getBody().getModule();
|
||||
for (int i = 0; i < modules.length; i++) {
|
||||
EModuleInvoke module = (EModuleInvoke) modules[i];
|
||||
double x = module.getInvoke().getInvokePos().getPoint2d().getX();
|
||||
double y = module.getInvoke().getInvokePos().getPoint2d().getY();
|
||||
|
||||
addHints(module, x, y);
|
||||
} // for i
|
||||
}
|
||||
|
||||
private void addHints(PointAggregate a_object, double a_x, double a_y) {
|
||||
XContourPoint [] points = a_object.getContourPoint();
|
||||
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
|
||||
if (!isPointVisible(point)) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
if (point.hasHintForCurrentPpem()) {
|
||||
EHint hint = point.getCurrentHint();
|
||||
hint.setOffset(a_x, a_y);
|
||||
m_list.add(hint);
|
||||
} // if
|
||||
|
||||
if (point.hasControlPoint1()) {
|
||||
EContourPoint p = (EContourPoint) point.getControlPoint1().getContourPoint();
|
||||
if (p.hasHintForCurrentPpem()) {
|
||||
EHint hint = p.getCurrentHint();
|
||||
hint.setOffset(a_x, a_y);
|
||||
m_list.add(hint);
|
||||
} // if
|
||||
}
|
||||
|
||||
if (point.hasControlPoint2()) {
|
||||
EContourPoint p = (EContourPoint) point.getControlPoint2().getContourPoint();
|
||||
if (p.hasHintForCurrentPpem()) {
|
||||
EHint hint = p.getCurrentHint();
|
||||
hint.setOffset(a_x, a_y);
|
||||
m_list.add(hint);
|
||||
} // if
|
||||
} // if
|
||||
} // for j
|
||||
}
|
||||
|
||||
private boolean isPointVisible(EContourPoint a_point) {
|
||||
if (m_file.getPointHost() == null) {
|
||||
return true;
|
||||
} // if
|
||||
|
||||
if (m_file.getPointHost() == a_point.getParent()) {
|
||||
return true;
|
||||
} // if
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void addPoints() {
|
||||
XContour [] contours = m_file.getGlyph().getBody().getContour();
|
||||
for (int i = 0; i < contours.length; i++) {
|
||||
addPoints((EContour) contours[i], 0, 0);
|
||||
} // for i
|
||||
|
||||
XModule [] modules = m_file.getGlyph().getBody().getModule();
|
||||
for (int i = 0; i < modules.length; i++) {
|
||||
EModuleInvoke module = (EModuleInvoke) modules[i];
|
||||
double x = module.getInvoke().getInvokePos().getPoint2d().getX();
|
||||
double y = module.getInvoke().getInvokePos().getPoint2d().getY();
|
||||
|
||||
addPoints(module, x, y);
|
||||
} // for i
|
||||
}
|
||||
|
||||
private void addPoints(PointAggregate a_object, double a_x, double a_y) {
|
||||
XContourPoint [] points = a_object.getContourPoint();
|
||||
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
|
||||
if (!isPointVisible(point)) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
point.setNumber(i);
|
||||
point.setOffset(a_x, a_y);
|
||||
m_list.add(point);
|
||||
} // for j
|
||||
}
|
||||
|
||||
protected void addModules() {
|
||||
XModule [] modules = m_file.getGlyph().getBody().getModule();
|
||||
for (int i = 0; i < modules.length; i++) {
|
||||
m_list.add(modules[i]);
|
||||
} // for i
|
||||
}
|
||||
|
||||
protected void addIncludes() {
|
||||
XInclude [] includes = m_file.getGlyph().getBody().getInclude();
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
m_list.add(includes[i]);
|
||||
} // for i;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return m_index < m_list.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public Object next() {
|
||||
return m_list.get(m_index++);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* $Id: GlyphModule.java,v 1.12 2004/09/04 21:54:19 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.module;
|
||||
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
import org.doubletype.ossa.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class GlyphModule implements VarStackFrame {
|
||||
protected VarStack m_stack = VarStack.getSingletonInstance();
|
||||
private Hashtable<String,Double> m_vars = new Hashtable<>();
|
||||
protected ActiveList m_actives = ActiveList.getSingletonInstance();
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public GlyphModule() {
|
||||
}
|
||||
|
||||
public Hashtable<String,Double> getVars() {
|
||||
return m_vars;
|
||||
}
|
||||
|
||||
// for var stack frame
|
||||
public boolean hasVariable(String a_name) {
|
||||
return m_vars.containsKey(a_name);
|
||||
}
|
||||
|
||||
// for var stack frame.
|
||||
public double getValue(String a_name) {
|
||||
Double d = (Double) m_vars.get(a_name);
|
||||
return d.doubleValue();
|
||||
}
|
||||
|
||||
// for var stack frame.
|
||||
public void beforePush() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Base for generating contours from modules.
|
||||
* @param a_moduleInvoke
|
||||
* @return XContour object which represents the module.
|
||||
*/
|
||||
public EContour toContour(EModuleInvoke a_moduleInvoke) {
|
||||
throw new RuntimeException("Unimplemented contour creation.");
|
||||
}
|
||||
|
||||
public void addVar(String a_name, double a_value) {
|
||||
m_vars.put(a_name, new Double(a_value));
|
||||
}
|
||||
|
||||
public int getMinimumPointCount() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
192
trunk/libsrc/ttf/src/org/doubletype/ossa/module/Rectangle.java
Normal file
192
trunk/libsrc/ttf/src/org/doubletype/ossa/module/Rectangle.java
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* $Id: Rectangle.java,v 1.16 2004/09/04 21:54:19 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.module;
|
||||
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
|
||||
import java.awt.geom.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*
|
||||
*/
|
||||
public class Rectangle extends GlyphModule {
|
||||
public static final double k_defaultPen = 68.0;
|
||||
public static final double k_defaultWeight = 1.0;
|
||||
public static final String k_weight = "weight";
|
||||
|
||||
public Rectangle() {
|
||||
super();
|
||||
|
||||
addVar(k_weight, k_defaultWeight);
|
||||
}
|
||||
|
||||
public EContour toContour(EModuleInvoke a_moduleInvoke) {
|
||||
int i;
|
||||
EContour retval = new EContour();
|
||||
XContourPoint[] points = a_moduleInvoke.getContourPoint();
|
||||
|
||||
// can't make rectangle with one or zero point
|
||||
if (points.length < 2) {
|
||||
retval.addContourPoint(new EContourPoint(0, 0, true));
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
double pen = m_stack.get(k_weight) * k_defaultPen;
|
||||
boolean steeps[] = new boolean[points.length - 1];
|
||||
double thetas[] = new double[points.length - 1];
|
||||
Point2D outStartPoints[] = new Point2D[points.length - 1];
|
||||
Point2D inStartPoints[] = new Point2D[points.length - 1];
|
||||
Point2D outPoints [] = new Point2D[points.length];
|
||||
Point2D inPoints[] = new Point2D[points.length];
|
||||
|
||||
// treat each segment as a vector (start point and theta)
|
||||
for (i = 0; i < points.length - 1; i++) {
|
||||
EContourPoint start = (EContourPoint) points[i];
|
||||
EContourPoint end = (EContourPoint) points[i + 1];
|
||||
|
||||
// calculate theta of the vector
|
||||
double theta;
|
||||
if (start.toPoint2D().distance(end.toPoint2D()) > 0) {
|
||||
theta = Math.atan2(end.getY() - start.getY(),
|
||||
end.getX() - start.getX());
|
||||
} else {
|
||||
theta = 0.0;
|
||||
} // if
|
||||
|
||||
thetas[i] = theta;
|
||||
outStartPoints[i] = start.toPoint2D();
|
||||
|
||||
// turn the vector 90 degrees clockwise to create the
|
||||
// starting point of the parallel vector (in-vector)
|
||||
inStartPoints[i] = new Point2D.Double(start.getX() + (pen * Math.cos(theta - Math.PI / 2)),
|
||||
start.getY() + (pen * Math.sin(theta - Math.PI / 2)) );
|
||||
} // for i
|
||||
|
||||
for (i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
|
||||
if (i == 0) {
|
||||
// dynamically generate the point using vertical line thru p0 and the ideal line.
|
||||
double cuttingTheta;
|
||||
if (isSteep(thetas[i])) {
|
||||
cuttingTheta = 0.0;
|
||||
} else {
|
||||
cuttingTheta = Math.PI / 2;
|
||||
} // if-else
|
||||
|
||||
outPoints[i] = getIntersection(point.toPoint2D(), cuttingTheta,
|
||||
outStartPoints[i], thetas[i]);
|
||||
inPoints[i] = getIntersection(point.toPoint2D(), cuttingTheta,
|
||||
inStartPoints[i], thetas[i]);
|
||||
continue;
|
||||
} else if (i == points.length - 1) {
|
||||
// vertial and ideal.
|
||||
double cuttingTheta;
|
||||
if (isSteep(thetas[i - 1])) {
|
||||
cuttingTheta = 0.0;
|
||||
} else {
|
||||
cuttingTheta = Math.PI / 2;
|
||||
} // if
|
||||
|
||||
outPoints[i] = getIntersection(point.toPoint2D(), cuttingTheta,
|
||||
outStartPoints[i - 1], thetas[i - 1]);
|
||||
inPoints[i] = getIntersection(point.toPoint2D(), cuttingTheta,
|
||||
inStartPoints[i - 1], thetas[i - 1]);
|
||||
|
||||
continue;
|
||||
} // if
|
||||
|
||||
if (thetas[i - 1] != thetas[i]) {
|
||||
outPoints[i] = getIntersection(outStartPoints[i - 1], thetas[i - 1],
|
||||
outStartPoints[i], thetas[i]);
|
||||
inPoints[i] = getIntersection(inStartPoints[i - 1], thetas[i - 1],
|
||||
inStartPoints[i], thetas[i]);
|
||||
} else {
|
||||
outPoints[i] = outStartPoints[i];
|
||||
inPoints[i] = inStartPoints[i];
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
for (i = 0; i < points.length; i++) {
|
||||
EContourPoint point = (EContourPoint) points[i];
|
||||
|
||||
retval.addContourPoint(i, point.cloneAt(outPoints[i]));
|
||||
retval.addContourPoint(i + 1, point.cloneAt(inPoints[i]));
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private boolean isSteep(double a_theta) {
|
||||
return (a_theta > (Math.PI / 4) && a_theta < (3 * Math.PI / 4))
|
||||
|| (a_theta < (-Math.PI / 4) && a_theta > (-3 * Math.PI / 4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersection of two lines line0 and line1, defined by a point and slope.
|
||||
* @param a_p0 a point line0 goes thru.
|
||||
* @param a_theta0 the slope of line0, given in radian.
|
||||
* @param a_p1 a point line1 goes thru.
|
||||
* @param a_theta1 the slope of line1, given in radian.
|
||||
* @return the intersection of line0 and line1, if any; a_p1, otherwise.
|
||||
*/
|
||||
private Point2D getIntersection(Point2D a_p0, double a_theta0,
|
||||
Point2D a_p1, double a_theta1) {
|
||||
Point2D retval = new Point2D.Double();
|
||||
retval.setLocation(a_p1);
|
||||
|
||||
if (a_theta0 == a_theta1)
|
||||
return retval;
|
||||
|
||||
double cos0 = Math.cos(a_theta0);
|
||||
double sin0 = Math.sin(a_theta0);
|
||||
double cos1 = Math.cos(a_theta1);
|
||||
double sin1 = Math.sin(a_theta1);
|
||||
double deltaX = a_p1.getX() - a_p0.getX();
|
||||
double deltaY = a_p1.getY() - a_p0.getY();
|
||||
|
||||
double r1 = (cos0 * deltaY - sin0 * deltaX)
|
||||
/ (sin0 * cos1 - cos0 * sin1);
|
||||
double x = a_p1.getX() + cos1 * r1;
|
||||
double y = a_p1.getY() + sin1 * r1;
|
||||
|
||||
retval.setLocation(x, y);
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* $Id: SelectionIterator.java,v 1.2 2004/11/08 06:29:52 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.module;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
import org.doubletype.ossa.xml.IRNode;
|
||||
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class SelectionIterator extends GlyphIterator implements Iterator {
|
||||
|
||||
/**
|
||||
* @param a_file
|
||||
*/
|
||||
public SelectionIterator(GlyphFile a_file) {
|
||||
super(a_file);
|
||||
}
|
||||
|
||||
protected void buildList() {
|
||||
super.buildList();
|
||||
|
||||
List<IRNode> reverseList = new ArrayList<>();
|
||||
for (int i = m_list.size() - 1; i >= 0; i--) {
|
||||
IRNode object = m_list.get(i);
|
||||
|
||||
|
||||
reverseList.add(object);
|
||||
} // for i
|
||||
|
||||
m_list = reverseList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,677 @@
|
||||
/*
|
||||
* $Copyright: copyright (c) 2003-2008, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.module;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.doubletype.ossa.*;
|
||||
import org.doubletype.ossa.xml.*;
|
||||
import org.doubletype.ossa.adapter.*;
|
||||
import org.doubletype.ossa.truetype.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class TypefaceFile extends GlyphFile {
|
||||
private final double k_defaultTopSideBearing = 170; // 2 px
|
||||
private final double k_defaultAscender = 683; // 8 px
|
||||
private final double k_defaultXHeight = 424; // 5 px
|
||||
private final double k_defaultDescender = 171; // 2 px
|
||||
private final double k_defaultBottomSideBearing = 0; // 0 px
|
||||
private final double k_em = 1024;
|
||||
private final int k_defaultAdvanceWidth = 512;
|
||||
private final String k_dotDtyp = ".dtyp";
|
||||
private final String k_dotTtf = ".ttf";
|
||||
|
||||
private File m_dir;
|
||||
private Hashtable<String, Integer> m_nameToIndeces = new Hashtable<>();
|
||||
private File m_ttfFile;
|
||||
private Font m_font = null;
|
||||
private File m_binFolder;
|
||||
|
||||
public TypefaceFile(String a_name, File a_dir) throws FileNotFoundException {
|
||||
super(TypefaceFile.class.getResource(s_emptyFileName));
|
||||
|
||||
m_dir = a_dir;
|
||||
setGlyphTitle(a_name);
|
||||
|
||||
m_fileName = new File(m_dir, a_name + k_dotDtyp);
|
||||
initFileName();
|
||||
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public TypefaceFile(File a_file) {
|
||||
super(a_file);
|
||||
|
||||
m_dir = a_file.getParentFile();
|
||||
m_fileName = a_file;
|
||||
|
||||
initFileName();
|
||||
}
|
||||
|
||||
private void initFileName() {
|
||||
m_binFolder = new File(m_dir, "bin");
|
||||
if (!m_binFolder.exists()) {
|
||||
m_binFolder.mkdir();
|
||||
} // if
|
||||
|
||||
String fileName = getGlyphTitle() + k_dotTtf;
|
||||
m_ttfFile = new File(m_binFolder, fileName);
|
||||
}
|
||||
|
||||
public GlyphFile createGlyph(long a_unicode) throws FileNotFoundException {
|
||||
String name = Character.getName((int) a_unicode);
|
||||
if (name == null) {
|
||||
name = "NAC_" + Long.toHexString(a_unicode);
|
||||
} // if
|
||||
|
||||
name = name.replace(' ', '_');
|
||||
return new GlyphFile(
|
||||
getGlyphPath(), name, a_unicode);
|
||||
}
|
||||
|
||||
public boolean addRequiredGlyphs() throws FileNotFoundException {
|
||||
boolean retval = false;
|
||||
|
||||
if (unicodeToFileName(TTUnicodeRange.k_notDef) == null) {
|
||||
GlyphFile glyph = new GlyphFile(getGlyphPath(), "NOTDEF", TTUnicodeRange.k_notDef);
|
||||
glyph.initNotDef(k_defaultAdvanceWidth);
|
||||
addGlyph(0, glyph);
|
||||
retval = true;
|
||||
} // if
|
||||
|
||||
if (unicodeToFileName(TTUnicodeRange.k_null) == null) {
|
||||
GlyphFile glyph = new GlyphFile(getGlyphPath(), "NULL", TTUnicodeRange.k_null);
|
||||
glyph.initNullGlyph();
|
||||
addGlyph(1, glyph);
|
||||
retval = true;
|
||||
} // if
|
||||
|
||||
if (unicodeToFileName(TTUnicodeRange.k_cr) == null) {
|
||||
GlyphFile glyph = new GlyphFile(getGlyphPath(), "CR", TTUnicodeRange.k_cr);
|
||||
glyph.initSpace(k_defaultAdvanceWidth);
|
||||
addGlyph(2, glyph);
|
||||
retval = true;
|
||||
} // if
|
||||
|
||||
if (unicodeToFileName(TTUnicodeRange.k_space) == null) {
|
||||
GlyphFile glyph = new GlyphFile(getGlyphPath(), "SPACE", TTUnicodeRange.k_space);
|
||||
glyph.initSpace(k_defaultAdvanceWidth);
|
||||
addGlyph(3, glyph);
|
||||
retval = true;
|
||||
} // if
|
||||
|
||||
if (retval) {
|
||||
saveGlyphFile();
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public void addBasicLatinGlyphs() throws FileNotFoundException {
|
||||
String basicLatin = Character.UnicodeBlock.BASIC_LATIN.toString();
|
||||
TTUnicodeRange.find(basicLatin);
|
||||
TTUnicodeRange range = TTUnicodeRange.getLastFound();
|
||||
addUnicodeRange(basicLatin);
|
||||
for (long i = range.getStartCode(); i <= range.getEndCode(); i++) {
|
||||
if (i != 0x0020) {
|
||||
addGlyph(createGlyph(i));
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public File getGlyphPath() {
|
||||
return m_dir;
|
||||
}
|
||||
|
||||
public String unicodeToFileName(long a_unicode) {
|
||||
for (XGlyphFile glyphFile: m_glyph.getBody().getGlyphFile()) {
|
||||
if (glyphFile.getUnicode() == a_unicode) {
|
||||
return glyphFile.getHref();
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* change glyph's unicode mapping.
|
||||
* @param a_glyphFile
|
||||
* @param a_unicode
|
||||
*/
|
||||
public void setGlyphUnicode(GlyphFile a_glyphFile, long a_unicode) throws FileNotFoundException {
|
||||
int i;
|
||||
XGlyphFile [] glyphFiles = m_glyph.getBody().getGlyphFile();
|
||||
for (i = 0; i < glyphFiles.length; i++) {
|
||||
XGlyphFile glyphFile = glyphFiles[i];
|
||||
|
||||
if (glyphFile.getHref().equals(
|
||||
a_glyphFile.getShortFileName())) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
glyphFile.setUnicode(a_unicode);
|
||||
a_glyphFile.setUnicode(Long.toHexString(a_unicode));
|
||||
a_glyphFile.saveGlyphFile();
|
||||
saveGlyphFile();
|
||||
|
||||
return;
|
||||
} // for i
|
||||
}
|
||||
|
||||
public void addGlyph(GlyphFile a_file) {
|
||||
XGlyphFile xglyphFile = new XGlyphFile();
|
||||
xglyphFile.setHref(a_file.getShortFileName());
|
||||
xglyphFile.setUnicode(a_file.getUnicodeAsLong());
|
||||
m_glyph.getBody().addGlyphFile(xglyphFile);
|
||||
}
|
||||
|
||||
public void addGlyph(int a_index, GlyphFile a_file) {
|
||||
XGlyphFile xglyphFile = new XGlyphFile();
|
||||
xglyphFile.setHref(a_file.getShortFileName());
|
||||
xglyphFile.setUnicode(a_file.getUnicodeAsLong());
|
||||
m_glyph.getBody().addGlyphFile(a_index, xglyphFile);
|
||||
}
|
||||
|
||||
public void removeGlyph(String a_fileName) {
|
||||
for (XGlyphFile file: m_glyph.getBody().getGlyphFile()) {
|
||||
if (file.getHref().equals(a_fileName)) {
|
||||
m_glyph.getBody().removeGlyphFile(file);
|
||||
return;
|
||||
} // if
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> getChildFileNames() {
|
||||
ArrayList<String> retval = new ArrayList<>();
|
||||
XGlyphFile [] files = m_glyph.getBody().getGlyphFile();
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
XGlyphFile file = files[i];
|
||||
retval.add(file.getHref());
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public Object [] getCodePages() {
|
||||
int i;
|
||||
Object [] retval;
|
||||
String [] codePages = m_glyph.getHead().getCodePage();
|
||||
retval = new Object[codePages.length];
|
||||
for (i = 0; i < codePages.length; i++) {
|
||||
retval[i] = codePages[i];
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public boolean containsUnicodeRange(String a_unicodeRange) {
|
||||
int i;
|
||||
String [] unicodeRanges = m_glyph.getHead().getUnicodeRange();
|
||||
|
||||
for (i = 0; i < unicodeRanges.length; i++) {
|
||||
if (unicodeRanges[i].equals(a_unicodeRange)) {
|
||||
return true;
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addUnicodeRange(String a_unicodeRange) throws FileNotFoundException {
|
||||
if (containsUnicodeRange(a_unicodeRange)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_glyph.getHead().addUnicodeRange(a_unicodeRange);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public boolean containsCodePage(String a_codePage) {
|
||||
int i;
|
||||
String [] codePages = m_glyph.getHead().getCodePage();
|
||||
|
||||
for (i = 0; i < codePages.length; i++) {
|
||||
if (codePages[i].equals(a_codePage)) {
|
||||
return true;
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addCodePage(String a_codePage) throws FileNotFoundException {
|
||||
if (containsCodePage(a_codePage)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_glyph.getHead().addCodePage(a_codePage);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public void removeCodePage(String a_codePage) throws FileNotFoundException {
|
||||
if (!containsCodePage(a_codePage)) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_glyph.getHead().removeCodePage(a_codePage);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public void setFontFamilyName(String a_value) throws FileNotFoundException {
|
||||
m_glyph.getHead().setFontFamily(a_value);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public String getFontFamilyName() {
|
||||
return m_glyph.getHead().getFontFamily();
|
||||
}
|
||||
|
||||
public String getVersion() throws FileNotFoundException {
|
||||
if (m_glyph.getHead().getVersion() == null) {
|
||||
m_glyph.getHead().setVersion("0.1");
|
||||
saveGlyphFile();
|
||||
} // if
|
||||
|
||||
return m_glyph.getHead().getVersion();
|
||||
}
|
||||
|
||||
public void setSubFamily(String a_value) throws FileNotFoundException {
|
||||
m_glyph.getHead().setFontSubFamily(a_value);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public void setDefaultMetrics() throws FileNotFoundException {
|
||||
XHead head = m_glyph.getHead();
|
||||
head.setTopSideBearing(k_defaultTopSideBearing);
|
||||
head.setAscender(k_defaultAscender);
|
||||
head.setXHeight(k_defaultXHeight);
|
||||
head.setDescender(k_defaultDescender);
|
||||
head.setBottomSideBearing(k_defaultBottomSideBearing);
|
||||
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public double getEm() {
|
||||
return k_em;
|
||||
}
|
||||
|
||||
public double getBaseline() throws FileNotFoundException {
|
||||
return getBottomSideBearing() + getDescender();
|
||||
}
|
||||
|
||||
public double getMeanline() throws FileNotFoundException {
|
||||
return getBottomSideBearing()
|
||||
+ getDescender() + getXHeight();
|
||||
}
|
||||
|
||||
public double getBodyBottom() throws FileNotFoundException {
|
||||
return getBottomSideBearing();
|
||||
}
|
||||
|
||||
public double getBodyTop() throws FileNotFoundException {
|
||||
return getEm() - getTopSideBearing();
|
||||
}
|
||||
|
||||
public double getTopSideBearing() throws FileNotFoundException {
|
||||
if (!m_glyph.getHead().checkTopSideBearing()) {
|
||||
setDefaultMetrics();
|
||||
} // if
|
||||
|
||||
return m_glyph.getHead().getTopSideBearing();
|
||||
}
|
||||
|
||||
public double getAscender() throws FileNotFoundException {
|
||||
if (!m_glyph.getHead().checkAscender()) {
|
||||
setDefaultMetrics();
|
||||
} // if
|
||||
|
||||
return m_glyph.getHead().getAscender();
|
||||
}
|
||||
|
||||
public double getXHeight() throws FileNotFoundException {
|
||||
if (!m_glyph.getHead().checkXHeight()) {
|
||||
setDefaultMetrics();
|
||||
} // if
|
||||
|
||||
return m_glyph.getHead().getXHeight();
|
||||
}
|
||||
|
||||
public double getDescender() throws FileNotFoundException {
|
||||
if (!m_glyph.getHead().checkDescender()) {
|
||||
setDefaultMetrics();
|
||||
} // if
|
||||
|
||||
return m_glyph.getHead().getDescender();
|
||||
}
|
||||
|
||||
public double getBottomSideBearing() throws FileNotFoundException {
|
||||
if (!m_glyph.getHead().checkBottomSideBearing()) {
|
||||
setDefaultMetrics();
|
||||
} // if
|
||||
|
||||
return m_glyph.getHead().getBottomSideBearing();
|
||||
}
|
||||
|
||||
public void setTopSideBearing(double a_value) throws OutOfRangeException, FileNotFoundException {
|
||||
checkBoundary(a_value);
|
||||
m_glyph.getHead().setTopSideBearing(a_value);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
private void checkBoundary(double a_value) throws OutOfRangeException {
|
||||
if (a_value > k_em || a_value < 0) {
|
||||
throw new OutOfRangeException(a_value);
|
||||
} // if
|
||||
}
|
||||
|
||||
public void setAscender(double a_value) throws OutOfRangeException, FileNotFoundException {
|
||||
checkBoundary(a_value);
|
||||
m_glyph.getHead().setAscender(a_value);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public void setXHeight(double a_value) throws OutOfRangeException, FileNotFoundException {
|
||||
checkBoundary(a_value);
|
||||
if (a_value > getAscender()) {
|
||||
throw new OutOfRangeException(a_value);
|
||||
} // if
|
||||
|
||||
m_glyph.getHead().setXHeight(a_value);
|
||||
|
||||
m_history.record("setXHeight");
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public void setDescender(double a_value) throws OutOfRangeException, FileNotFoundException {
|
||||
checkBoundary(a_value);
|
||||
m_glyph.getHead().setDescender(a_value);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public void setBottomSideBearing(double a_value) throws OutOfRangeException, FileNotFoundException {
|
||||
checkBoundary(a_value);
|
||||
m_glyph.getHead().setBottomSideBearing(a_value);
|
||||
saveGlyphFile();
|
||||
}
|
||||
|
||||
public double getBodyHeight() throws FileNotFoundException {
|
||||
return k_em - getTopSideBearing() - getBottomSideBearing();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Calls FontFileWriter to produce TrueType font file.
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public void buildTTF(boolean a_isDebug) throws Exception {
|
||||
String randomString = UUID.randomUUID().toString().substring(0, 4);
|
||||
|
||||
File tempFile = new File(m_binFolder,
|
||||
getGlyphTitle() + "_" + randomString + k_dotTtf);
|
||||
File target;
|
||||
String fontFamilyName;
|
||||
|
||||
if (a_isDebug) {
|
||||
target = tempFile;
|
||||
fontFamilyName = getGlyphTitle() + " " + randomString;
|
||||
} else {
|
||||
target = m_ttfFile;
|
||||
fontFamilyName = getFontFamilyName();
|
||||
} // if-else
|
||||
|
||||
target.delete();
|
||||
FontFileWriter writer;
|
||||
ModuleManager.getSingletonInstance().clear();
|
||||
m_stack.clear();
|
||||
m_stack.push(this);
|
||||
try (RandomAccessFile randomAccessFile = new RandomAccessFile(target, "rw")) {
|
||||
writer = new FontFileWriter(randomAccessFile);
|
||||
|
||||
writer.setFontFamilyName(fontFamilyName);
|
||||
writer.setCopyrightYear(getCopyrightYear());
|
||||
writer.setFontVersion(getVersion());
|
||||
writer.setManufacturer(getAuthor());
|
||||
writer.setAscent((int) getAscender());
|
||||
writer.setXHeight((int) getXHeight());
|
||||
writer.setDescent((int) getDescender());
|
||||
writer.setLineGap((int) (getTopSideBearing() + getBottomSideBearing()));
|
||||
|
||||
loadCodePages(writer);
|
||||
loadUnicodeRanges(writer);
|
||||
loadGlyphs(writer);
|
||||
writer.write();
|
||||
}
|
||||
if (!a_isDebug && target.exists()) {
|
||||
copyFile(target, tempFile);
|
||||
} // if
|
||||
|
||||
FileInputStream in = new FileInputStream(tempFile);
|
||||
m_font = Font.createFont(Font.TRUETYPE_FONT,
|
||||
(InputStream) in);
|
||||
in.close();
|
||||
|
||||
ModuleManager.getSingletonInstance().clear();
|
||||
m_stack.pop(); // pop this
|
||||
}
|
||||
|
||||
private void copyFile(File a_in, File a_out) throws Exception {
|
||||
FileInputStream in = new FileInputStream(a_in);
|
||||
FileOutputStream out = new FileOutputStream(a_out);
|
||||
byte [] buffer = new byte[1024];
|
||||
int i = 0;
|
||||
while ((i = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, i);
|
||||
} // while
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
|
||||
public Font getFont() {
|
||||
return m_font;
|
||||
}
|
||||
|
||||
private void loadCodePages(FontFileWriter a_writer) {
|
||||
for (String codePageName: m_glyph.getHead().getCodePage()) {
|
||||
TTCodePage codePage = TTCodePage.forName(codePageName);
|
||||
if (codePage == null) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
a_writer.setCodeRangeFlag(codePage.getOsTwoFlag());
|
||||
} // for codePageName
|
||||
}
|
||||
|
||||
private void loadUnicodeRanges(FontFileWriter a_writer) {
|
||||
String [] unicodeRanges = m_glyph.getHead().getUnicodeRange();
|
||||
int i;
|
||||
for (i = 0; i < unicodeRanges.length; i++) {
|
||||
if (!TTUnicodeRange.find(unicodeRanges[i])) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
a_writer.addUnicodeRange(TTUnicodeRange.getLastFound());
|
||||
} // for i
|
||||
}
|
||||
|
||||
private void loadGlyphs(FontFileWriter a_writer) throws Exception {
|
||||
m_nameToIndeces.clear();
|
||||
|
||||
for (String fileName: getChildFileNames()) {
|
||||
GlyphFile glyphFile = nameToGlyphFile(fileName);
|
||||
loadGlyph(glyphFile, glyphFile, a_writer);
|
||||
} // for
|
||||
}
|
||||
|
||||
private GlyphFile nameToGlyphFile(String a_fileName) throws FileNotFoundException {
|
||||
File file = new File(m_dir, a_fileName);
|
||||
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException(a_fileName);
|
||||
} // if
|
||||
|
||||
GlyphFile retval = new GlyphFile(file);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* load the glyph into FontFileWriter.
|
||||
* @param a_fileName
|
||||
* @param a_writer
|
||||
* @throws Exception
|
||||
*/
|
||||
private void loadGlyph(GlyphFile a_glyphFile, VarStackFrame a_frame, FontFileWriter a_writer) throws Exception {
|
||||
if (m_nameToIndeces.containsKey(a_glyphFile.getShortFileName())) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
/*
|
||||
if (a_glyphFile.getUnicodeAsLong() == TTUnicodeRange.k_null) {
|
||||
return;
|
||||
} // if
|
||||
*/
|
||||
|
||||
TTGlyph glyph = null;
|
||||
m_stack.push(a_frame);
|
||||
|
||||
if (a_glyphFile.isSimple()) {
|
||||
// glyph will be null if it is empty
|
||||
glyph = a_glyphFile.toSimpleGlyph();
|
||||
} else {
|
||||
glyph = createCompoundGlyph(a_glyphFile, a_writer);
|
||||
} // if
|
||||
|
||||
m_stack.pop();
|
||||
|
||||
if (glyph == null && a_glyphFile.isWhiteSpace()) {
|
||||
glyph = new TTGlyph();
|
||||
} // if
|
||||
|
||||
if (glyph == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
int glyphIndex = a_writer.addGlyph(glyph);
|
||||
m_nameToIndeces.put(a_glyphFile.getShortFileName(), glyphIndex);
|
||||
long unicode = a_glyphFile.getUnicodeAsLong();
|
||||
|
||||
if (unicode != -1 && glyph != null) {
|
||||
long existingIndex = a_writer.getCharacterMapping(unicode);
|
||||
if (existingIndex != 0) {
|
||||
throw new Exception(Long.toHexString(unicode) + " is mapped already.");
|
||||
} // if
|
||||
|
||||
a_writer.addCharacterMapping(unicode, glyphIndex);
|
||||
} // if
|
||||
}
|
||||
|
||||
private TTGlyph createCompoundGlyph(GlyphFile a_glyphFile,
|
||||
FontFileWriter a_writer) throws Exception
|
||||
{
|
||||
TTGlyph retval = new TTGlyph();
|
||||
ArrayList<Point> locs = new ArrayList<>();
|
||||
ArrayList<Integer> indeces = new ArrayList<>();
|
||||
|
||||
retval.setSimple(false);
|
||||
retval.setAdvanceWidth(a_glyphFile.getAdvanceWidth());
|
||||
|
||||
TTGlyph simple = a_glyphFile.toSimpleGlyph();
|
||||
if (simple != null) {
|
||||
int glyphIndex = a_writer.addGlyph(simple);
|
||||
|
||||
locs.add(new Point(0, 0));
|
||||
indeces.add(glyphIndex);
|
||||
} // if
|
||||
|
||||
XInclude [] includes = a_glyphFile.m_glyph.getBody().getInclude();
|
||||
int i;
|
||||
for (i = 0; i < includes.length; i++) {
|
||||
EIncludeInvoke include = (EIncludeInvoke) includes[i];
|
||||
GlyphFile glyphFile = nameToGlyphFile(include.getHref());
|
||||
|
||||
// load the glyph included in this one
|
||||
loadGlyph(glyphFile, include, a_writer);
|
||||
Integer n = m_nameToIndeces.get(glyphFile.getShortFileName());
|
||||
if (n == null) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
indeces.add(n);
|
||||
XPoint2d pos = include.getInvoke().getInvokePos().getPoint2d();
|
||||
locs.add(new Point((int) pos.getX(), (int) pos.getY()));
|
||||
} // for i
|
||||
|
||||
int flag = TTGlyph.ARG_1_AND_2_ARE_WORDS
|
||||
| TTGlyph.ARGS_ARE_XY_VALUES
|
||||
| TTGlyph.ROUND_XY_TO_GRID;
|
||||
int numOfCompositePoints = 0;
|
||||
int numOfCompositeContours = 0;
|
||||
int componentDepth = 0;
|
||||
|
||||
for (int glyfIndex: indeces) {
|
||||
TTGlyph glyph = a_writer.getGlyph(glyfIndex);
|
||||
numOfCompositePoints += glyph.getNumOfCompositePoints();
|
||||
numOfCompositeContours += glyph.getNumOfCompositeContours();
|
||||
if (glyph.getComponentDepth() > componentDepth) {
|
||||
componentDepth = glyph.getComponentDepth();
|
||||
} // if
|
||||
|
||||
retval.addGlyfIndex(glyfIndex);
|
||||
if (i < indeces.size() - 1) {
|
||||
retval.addFlag(flag | TTGlyph.MORE_COMPONENTS);
|
||||
} else {
|
||||
retval.addFlag(flag);
|
||||
} // if-else
|
||||
|
||||
Point loc = locs.get(i);
|
||||
retval.addArg1(loc.x);
|
||||
retval.addArg2(loc.y);
|
||||
} // for
|
||||
|
||||
retval.setNumOfCompositePoints(numOfCompositePoints);
|
||||
retval.setNumOfCompositeContours(numOfCompositeContours);
|
||||
retval.setComponentDepth(componentDepth + 1);
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
112
trunk/libsrc/ttf/src/org/doubletype/ossa/module/VarStack.java
Normal file
112
trunk/libsrc/ttf/src/org/doubletype/ossa/module/VarStack.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* $Id: VarStack.java,v 1.1 2004/04/21 10:54:41 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.module;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class VarStack {
|
||||
private static VarStack s_varstack = null;
|
||||
|
||||
public static VarStack getSingletonInstance() {
|
||||
if (s_varstack == null)
|
||||
s_varstack = new VarStack();
|
||||
|
||||
return s_varstack;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
private ArrayList<VarStackFrame> m_stack = new ArrayList<>();
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public void push(VarStackFrame a_frame) {
|
||||
a_frame.beforePush();
|
||||
m_stack.add(a_frame);
|
||||
}
|
||||
|
||||
public VarStackFrame pop() {
|
||||
VarStackFrame retval = peek();
|
||||
if (retval == null) {
|
||||
return retval;
|
||||
} // if
|
||||
|
||||
m_stack.remove(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public VarStackFrame peek() {
|
||||
if (m_stack.size() <= 0) {
|
||||
return null;
|
||||
} // if
|
||||
|
||||
return (VarStackFrame) m_stack.get(m_stack.size() - 1);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
m_stack.clear();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return m_stack.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* goes through the var stack and returns the variable value
|
||||
* @param a_name name of the variable
|
||||
* @return the value of the variable
|
||||
*/
|
||||
public double get(String a_name) {
|
||||
int i;
|
||||
double retval = 0.0;
|
||||
|
||||
for (i = 0; i < m_stack.size(); i++) {
|
||||
VarStackFrame frame
|
||||
= (VarStackFrame) m_stack.get(m_stack.size() - i - 1);
|
||||
if (!frame.hasVariable(a_name)) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
return frame.getValue(a_name);
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* $Id: VarStackFrame.java,v 1.1 2004/04/21 10:55:02 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.module;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public interface VarStackFrame {
|
||||
/**
|
||||
* tests if the variable is declared in this module.
|
||||
* @param a_name name of the variable
|
||||
* @return true, if declared; false, otherwise.
|
||||
*/
|
||||
boolean hasVariable(String a_name);
|
||||
double getValue(String a_name);
|
||||
|
||||
/** fired before push by the var stack.
|
||||
*/
|
||||
void beforePush();
|
||||
}
|
||||
21
trunk/libsrc/ttf/src/org/doubletype/ossa/module/empty.glyph
Normal file
21
trunk/libsrc/ttf/src/org/doubletype/ossa/module/empty.glyph
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<glyphElement xmlns="http://doubletype.org/ns/glyph/0.0">
|
||||
<head>
|
||||
<title></title>
|
||||
<unicode></unicode>
|
||||
|
||||
<author>Nobody</author>
|
||||
<copyright>2004</copyright>
|
||||
<fontFamily>temp</fontFamily>
|
||||
<fontSubFamily>Regular</fontSubFamily>
|
||||
<license>All rights reserved.</license>
|
||||
|
||||
<global>
|
||||
</global>
|
||||
<local>
|
||||
</local>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</glyphElement>
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* $Id: CmapWriter.java,v 1.8 2004/01/27 00:35:08 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class CmapWriter extends FontFormatWriter {
|
||||
final long k_basicLatinStart = 0x20;
|
||||
final long k_basicLatinEnd = 0x7e;
|
||||
final long k_tableEnd = 0xffff;
|
||||
final int k_unmappedChar = 0x0;
|
||||
|
||||
private OS2Writer m_os2;
|
||||
private List<Long> m_unicodes = new ArrayList<>();
|
||||
private List<Long> m_startCodes = new ArrayList<>();
|
||||
private List<Long> m_endCodes = new ArrayList<>();
|
||||
private Hashtable<Long, Long> m_unicode2glyph = new Hashtable<>();
|
||||
private List<TTUnicodeRange> m_unicodeRanges = new ArrayList<>();
|
||||
private List<Long> m_idDeltas = new ArrayList<>();
|
||||
private List<Long> m_idRangeOffsets = new ArrayList<>();
|
||||
private boolean m_isIncludeVersion0;
|
||||
private byte [] m_version0;
|
||||
private byte [] m_version4;
|
||||
private byte [] m_version12;
|
||||
|
||||
public CmapWriter(OS2Writer a_os2) {
|
||||
super();
|
||||
|
||||
m_os2 = a_os2;
|
||||
m_isIncludeVersion0 = false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void prepare() {
|
||||
Collections.sort(m_unicodeRanges);
|
||||
|
||||
TTUnicodeRange range = (TTUnicodeRange) m_unicodeRanges.get(0);
|
||||
m_os2.m_usFirstCharIndex = (int) range.getStartCode();
|
||||
m_os2.m_usLastCharIndex = (int) range.getEndCode();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < m_unicodeRanges.size(); i++) {
|
||||
range = m_unicodeRanges.get(i);
|
||||
|
||||
m_startCodes.add(range.getStartCode());
|
||||
m_endCodes.add(range.getEndCode());
|
||||
m_idDeltas.add(0L);
|
||||
m_idRangeOffsets.add(
|
||||
2L * (m_unicodeRanges.size() - i) + 2L
|
||||
+ 2L * (m_unicodes.size()));
|
||||
|
||||
m_os2.m_usLastCharIndex = (int) range.getEndCode();
|
||||
m_os2.setUnicodeRangeFlag(range.getOsTwoFlag());
|
||||
|
||||
for (long unicode = range.getStartCode();
|
||||
unicode <= range.getEndCode(); unicode++)
|
||||
{
|
||||
m_unicodes.add(unicode);
|
||||
} // for unicode
|
||||
} // for i
|
||||
|
||||
m_startCodes.add(k_tableEnd);
|
||||
m_endCodes.add(k_tableEnd);
|
||||
m_idDeltas.add(1L);
|
||||
m_idRangeOffsets.add(0L);
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
prepare();
|
||||
|
||||
if (m_isIncludeVersion0) {
|
||||
storeVersion0();
|
||||
} // if
|
||||
storeVersion4();
|
||||
|
||||
reset();
|
||||
|
||||
writeUInt16(0); // table version number
|
||||
writeUInt16(getNumOfEncoding()); // num of encodings
|
||||
|
||||
if (m_isIncludeVersion0) {
|
||||
writeUInt16(TTName.k_macintosh);
|
||||
writeUInt16(TTName.k_macRomanEncode);
|
||||
writeUInt32(size() + 4 + 8);
|
||||
} // if
|
||||
|
||||
writeUInt16(TTName.k_microsoft);
|
||||
writeUInt16(TTName.k_winUnicodeEncode);
|
||||
int version4Offset = size() + 4;
|
||||
if (m_isIncludeVersion0) {
|
||||
version4Offset += m_version0.length;
|
||||
} // if
|
||||
writeUInt32(version4Offset);
|
||||
|
||||
if (m_isIncludeVersion0) {
|
||||
m_buffer.write(m_version0);
|
||||
} // if
|
||||
|
||||
m_buffer.write(m_version4);
|
||||
pad();
|
||||
}
|
||||
|
||||
private int getNumOfEncoding() {
|
||||
if (m_isIncludeVersion0) {
|
||||
return 2;
|
||||
} // if
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void addUnicodeRange(TTUnicodeRange a_range) {
|
||||
m_unicodeRanges.add(a_range);
|
||||
}
|
||||
|
||||
public void addMapping(long a_unicode, long a_glyfIndex) {
|
||||
m_unicode2glyph.put(a_unicode, a_glyfIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find 'glyf' index for the given unicode.
|
||||
* This method returns 0, if a_key was not found, which will be treated
|
||||
* as unmapped character.
|
||||
* @param a_key Long object with unicode value.
|
||||
* @return 'glyf' index if a_key was found; 0 otherwise.
|
||||
*/
|
||||
public long getGlyfIndex(Long a_key) {
|
||||
long retval = 0;
|
||||
|
||||
if (m_unicode2glyph.containsKey(a_key)) {
|
||||
retval = m_unicode2glyph.get(a_key);
|
||||
} // if
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private void storeVersion0() throws IOException {
|
||||
reset();
|
||||
writeVersion0();
|
||||
m_version0 = toByteArray();
|
||||
reset();
|
||||
}
|
||||
|
||||
private void storeVersion4() throws IOException {
|
||||
reset();
|
||||
writeVersion4();
|
||||
m_version4 = toByteArray();
|
||||
reset();
|
||||
}
|
||||
|
||||
private void storeVersion12() throws IOException {
|
||||
reset();
|
||||
writeVersion12();
|
||||
m_version12 = toByteArray();
|
||||
reset();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "cmap";
|
||||
}
|
||||
|
||||
private void writeVersion0() throws IOException {
|
||||
writeUInt16(0);
|
||||
writeUInt16(262);
|
||||
writeUInt16(0);
|
||||
int i;
|
||||
for (i = 0; i < 256; i++) {
|
||||
if ((i == 0x000) || (i == 0x0008) || (i == 0x001D)) {
|
||||
writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_null)); // .null
|
||||
}
|
||||
else if ((i == 0x0009) || (i == 0x000d)) {
|
||||
writeUInt8((int) getGlyfIndex(TTUnicodeRange.k_cr)); // CR
|
||||
}
|
||||
else {
|
||||
writeUInt8((int) getGlyfIndex((long) i));
|
||||
} // if
|
||||
} // for i
|
||||
}
|
||||
|
||||
private void writeVersion4() throws IOException {
|
||||
int segCount = m_startCodes.size();
|
||||
int i;
|
||||
|
||||
// endCount
|
||||
for (i = 0; i < segCount; i++) {
|
||||
Long n = (Long) m_endCodes.get(i);
|
||||
writeUInt16(n.intValue());
|
||||
} // for i
|
||||
|
||||
// reserverdPad
|
||||
writeUInt16(0);
|
||||
|
||||
// startCount
|
||||
for (i = 0; i < segCount; i++) {
|
||||
Long n = m_startCodes.get(i);
|
||||
writeUInt16(n.intValue());
|
||||
} // for i
|
||||
|
||||
// idDelta
|
||||
for (i = 0; i < segCount; i++) {
|
||||
Long n = m_idDeltas.get(i);
|
||||
writeInt16(n.intValue());
|
||||
} // for i
|
||||
|
||||
// idRangeOffset
|
||||
for (i = 0; i < segCount; i++) {
|
||||
Long n = m_idRangeOffsets.get(i);
|
||||
writeInt16(n.intValue());
|
||||
}
|
||||
|
||||
// glyphIdArray 2 bytes each
|
||||
for (i = 0; i < m_unicodes.size(); i++) {
|
||||
Long unicode = m_unicodes.get(i);
|
||||
writeUInt16((int) getGlyfIndex(unicode));
|
||||
} // for i
|
||||
|
||||
byte [] bytes = m_bytes.toByteArray();
|
||||
|
||||
reset();
|
||||
|
||||
writeUInt16(4);
|
||||
writeUInt16(bytes.length + 14);
|
||||
writeUInt16(0);
|
||||
writeUInt16(segCount * 2);
|
||||
|
||||
int searchRange = getSearchRange(segCount);
|
||||
writeUInt16(searchRange);
|
||||
writeUInt16(getEntrySelector(searchRange));
|
||||
writeUInt16(getRangeShift(segCount, searchRange));
|
||||
m_buffer.write(bytes);
|
||||
}
|
||||
|
||||
public void writeVersion12() throws IOException {
|
||||
ArrayList<Long> startCharCode = new ArrayList<>();
|
||||
ArrayList<Long> endCharCode = new ArrayList<>();
|
||||
ArrayList<Long> startGlyphCode = new ArrayList<>();
|
||||
|
||||
// TODO: map to real one
|
||||
startCharCode.add(k_basicLatinStart);
|
||||
endCharCode.add(k_basicLatinEnd);
|
||||
startGlyphCode.add(1L);
|
||||
|
||||
long length = 16 + 12 * startCharCode.size();
|
||||
|
||||
writeFixed32(12.0);
|
||||
writeUInt32(length);
|
||||
writeUInt32(0);
|
||||
writeUInt32(startCharCode.size());
|
||||
|
||||
int i;
|
||||
for (i = 0; i < startCharCode.size(); i++) {
|
||||
writeUInt32(startCharCode.get(i));
|
||||
writeUInt32(endCharCode.get(i));
|
||||
writeUInt32(startGlyphCode.get(i));
|
||||
} // for i
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for searchRange
|
||||
* @param a_value
|
||||
* @return
|
||||
*/
|
||||
private int getSearchRange(int a_value) {
|
||||
int retval
|
||||
= (int) Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2)));
|
||||
return 2 * retval;
|
||||
}
|
||||
|
||||
private int getEntrySelector(int a_searchRange) {
|
||||
int retval
|
||||
= (int) (Math.log(a_searchRange / 2) / Math.log(2));
|
||||
return retval;
|
||||
}
|
||||
|
||||
private int getRangeShift(int a_value, int a_searchRange) {
|
||||
int retval
|
||||
= 2 * a_value - a_searchRange;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* $Id: FontFileWriter.java,v 1.15 2004/10/04 02:25:39 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class FontFileWriter extends FontFormatWriter {
|
||||
private CmapWriter m_cmap;
|
||||
private GlyfWriter m_glyf;
|
||||
private LocaWriter m_loca;
|
||||
private HeadWriter m_head;
|
||||
private HdmxWriter m_hdmx;
|
||||
private HheaWriter m_hhea;
|
||||
private HmtxWriter m_hmtx;
|
||||
private MaxpWriter m_maxp;
|
||||
private NameWriter m_name;
|
||||
private PostWriter m_post;
|
||||
private OS2Writer m_os2;
|
||||
|
||||
protected RandomAccessFile m_file;
|
||||
private ArrayList<FontFormatWriter> m_tables = new ArrayList<>();
|
||||
|
||||
public FontFileWriter(RandomAccessFile a_file) {
|
||||
super();
|
||||
|
||||
m_file = a_file;
|
||||
|
||||
m_loca = new LocaWriter();
|
||||
m_maxp = new MaxpWriter();
|
||||
m_head = new HeadWriter();
|
||||
m_hdmx = new HdmxWriter();
|
||||
m_os2 = new OS2Writer(m_head);
|
||||
m_cmap = new CmapWriter(m_os2);
|
||||
|
||||
m_glyf = new GlyfWriter(m_loca, m_maxp,
|
||||
m_head, m_hdmx);
|
||||
|
||||
m_hhea = new HheaWriter(m_glyf, m_head);
|
||||
m_hmtx = new HmtxWriter(m_glyf, m_hhea);
|
||||
m_name = new NameWriter();
|
||||
m_post = new PostWriter();
|
||||
|
||||
// http://www.microsoft.com/typography/otspec/recom.htm
|
||||
// head, hhea, maxp, OS/2, hmtx, LTSH, VDMX, hdmx, cmap,
|
||||
// fpgm, prep, cvt, loca, glyf, kern, name, post, gasp, PCLT, DSIG
|
||||
/*
|
||||
m_tables.add(m_head);
|
||||
m_tables.add(m_hhea);
|
||||
m_tables.add(m_maxp);
|
||||
m_tables.add(m_os2);
|
||||
m_tables.add(m_hmtx);
|
||||
m_tables.add(m_hdmx);
|
||||
m_tables.add(m_cmap);
|
||||
m_tables.add(m_loca);
|
||||
m_tables.add(m_glyf);
|
||||
m_tables.add(m_name);
|
||||
m_tables.add(m_post);
|
||||
*/
|
||||
|
||||
// Verdana has head, hhea, maxp, OS/2, gasp, name, cmap, loca
|
||||
// LTSH, VDMX, prep, fpgm, cvt, hmtx, hdmx, glyf, post, kern, edt0, DSIG
|
||||
m_tables.add(m_head);
|
||||
m_tables.add(m_hhea);
|
||||
m_tables.add(m_maxp);
|
||||
m_tables.add(m_os2);
|
||||
m_tables.add(m_name);
|
||||
m_tables.add(m_cmap);
|
||||
m_tables.add(m_loca);
|
||||
|
||||
m_tables.add(m_hmtx);
|
||||
m_tables.add(m_hdmx);
|
||||
m_tables.add(m_glyf);
|
||||
m_tables.add(m_post);
|
||||
}
|
||||
|
||||
/**
|
||||
* write TrueType file to the random access file
|
||||
*/
|
||||
public void write() throws IOException {
|
||||
m_cmap.write();
|
||||
// hmtx must be written before hhea
|
||||
m_hmtx.write();
|
||||
m_hhea.write();
|
||||
|
||||
m_glyf.write();
|
||||
m_loca.write();
|
||||
|
||||
m_head.setCheckSumAdjustment(0);
|
||||
m_head.write();
|
||||
m_maxp.write(); // must be written after m_glyf
|
||||
m_hdmx.write();
|
||||
m_name.write();
|
||||
m_post.write();
|
||||
m_os2.write();
|
||||
|
||||
writeTableDirectory();
|
||||
byte [] tableDir = toByteArray();
|
||||
for (FontFormatWriter table: m_tables) {
|
||||
m_buffer.write(table.toByteArray());
|
||||
} // for table
|
||||
|
||||
long checkSum = 0xb1b0afba - (0xffffffff & getCheckSum());
|
||||
m_head.setCheckSumAdjustment(checkSum);
|
||||
m_head.reset();
|
||||
m_head.write();
|
||||
|
||||
reset();
|
||||
|
||||
m_buffer.write(tableDir);
|
||||
for (FontFormatWriter table: m_tables) {
|
||||
m_buffer.write(table.toByteArray());
|
||||
} // for table
|
||||
|
||||
m_file.write(toByteArray());
|
||||
m_file.close();
|
||||
}
|
||||
|
||||
public void setAscent(int a_value) {
|
||||
m_os2.setTypoAscender(a_value);
|
||||
m_os2.setCapHeight(a_value);
|
||||
}
|
||||
|
||||
public void setDescent(int a_value) {
|
||||
m_os2.setTypoDescender(-a_value);
|
||||
}
|
||||
|
||||
public void setXHeight(int a_value) {
|
||||
m_os2.setXHeight(a_value);
|
||||
}
|
||||
|
||||
public void setLineGap(int a_value) {
|
||||
m_os2.setTypoLineGap(a_value);
|
||||
m_hhea.setLineGap(a_value);
|
||||
}
|
||||
|
||||
public void setFontFamilyName(String a_name) {
|
||||
m_name.m_familyName = a_name;
|
||||
}
|
||||
|
||||
public void setCopyrightYear(String a_year) {
|
||||
m_name.m_year = a_year;
|
||||
}
|
||||
|
||||
public void setManufacturer(String a_manufacturer) {
|
||||
m_name.m_manufacturer = a_manufacturer;
|
||||
}
|
||||
|
||||
public void setFontVersion(String a_version) {
|
||||
m_name.m_version = a_version;
|
||||
}
|
||||
|
||||
public void addUnicodeRange(TTUnicodeRange a_range) {
|
||||
m_cmap.addUnicodeRange(a_range);
|
||||
}
|
||||
|
||||
/**
|
||||
* http://www.microsoft.com/typography/otspec/os2.htm
|
||||
* @param a_codeRange position of the bit. For example, JIS will be 17.
|
||||
*/
|
||||
public void setCodeRangeFlag(int a_codeRange) {
|
||||
m_os2.setCodePageRangeFlag(a_codeRange);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds glyph to the 'glyf' subtable.
|
||||
* @param a_glyph the glyph to be added.
|
||||
* @return 'glyf' index of the added glyph.
|
||||
*/
|
||||
public int addGlyph(TTGlyph a_glyph) {
|
||||
return m_glyf.add(a_glyph);
|
||||
}
|
||||
|
||||
public TTGlyph getGlyph(int a_index) {
|
||||
return m_glyf.getGlyph(a_index);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds character mapping to
|
||||
* @param a_unicode unicode of the character
|
||||
* @param a_glyfIndex 'glyf' index obtained from #addGlyph
|
||||
*/
|
||||
public void addCharacterMapping(long a_unicode, long a_glyfIndex) {
|
||||
m_cmap.addMapping(a_unicode, a_glyfIndex);
|
||||
}
|
||||
|
||||
public long getCharacterMapping(long a_unicode) {
|
||||
return m_cmap.getGlyfIndex(new Long(a_unicode));
|
||||
}
|
||||
|
||||
/**
|
||||
* writes table directory.
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeTableDirectory() throws IOException {
|
||||
int headerLength = m_tables.size() * 16 + 16;
|
||||
int tableOffset = headerLength;
|
||||
for (FontFormatWriter table: m_tables) {
|
||||
table.setOffset(tableOffset);
|
||||
tableOffset += table.size();
|
||||
} // for table
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<FontFormatWriter> tables = (ArrayList<FontFormatWriter>) m_tables.clone();
|
||||
Collections.sort(tables, new Comparator<FontFormatWriter>() {
|
||||
public int compare(FontFormatWriter a_lhs, FontFormatWriter a_rhs) {
|
||||
return a_lhs.getTag().compareTo(a_rhs.getTag());
|
||||
}
|
||||
|
||||
public boolean equals(Object a_value) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
writeFixed32(1.0);
|
||||
|
||||
int numOfTables = tables.size();
|
||||
writeUInt16(numOfTables);
|
||||
int searchRange = getSearchRange(numOfTables);
|
||||
writeUInt16(searchRange);
|
||||
int entrySelector = getEntrySelector(numOfTables);
|
||||
writeUInt16(entrySelector);
|
||||
writeUInt16(numOfTables * 16 - searchRange);
|
||||
|
||||
for (FontFormatWriter table: tables) {
|
||||
writeTag(table.getTag());
|
||||
writeUInt32(table.getCheckSum());
|
||||
writeUInt32(table.getOffset());
|
||||
writeUInt32(table.size());
|
||||
} // for
|
||||
|
||||
// padding is always 4 zeros
|
||||
for (int i = 0; i < 4; i++) {
|
||||
writeUInt8(0);
|
||||
} // for i
|
||||
}
|
||||
|
||||
private int getSearchRange(int a_value) {
|
||||
int retval
|
||||
= (int) (Math.pow(2, Math.floor(Math.log(a_value) / Math.log(2))));
|
||||
return 16 * retval;
|
||||
}
|
||||
|
||||
private int getEntrySelector(int a_value) {
|
||||
int retval
|
||||
= (int) Math.floor(Math.log(a_value) / Math.log(2));
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* $Id: FontFormatWriter.java,v 1.6 2004/01/28 11:44:08 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class FontFormatWriter {
|
||||
protected DataOutputStream m_buffer;
|
||||
protected ByteArrayOutputStream m_bytes;
|
||||
private int m_offset;
|
||||
|
||||
public FontFormatWriter() {
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
m_bytes = new ByteArrayOutputStream();
|
||||
m_buffer = new DataOutputStream(m_bytes);
|
||||
m_offset = 0;
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
return m_bytes.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of buffer in bytes.
|
||||
* @return size of buffer in bytes.
|
||||
*/
|
||||
public int size() {
|
||||
return m_bytes.size();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
m_bytes.reset();
|
||||
}
|
||||
|
||||
protected void writeFixed32(double a_value) throws IOException {
|
||||
final int k_denom = 16384;
|
||||
|
||||
short mantissa = (short) Math.floor(a_value);
|
||||
int fraction = (int) ((a_value - mantissa) * k_denom);
|
||||
if (fraction > k_denom) {
|
||||
fraction = 0;
|
||||
mantissa++;
|
||||
} // if
|
||||
|
||||
m_buffer.writeShort(mantissa);
|
||||
m_buffer.writeShort(fraction);
|
||||
}
|
||||
|
||||
protected void writeUInt16(int a_value) throws IOException {
|
||||
writeInt16((short) (0xffff & a_value));
|
||||
}
|
||||
|
||||
protected void writeInt16(int a_value) throws IOException {
|
||||
m_buffer.writeShort((short) a_value);
|
||||
}
|
||||
|
||||
protected void writeFWord(int a_value) throws IOException {
|
||||
writeInt16(a_value);
|
||||
}
|
||||
|
||||
protected void writeUFWord(int a_value) throws IOException {
|
||||
writeUInt16(a_value);
|
||||
}
|
||||
|
||||
protected void writeUInt32 (long a_value) throws IOException {
|
||||
writeInt32((int) (0xffffffff & a_value));
|
||||
}
|
||||
|
||||
protected void writeInt32(int a_value) throws IOException {
|
||||
m_buffer.writeInt(a_value);
|
||||
}
|
||||
|
||||
protected void writeUInt8(int a_byte) throws IOException {
|
||||
m_buffer.writeByte(a_byte);
|
||||
}
|
||||
|
||||
protected void writeTag(String a_value) throws IOException {
|
||||
String s = a_value + " ";
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
writeUInt8(s.charAt(i));
|
||||
} // for i
|
||||
}
|
||||
|
||||
protected void writeLongDateTime(Date a_date) throws IOException {
|
||||
long sec = a_date.getTime() / 1000;
|
||||
sec += (1970 - 1904) * 365 * 24 * 60 * 60;
|
||||
m_buffer.writeLong(sec);
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
throw new RuntimeException("unimplemnted call to getTag");
|
||||
}
|
||||
|
||||
protected long getCheckSum() {
|
||||
long retval = 0;
|
||||
byte [] bytes = toByteArray();
|
||||
|
||||
for (int i = 0; i < bytes.length / 4; i++) {
|
||||
long n = 0;
|
||||
for (int j = 0; j < 4; j++) {
|
||||
n += bytes[4 * i + j] << ((4 - j) * 8);
|
||||
} // for j
|
||||
retval += n;
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
protected void pad() throws IOException {
|
||||
int align = 4;
|
||||
int numOfPad = align - toByteArray().length % align;
|
||||
if (numOfPad == align)
|
||||
return;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < numOfPad; i++) {
|
||||
writeUInt8(0);
|
||||
} // for i
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
public void setOffset(int a_value) {
|
||||
m_offset = a_value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* $Id: GlyfWriter.java,v 1.17 2004/09/23 07:47:39 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class GlyfWriter extends FontFormatWriter {
|
||||
private ArrayList<TTGlyph> m_glyphs;
|
||||
|
||||
private LocaWriter m_loca;
|
||||
private MaxpWriter m_maxp;
|
||||
private HeadWriter m_head;
|
||||
private HdmxWriter m_hdmx;
|
||||
|
||||
public GlyfWriter(LocaWriter a_loca, MaxpWriter a_maxp,
|
||||
HeadWriter a_head, HdmxWriter a_hdmx) {
|
||||
super();
|
||||
|
||||
m_loca = a_loca;
|
||||
m_maxp = a_maxp;
|
||||
m_head = a_head;
|
||||
m_hdmx = a_hdmx;
|
||||
m_glyphs = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
m_hdmx.setNumGlyphs(numOfGlyph());
|
||||
m_maxp.setNumGlyphs(numOfGlyph());
|
||||
m_loca.m_offsets.clear();
|
||||
|
||||
for (int i = 0; i < m_glyphs.size(); i++) {
|
||||
writeGlyph(m_glyphs.get(i));
|
||||
m_hdmx.updatePixelWidth(i, m_glyphs.get(i));
|
||||
} // for i
|
||||
|
||||
m_loca.m_offsets.add(size());
|
||||
}
|
||||
|
||||
public int add(TTGlyph a_glyph) {
|
||||
m_head.updateMax(a_glyph.getMax());
|
||||
m_head.updateMin(a_glyph.getMin());
|
||||
|
||||
m_glyphs.add(a_glyph);
|
||||
return m_glyphs.size() - 1;
|
||||
}
|
||||
|
||||
public int numOfGlyph() {
|
||||
return m_glyphs.size();
|
||||
}
|
||||
|
||||
public TTGlyph getGlyph(int a_index) {
|
||||
return m_glyphs.get(a_index);
|
||||
}
|
||||
|
||||
private void writeGlyph(TTGlyph a_glyph) throws IOException {
|
||||
m_loca.m_offsets.add(size());
|
||||
|
||||
if (a_glyph == null) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
if (a_glyph.isSimple()) {
|
||||
writeSimpleGlyph(a_glyph);
|
||||
} else {
|
||||
writeCompoundGlyph(a_glyph);
|
||||
} // if-else
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param a_glyph
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeSimpleGlyph(TTGlyph a_glyph) throws IOException {
|
||||
if (a_glyph.getNumOfContours() == 0) {
|
||||
return;
|
||||
} // if
|
||||
|
||||
m_maxp.updateNumOfContours(a_glyph.getNumOfContours());
|
||||
writeInt16(a_glyph.getNumOfContours());
|
||||
writeMinMax(a_glyph);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < a_glyph.getNumOfContours(); i++) {
|
||||
writeUInt16(a_glyph.getEndPoint(i));
|
||||
} // for i
|
||||
|
||||
int numOfInst = a_glyph.getNumOfInstructions();
|
||||
m_maxp.updateSizeOfInstructions(numOfInst);
|
||||
|
||||
writeUInt16(numOfInst);
|
||||
for (i = 0; i < numOfInst; i++) {
|
||||
writeUInt8(a_glyph.getInstruction(i));
|
||||
} // for i
|
||||
|
||||
for (i = 0; i < a_glyph.getNumOfFlags(); i++) {
|
||||
int flag = a_glyph.getFlag(i);
|
||||
writeUInt8(flag);
|
||||
} // for i
|
||||
|
||||
// update num of points
|
||||
m_maxp.updateNumOfPoints(a_glyph.getNumOfPoints());
|
||||
|
||||
int lastX = 0;
|
||||
for (i = 0; i < a_glyph.getNumOfPoints(); i++) {
|
||||
Point point = a_glyph.getPoint(i);
|
||||
|
||||
writeInt16(point.x - lastX);
|
||||
lastX = point.x;
|
||||
} // for i
|
||||
|
||||
int lastY = 0;
|
||||
for (i = 0; i < a_glyph.getNumOfPoints(); i++) {
|
||||
Point point = a_glyph.getPoint(i);
|
||||
|
||||
writeInt16(point.y - lastY);
|
||||
lastY = point.y;
|
||||
} // for i
|
||||
}
|
||||
|
||||
/**
|
||||
* @param a_glyph
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeCompoundGlyph(TTGlyph a_glyph) throws IOException {
|
||||
int i;
|
||||
|
||||
m_maxp.updateNumOfCompositePoints(a_glyph.getNumOfCompositePoints());
|
||||
m_maxp.updateNumOfCompositeContours(a_glyph.getNumOfCompositeContours());
|
||||
|
||||
writeInt16(-1);
|
||||
writeMinMax(a_glyph);
|
||||
|
||||
int numOfGlyphs = a_glyph.getNumOfFlags();
|
||||
m_maxp.updateNumOfComponentElements(numOfGlyphs);
|
||||
m_maxp.updateComponentDepth(a_glyph.getComponentDepth());
|
||||
|
||||
for (i = 0; i < numOfGlyphs; i++) {
|
||||
writeUInt16(a_glyph.getFlag(i));
|
||||
writeUInt16(a_glyph.getGlyfIndex(i));
|
||||
writeInt16(a_glyph.getArg1(i));
|
||||
writeInt16(a_glyph.getArg2(i));
|
||||
} // for i
|
||||
}
|
||||
|
||||
/**
|
||||
* @param a_glyph
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeMinMax(TTGlyph a_glyph) throws IOException {
|
||||
Point min = a_glyph.getMin();
|
||||
Point max = a_glyph.getMax();
|
||||
|
||||
writeFWord(min.x);
|
||||
writeFWord(min.y);
|
||||
writeFWord(max.x);
|
||||
writeFWord(max.y);
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "glyf";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* $Copyright: copyright (c) 2003-2008, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* HtmxWriter depends on GlyfWriter.
|
||||
*
|
||||
* @author e.e
|
||||
*/
|
||||
public class HdmxWriter extends FontFormatWriter {
|
||||
static public int getNumOfPixelSizes() {
|
||||
return TTPixelSize.getList().size();
|
||||
}
|
||||
|
||||
static public ArrayList<TTPixelSize> getPixelSizes() {
|
||||
return TTPixelSize.getList();
|
||||
}
|
||||
|
||||
private int m_numGlyphs = 98; // set by GlyfWriter
|
||||
|
||||
public HdmxWriter() {
|
||||
super();
|
||||
}
|
||||
|
||||
/** set the number of glyphs in the font */
|
||||
public void setNumGlyphs(int a_value) {
|
||||
m_numGlyphs = a_value;
|
||||
|
||||
for (TTPixelSize pixelSize: getPixelSizes()) {
|
||||
pixelSize.setPixelWidthsSize(a_value);
|
||||
} // for pixelSize
|
||||
}
|
||||
|
||||
public void updatePixelWidth(int a_glyphIndex, TTGlyph a_glyph) {
|
||||
double advanceWidth = a_glyph.getAdvanceWidth();
|
||||
double em = TTPixelSize.getEm();
|
||||
|
||||
for (TTPixelSize pixelSize: TTPixelSize.getList()) {
|
||||
int width = (int) Math.round(((double) pixelSize.getPixel() * advanceWidth) / em);
|
||||
pixelSize.setPixelWidth(a_glyphIndex, width);
|
||||
} // pixelSize
|
||||
}
|
||||
|
||||
/**
|
||||
* writes htmx record.
|
||||
* The size of a device record is calculated to align it to 32bit boundary.
|
||||
*/
|
||||
public void write() throws IOException {
|
||||
int numOfPads = 4 - ((m_numGlyphs + 2) % 4);
|
||||
if (numOfPads == 4) {
|
||||
numOfPads = 0;
|
||||
} // if
|
||||
int size = m_numGlyphs + 2 + numOfPads; // 2 comes from the ppem and max
|
||||
|
||||
// format version number
|
||||
writeInt16(0);
|
||||
|
||||
// number of device records
|
||||
writeInt16(getNumOfPixelSizes());
|
||||
//System.out.printf("num of pixel sizes %d\n", getNumOfPixelSizes());
|
||||
// size of device record
|
||||
writeInt32(size);
|
||||
//System.out.printf("num of glyphs %d\n", m_numGlyphs);
|
||||
for (TTPixelSize pixelSize: getPixelSizes()) {
|
||||
writeUInt8(pixelSize.getPixel());
|
||||
writeUInt8(pixelSize.getMaxPixelWidth());
|
||||
for (int pixelWidth: pixelSize.getPixelWidths()) {
|
||||
writeUInt8(pixelWidth);
|
||||
} // for pixelWidth
|
||||
|
||||
for (int j = 0; j < numOfPads; j++) {
|
||||
writeUInt8(0);
|
||||
} // for j
|
||||
} // for pixelSize
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "hdmx";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* $Id: HeadWriter.java,v 1.7 2004/09/26 09:15:48 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class HeadWriter extends FontFormatWriter {
|
||||
static public final int k_yZeroIsBaseLine = 0x1; // bit 0
|
||||
static public final int k_xLeftMostBlackIsLsb = 0x2; // bit 1
|
||||
static public final int k_scaledPointDiffer = 0x4; // bit 2
|
||||
static public final int k_useIntegerScaling = 0x8; // bit 3
|
||||
|
||||
// used by microsoft
|
||||
static public final int k_scaleLinear = 0x10;
|
||||
|
||||
// for vertical fonts
|
||||
static public final int k_xZeroIsBaseLine = 0x20;
|
||||
// 0x40
|
||||
static public final int k_linguisticRendering = 0x80;
|
||||
static public final int k_defaultMetamorphosis = 0x100;
|
||||
static public final int k_rightToLeft = 0x200;
|
||||
static public final int k_indicRearrangement = 0x400;
|
||||
|
||||
|
||||
private final long k_magicNumber = 0x5f0f3cf5;
|
||||
|
||||
private long m_checkSumAdjustment = 0;
|
||||
private Point m_min = new Point(0, 0);
|
||||
private Point m_max = new Point(0, 0);
|
||||
|
||||
public HeadWriter() {
|
||||
super();
|
||||
}
|
||||
|
||||
void setCheckSumAdjustment(long a_value) {
|
||||
m_checkSumAdjustment = a_value;
|
||||
}
|
||||
|
||||
public Point getMin() {
|
||||
return m_min;
|
||||
}
|
||||
|
||||
public Point getMax() {
|
||||
return m_max;
|
||||
}
|
||||
|
||||
public void updateMin(Point a_value) {
|
||||
if (a_value.x < m_min.x) {
|
||||
m_min.x = a_value.x;
|
||||
} // if
|
||||
|
||||
if (a_value.y < m_min.y) {
|
||||
m_min.y = a_value.y;
|
||||
} // if
|
||||
}
|
||||
|
||||
public void updateMax(Point a_value) {
|
||||
if (a_value.x > m_max.x) {
|
||||
m_max.x = a_value.x;
|
||||
} // if
|
||||
|
||||
if (a_value.y > m_max.y) {
|
||||
m_max.y = a_value.y;
|
||||
} // if
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
// table version number
|
||||
writeFixed32(1.0);
|
||||
|
||||
// fontRevision
|
||||
writeFixed32(1.0);
|
||||
|
||||
writeUInt32(m_checkSumAdjustment);
|
||||
writeUInt32(k_magicNumber);
|
||||
|
||||
// LSB is the distance from 0, 0 to the left of the glyph bounds.
|
||||
// flags
|
||||
writeUInt16(k_yZeroIsBaseLine
|
||||
| k_xLeftMostBlackIsLsb
|
||||
| k_scaledPointDiffer);;
|
||||
|
||||
// unitsPerEm
|
||||
writeUInt16(1024);
|
||||
|
||||
// created, modified
|
||||
writeLongDateTime(new Date());
|
||||
writeLongDateTime(new Date());
|
||||
|
||||
writeFWord(m_min.x);
|
||||
writeFWord(m_min.y);
|
||||
writeFWord(m_max.x);
|
||||
writeFWord(m_max.y);
|
||||
|
||||
// macStyle
|
||||
writeUInt16(0);
|
||||
|
||||
// lowestRecPPEM
|
||||
writeUInt16(11);
|
||||
|
||||
// font direction hint
|
||||
// 2, for strongly left to right
|
||||
// but also contains neutrals
|
||||
writeInt16(2);
|
||||
|
||||
// indexToLocFormat. 1, for long
|
||||
writeInt16(1);
|
||||
|
||||
// glyfDataFormat
|
||||
writeInt16(0);
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "head";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* $Id: HheaWriter.java,v 1.5 2004/09/26 09:15:48 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* HheaWriter depends on HtmxWriter.
|
||||
* @author e.e
|
||||
*/
|
||||
public class HheaWriter extends FontFormatWriter {
|
||||
private GlyfWriter m_glyf;
|
||||
private HeadWriter m_head;
|
||||
|
||||
private int m_lineGap = 0;
|
||||
private int m_maxAdvanceWidth = 0;
|
||||
private int m_minRightSideBearing = 0;
|
||||
|
||||
public HheaWriter(GlyfWriter a_glyf, HeadWriter a_head) {
|
||||
super();
|
||||
|
||||
m_glyf = a_glyf;
|
||||
m_head = a_head;
|
||||
}
|
||||
|
||||
public void setLineGap(int a_value) {
|
||||
m_lineGap = a_value;
|
||||
}
|
||||
|
||||
public void setMaxAdvanceWidth(int a_value) {
|
||||
m_maxAdvanceWidth = a_value;
|
||||
}
|
||||
|
||||
public void setMinRightSideBearing(int a_value) {
|
||||
m_minRightSideBearing = a_value;
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
// table version number
|
||||
writeFixed32(1.0);
|
||||
|
||||
writeFWord(m_head.getMax().y);
|
||||
writeFWord(m_head.getMin().y);
|
||||
writeFWord(m_lineGap);
|
||||
writeUFWord(m_maxAdvanceWidth);
|
||||
|
||||
int minLeftSideBearing = m_head.getMin().x;
|
||||
writeFWord(minLeftSideBearing);
|
||||
writeFWord(m_minRightSideBearing);
|
||||
|
||||
int xMaxExtent = m_head.getMax().x - m_head.getMin().x;
|
||||
writeFWord(xMaxExtent);
|
||||
|
||||
// caratSlopeRise
|
||||
writeInt16(1);
|
||||
writeInt16(0);
|
||||
|
||||
// reserved
|
||||
for (int i = 0; i < 5; i++) {
|
||||
writeInt16(0);
|
||||
} // for i
|
||||
|
||||
writeInt16(0);
|
||||
|
||||
int numOfHMetrics = m_glyf.numOfGlyph();
|
||||
writeUInt16(numOfHMetrics);
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "hhea";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* $Id: HmtxWriter.java,v 1.10 2004/10/04 02:25:39 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* HtmxWriter depends on GlyfWriter.
|
||||
*
|
||||
* @author e.e
|
||||
*/
|
||||
public class HmtxWriter extends FontFormatWriter {
|
||||
HheaWriter m_hhea;
|
||||
GlyfWriter m_glyf;
|
||||
|
||||
public HmtxWriter(GlyfWriter a_glyf, HheaWriter a_hhea) {
|
||||
super();
|
||||
|
||||
m_hhea = a_hhea;
|
||||
m_glyf = a_glyf;
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
int i;
|
||||
|
||||
TTGlyph glyphZero = m_glyf.getGlyph(0);
|
||||
int maxWidth = glyphZero.getAdvanceWidth();
|
||||
int minRightSideBearing = glyphZero.getRightSideBearing();
|
||||
for (i = 0; i < m_glyf.numOfGlyph(); i++) {
|
||||
TTGlyph glyph = m_glyf.getGlyph(i);
|
||||
|
||||
if (glyph.getAdvanceWidth() > maxWidth) {
|
||||
maxWidth = glyph.getAdvanceWidth();
|
||||
} // if
|
||||
|
||||
if (glyph.getRightSideBearing() < minRightSideBearing) {
|
||||
minRightSideBearing = glyph.getRightSideBearing();
|
||||
} // if
|
||||
|
||||
writeUFWord(glyph.getAdvanceWidth());
|
||||
writeFWord(glyph.getLeftSideBearing());
|
||||
} // for i
|
||||
|
||||
writeFWord(0);
|
||||
|
||||
m_hhea.setMaxAdvanceWidth(maxWidth);
|
||||
m_hhea.setMinRightSideBearing(minRightSideBearing);
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "hmtx";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* $Id: LocaWriter.java,v 1.3 2004/01/15 07:06:27 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class LocaWriter extends FontFormatWriter {
|
||||
public ArrayList<Integer> m_offsets = new ArrayList<>();
|
||||
|
||||
public LocaWriter() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
// assume glyf table is already written,
|
||||
// and offsets are stored in m_offsets
|
||||
|
||||
int i;
|
||||
for (i = 0; i < m_offsets.size(); i++) {
|
||||
writeUInt32(m_offsets.get(i));
|
||||
} // for i
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "loca";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* $Id: MaxpWriter.java,v 1.11 2004/06/27 07:26:46 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class MaxpWriter extends FontFormatWriter {
|
||||
private int m_numGlyphs = 98; // set by GlyfWriter
|
||||
private int m_maxPoints = 0;
|
||||
private int m_maxContours = 0;
|
||||
private int m_maxCompositePoints = 0;
|
||||
private int m_maxCompositeContours = 0;
|
||||
private int m_maxZones = 2;
|
||||
private int m_maxTwilightPoints = 128;
|
||||
private int m_maxStorage = 64;
|
||||
private int m_maxFunctionDefs = 128;
|
||||
private int m_maxInstructionDefs = 128;
|
||||
private int m_maxStackElements = 128;
|
||||
private int m_maxSizeOfInstructions = 128;
|
||||
private int m_maxComponentElements = 128;
|
||||
private int m_maxComponentDepth = 0;
|
||||
|
||||
public MaxpWriter() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
writeFixed32(1.0);
|
||||
writeUInt16(m_numGlyphs);
|
||||
writeUInt16(m_maxPoints);
|
||||
writeUInt16(m_maxContours);
|
||||
writeUInt16(m_maxCompositePoints);
|
||||
writeUInt16(m_maxCompositeContours);
|
||||
writeUInt16(m_maxZones);
|
||||
writeUInt16(m_maxTwilightPoints);
|
||||
writeUInt16(m_maxStorage);
|
||||
writeUInt16(m_maxFunctionDefs);
|
||||
writeUInt16(m_maxInstructionDefs);
|
||||
writeUInt16(m_maxStackElements);
|
||||
writeUInt16(m_maxSizeOfInstructions);
|
||||
writeUInt16(m_maxComponentElements);
|
||||
writeUInt16(m_maxComponentDepth);
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "maxp";
|
||||
}
|
||||
|
||||
/** set the number of glyphs in the font */
|
||||
public void setNumGlyphs(int a_value) {
|
||||
m_numGlyphs = a_value;
|
||||
}
|
||||
|
||||
/** update points in non-compound glyph */
|
||||
public void updateNumOfPoints(int a_value) {
|
||||
if (a_value > m_maxPoints) {
|
||||
m_maxPoints = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
/** update points in non-compound glyph */
|
||||
public void updateNumOfContours(int a_value) {
|
||||
if (a_value > m_maxContours) {
|
||||
m_maxContours = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
public void updateNumOfCompositePoints(int a_value) {
|
||||
if (a_value > m_maxCompositePoints) {
|
||||
m_maxCompositePoints = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
public void updateNumOfCompositeContours(int a_value) {
|
||||
if (a_value > m_maxCompositeContours) {
|
||||
m_maxCompositeContours = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
/** update byte count for glyph instructions */
|
||||
public void updateSizeOfInstructions(int a_value) {
|
||||
if (a_value > m_maxSizeOfInstructions) {
|
||||
m_maxSizeOfInstructions = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
public void updateNumOfComponentElements(int a_value) {
|
||||
if (a_value > m_maxComponentElements) {
|
||||
m_maxComponentElements = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
public void updateComponentDepth(int a_value) {
|
||||
if (a_value > m_maxComponentDepth) {
|
||||
m_maxComponentDepth = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* $Id: NameWriter.java,v 1.9 2004/06/16 07:02:52 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class NameWriter extends FontFormatWriter {
|
||||
public static final String k_regular = "Regular";
|
||||
private static final String k_utf16be = "UTF-16BE";
|
||||
private static final String k_iso8859_1 = "ISO-8859-1";
|
||||
|
||||
String m_copyright = "\u00A9 Copyright";
|
||||
String m_familyName = "Temp";
|
||||
String m_subFamilyName = k_regular;
|
||||
String m_unique = "eed3si9n: Temp Regular: 2003";
|
||||
String m_fullFontName = "Temp";
|
||||
String m_version = "0.00";
|
||||
String m_psName = "Temp";
|
||||
String m_tradeMark = "";
|
||||
String m_manufacturer = "eed3si9n";
|
||||
String m_year = "2004";
|
||||
String m_sample = "The quick brown fox jumps over the lazy dog.";
|
||||
|
||||
private ArrayList<TTName> m_names = new ArrayList<>();
|
||||
|
||||
public NameWriter() {
|
||||
super();
|
||||
}
|
||||
|
||||
private void prepare() {
|
||||
m_copyright = "\u00A9 Copyright "
|
||||
+ m_year
|
||||
+ ", "
|
||||
+ m_manufacturer
|
||||
+ ".";
|
||||
m_unique = "dtype: "
|
||||
+ m_manufacturer + ": "
|
||||
+ m_familyName + " "
|
||||
+ m_subFamilyName + ": "
|
||||
+ "Version " + m_version + ": "
|
||||
+ m_year;
|
||||
m_fullFontName = m_familyName;
|
||||
m_psName = m_fullFontName;
|
||||
|
||||
if (m_tradeMark.length() == 0) {
|
||||
m_tradeMark = "n/a";
|
||||
} // if
|
||||
|
||||
m_names.clear();
|
||||
addNames();
|
||||
}
|
||||
|
||||
private void addNames() {
|
||||
addMacintoshRomanEnglish(0, m_copyright);
|
||||
addMacintoshRomanEnglish(1, m_familyName);
|
||||
addMacintoshRomanEnglish(2, m_subFamilyName);
|
||||
addMacintoshRomanEnglish(3, m_unique);
|
||||
addMacintoshRomanEnglish(4, m_fullFontName);
|
||||
addMacintoshRomanEnglish(5, "Version " + m_version);
|
||||
addMacintoshRomanEnglish(6, m_psName);
|
||||
addMacintoshRomanEnglish(7, m_tradeMark);
|
||||
addMacintoshRomanEnglish(8, m_manufacturer);
|
||||
|
||||
addMicrosoftUnicodeEnglish(0, m_copyright);
|
||||
addMicrosoftUnicodeEnglish(1, m_familyName);
|
||||
addMicrosoftUnicodeEnglish(2, m_subFamilyName);
|
||||
addMicrosoftUnicodeEnglish(3, m_unique);
|
||||
addMicrosoftUnicodeEnglish(4, m_fullFontName);
|
||||
addMicrosoftUnicodeEnglish(5, "Version " + m_version);
|
||||
addMicrosoftUnicodeEnglish(6, m_psName);
|
||||
addMicrosoftUnicodeEnglish(7, m_tradeMark);
|
||||
addMicrosoftUnicodeEnglish(8, m_manufacturer);
|
||||
// addMicrosoftUnicodeEnglish(19, m_sample);
|
||||
}
|
||||
|
||||
private void addMacintoshRomanEnglish(int a_nameId, String a_value) {
|
||||
try {
|
||||
add(TTName.k_macintosh,
|
||||
TTName.k_macRomanEncode,
|
||||
TTName.k_macEnglishLang,
|
||||
a_nameId,
|
||||
a_value.getBytes(k_iso8859_1));
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} // try-catch
|
||||
}
|
||||
|
||||
private void addMicrosoftUnicodeEnglish(int a_nameId, String a_value) {
|
||||
try {
|
||||
add(TTName.k_microsoft,
|
||||
TTName.k_winUnicodeEncode,
|
||||
TTName.k_winEnglishLang,
|
||||
a_nameId,
|
||||
a_value.getBytes(k_utf16be));
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void add(int a_platformId, int a_encodingId, int a_languageId,
|
||||
int a_nameId, byte a_bytes[]) {
|
||||
TTName name = new TTName(a_platformId,
|
||||
a_encodingId,
|
||||
a_languageId,
|
||||
a_nameId,
|
||||
a_bytes);
|
||||
m_names.add(name);
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
prepare();
|
||||
|
||||
// table version number
|
||||
writeUInt16(0);
|
||||
|
||||
// number of name records
|
||||
writeUInt16(m_names.size());
|
||||
|
||||
// Offset to start of string storage (from start of table).
|
||||
writeUInt16(12 * m_names.size() + 6);
|
||||
|
||||
int offset = 0;
|
||||
for (TTName name: m_names) {
|
||||
writeUInt16(name.getPlatformId());
|
||||
writeUInt16(name.getEncodingId());
|
||||
writeUInt16(name.getLanguageId());
|
||||
writeUInt16(name.getNameId());
|
||||
writeUInt16(name.getStringLength());
|
||||
writeUInt16(offset);
|
||||
offset += name.getStringLength();
|
||||
} // for i
|
||||
|
||||
for (TTName name: m_names) {
|
||||
m_buffer.write(name.getBytes());
|
||||
} // for i
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "name";
|
||||
}
|
||||
}
|
||||
242
trunk/libsrc/ttf/src/org/doubletype/ossa/truetype/OS2Writer.java
Normal file
242
trunk/libsrc/ttf/src/org/doubletype/ossa/truetype/OS2Writer.java
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* $Id: OS2Writer.java,v 1.11 2004/10/04 02:25:39 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class OS2Writer extends FontFormatWriter {
|
||||
final int FW_THIN = 100;
|
||||
final int FW_EXTRALIGHT = 200;
|
||||
final int FW_LIGHT = 300;
|
||||
final int FW_NORMAL = 400;
|
||||
final int FW_MEDIUM = 500;
|
||||
final int FW_SEMIBOLD = 600;
|
||||
final int FW_BOLD = 700;
|
||||
final int FW_EXTRABOLD = 800;
|
||||
final int FW_BLACK = 900;
|
||||
|
||||
final int FWIDTH_NORMAL = 5;
|
||||
|
||||
final int k_editableEmbedding = 0x0008;
|
||||
|
||||
final int k_sansSerif = 0x0800;
|
||||
|
||||
// unicode
|
||||
final int k_basicLatin = 0x0001;
|
||||
final int k_latin1Supplement = 0x0002;
|
||||
|
||||
final int k_regular = 0x40;
|
||||
final int k_basicLatinStart = 0x0020;
|
||||
final int k_basciLatinEnd = 0x007e;
|
||||
|
||||
private HeadWriter m_head;
|
||||
|
||||
int m_xAvgCharWidth = 512;
|
||||
int m_usWeightClass = FW_NORMAL;
|
||||
int m_usWidthClass = FWIDTH_NORMAL;
|
||||
int m_fsType = 0;
|
||||
int m_ySubscriptXSize = 128;
|
||||
int m_ySubscriptYSize = 128;
|
||||
int m_ySubscriptXOffset = 0;
|
||||
int m_ySubscriptYOffset = -64;
|
||||
int m_ySuperscriptXSize = 128;
|
||||
int m_ySuperscriptYSize = 128;
|
||||
int m_ySuperscriptXOffset = 0;
|
||||
int m_ySuperscriptYOffset = 64;
|
||||
int m_yStrikeoutSize = 51;
|
||||
int m_yStrikeoutPosition = 512;
|
||||
int m_sFamilyClass = k_sansSerif;
|
||||
|
||||
long m_ulUnicodeRange1 = k_basicLatin | k_latin1Supplement;
|
||||
long m_ulUnicodeRange2 = 0;
|
||||
long m_ulUnicodeRange3 = 0;
|
||||
long m_ulUnicodeRange4 = 0;
|
||||
String m_vendId = "dtyp";
|
||||
int m_fsSelection = k_regular;
|
||||
int m_usFirstCharIndex = k_basicLatinStart;
|
||||
int m_usLastCharIndex = k_basciLatinEnd;
|
||||
private int m_sTypoAscender = 1024;
|
||||
private int m_sTypoDescender = 0;
|
||||
private int m_sTypoLineGap = 0;
|
||||
private int m_usWinAscent = 1024;
|
||||
private int m_usWinDescent = 0;
|
||||
long m_ulCodePageRange1 = 0;
|
||||
long m_ulCodePageRange2 = 0;
|
||||
private int m_sxHeight = 512;
|
||||
private int m_sCapHeight = 1024;
|
||||
int m_usDefaultChar = 0x0;
|
||||
int m_usBreakChar = 0x20;
|
||||
int m_usMaxContext = 1;
|
||||
|
||||
public OS2Writer(HeadWriter a_head) {
|
||||
super();
|
||||
|
||||
m_head = a_head;
|
||||
}
|
||||
|
||||
public void setCapHeight(int a_value) {
|
||||
m_sCapHeight = a_value;
|
||||
}
|
||||
|
||||
public void setXHeight(int a_value) {
|
||||
m_sxHeight = a_value;
|
||||
}
|
||||
|
||||
public void setTypoAscender(int a_value) {
|
||||
m_sTypoAscender = a_value;
|
||||
}
|
||||
|
||||
public void setTypoDescender(int a_value) {
|
||||
m_sTypoDescender = a_value;
|
||||
}
|
||||
|
||||
public void setTypoLineGap(int a_value) {
|
||||
m_sTypoLineGap = a_value;
|
||||
}
|
||||
|
||||
public void setUnicodeRangeFlag(int a_pos) {
|
||||
int which = a_pos / 32;
|
||||
int where = a_pos % 32;
|
||||
long what = 0x1 << where;
|
||||
|
||||
switch (which) {
|
||||
case 0: {
|
||||
m_ulUnicodeRange1 |= what;
|
||||
} break;
|
||||
|
||||
case 1: {
|
||||
m_ulUnicodeRange2 |= what;
|
||||
} break;
|
||||
|
||||
case 2: {
|
||||
m_ulUnicodeRange3 |= what;
|
||||
} break;
|
||||
|
||||
case 3: {
|
||||
m_ulUnicodeRange4 |= what;
|
||||
} break;
|
||||
} // switch
|
||||
}
|
||||
|
||||
public void setCodePageRangeFlag(int a_pos) {
|
||||
int which = a_pos / 32;
|
||||
int where = a_pos % 32;
|
||||
long what = 0x1 << where;
|
||||
|
||||
switch (which) {
|
||||
case 0: {
|
||||
m_ulCodePageRange1 |= what;
|
||||
} break;
|
||||
|
||||
case 1: {
|
||||
m_ulCodePageRange2 |= what;
|
||||
} break;
|
||||
} // switch
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
m_usWinAscent = m_head.getMax().y;
|
||||
m_usWinDescent = 0;
|
||||
if (m_head.getMin().y < 0) {
|
||||
m_usWinDescent = -m_head.getMin().y;
|
||||
} // if
|
||||
|
||||
// table version number
|
||||
writeUInt16(0x02);
|
||||
|
||||
writeInt16(m_xAvgCharWidth);
|
||||
writeUInt16(m_usWeightClass);
|
||||
writeUInt16(m_usWidthClass);
|
||||
writeInt16(m_fsType);
|
||||
writeInt16(m_ySubscriptXSize);
|
||||
writeInt16(m_ySubscriptYSize);
|
||||
writeInt16(m_ySubscriptXOffset);
|
||||
writeInt16(m_ySubscriptYOffset);
|
||||
writeInt16(m_ySuperscriptXSize);
|
||||
writeInt16(m_ySuperscriptYSize);
|
||||
writeInt16(m_ySuperscriptXOffset);
|
||||
writeInt16(m_ySuperscriptYOffset);
|
||||
writeInt16(m_yStrikeoutSize);
|
||||
writeInt16(m_yStrikeoutPosition);
|
||||
writeInt16(m_sFamilyClass);
|
||||
|
||||
writePanose();
|
||||
|
||||
writeUInt32(m_ulUnicodeRange1);
|
||||
writeUInt32(m_ulUnicodeRange2);
|
||||
writeUInt32(m_ulUnicodeRange3);
|
||||
writeUInt32(m_ulUnicodeRange4);
|
||||
writeTag(m_vendId);
|
||||
writeUInt16(m_fsSelection);
|
||||
writeUInt16(m_usFirstCharIndex);
|
||||
writeUInt16(m_usLastCharIndex);
|
||||
writeUInt16(m_sTypoAscender);
|
||||
writeUInt16(m_sTypoDescender);
|
||||
writeUInt16(m_sTypoLineGap);
|
||||
writeUInt16(m_usWinAscent);
|
||||
writeUInt16(m_usWinDescent);
|
||||
writeUInt32(m_ulCodePageRange1);
|
||||
writeUInt32(m_ulCodePageRange2);
|
||||
writeInt16(m_sxHeight);
|
||||
writeInt16(m_sCapHeight);
|
||||
writeUInt16(m_usDefaultChar);
|
||||
writeUInt16(m_usBreakChar);
|
||||
writeUInt16(m_usMaxContext);
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
private void writePanose() throws IOException {
|
||||
writeUInt8(0); // family
|
||||
writeUInt8(0); // serif
|
||||
writeUInt8(0); // weight
|
||||
writeUInt8(0); // proportion
|
||||
writeUInt8(0); // contrast
|
||||
writeUInt8(0); // stroke
|
||||
writeUInt8(0); // arm style
|
||||
writeUInt8(0); // letterform
|
||||
writeUInt8(0); // midline
|
||||
writeUInt8(0); // x-height
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "OS/2 ";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* $Id: PostWriter.java,v 1.3 2004/01/11 13:14:45 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class PostWriter extends FontFormatWriter {
|
||||
boolean m_isMonospaced = false;
|
||||
|
||||
public PostWriter() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
// table version number
|
||||
writeFixed32(1.0);
|
||||
writeFixed32(10.0); // italic angle
|
||||
writeFWord(0); // underline pos
|
||||
writeFWord(60); // underline thickness
|
||||
|
||||
if (m_isMonospaced) {
|
||||
writeUInt32(1); // fixed pitch
|
||||
} else {
|
||||
writeUInt32(0);
|
||||
} // if
|
||||
|
||||
// vm memory stuff
|
||||
writeUInt32(0);
|
||||
writeUInt32(0);
|
||||
writeUInt32(0);
|
||||
writeUInt32(0);
|
||||
|
||||
pad();
|
||||
}
|
||||
|
||||
protected String getTag() {
|
||||
return "post";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* $Id: TTCodePage.java,v 1.3 2004/05/16 12:59:07 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.util.*;
|
||||
import java.nio.charset.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class TTCodePage {
|
||||
static public TTCodePage US_ASCII = new TTCodePage("US-ASCII",
|
||||
"US-ASCII",
|
||||
64);
|
||||
static public TTCodePage Latin_1 = new TTCodePage("windows-1252",
|
||||
"Latin 1 windows-1252",
|
||||
0);
|
||||
static private boolean s_isInitialized = false;
|
||||
static private ArrayList<TTCodePage> s_list = new ArrayList<>();
|
||||
|
||||
static public String [] getNames() {
|
||||
initList();
|
||||
String [] retval = new String[s_list.size()];
|
||||
int i;
|
||||
for (i = 0; i < s_list.size(); i++) {
|
||||
TTCodePage codePage = (TTCodePage) s_list.get(i);
|
||||
retval[i] = codePage.getName();
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static public TTCodePage forName(String a_name) {
|
||||
initList();
|
||||
|
||||
TTCodePage retval = null;
|
||||
for (TTCodePage codePage: s_list) {
|
||||
if (codePage.getName().equals(a_name)) {
|
||||
return codePage;
|
||||
}
|
||||
} // for
|
||||
|
||||
for (TTCodePage codePage: s_list) {
|
||||
if (codePage.getCharset() == null) {
|
||||
continue;
|
||||
} // if
|
||||
|
||||
if (codePage.getCharset().name().equals(a_name)) {
|
||||
return codePage;
|
||||
}
|
||||
} // for
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static private void initList() {
|
||||
if (s_isInitialized)
|
||||
return;
|
||||
|
||||
s_isInitialized = true;
|
||||
|
||||
s_list.add(US_ASCII);
|
||||
s_list.add(Latin_1);
|
||||
s_list.add(new TTCodePage("ISO-2022-JP",
|
||||
"Japan-JIS",
|
||||
17));
|
||||
s_list.add(new TTCodePage("windows-1250",
|
||||
"Latin 2: Eastern Europe windows-1250",
|
||||
1));
|
||||
s_list.add(new TTCodePage("windows-1251",
|
||||
"Cyrillic windows-1251",
|
||||
2));
|
||||
s_list.add(new TTCodePage("windows-1253",
|
||||
"Greek windows-1253",
|
||||
3));
|
||||
s_list.add(new TTCodePage("windows-1254",
|
||||
"Turkish windows-1254",
|
||||
4));
|
||||
s_list.add(new TTCodePage("windows-1258",
|
||||
"Vietnamese windows-1258",
|
||||
8));
|
||||
|
||||
|
||||
// extended
|
||||
s_list.add(new TTCodePage("windows-1255",
|
||||
"Hebrew windows-1255",
|
||||
5));
|
||||
s_list.add(new TTCodePage("windows-1256",
|
||||
"Arabic windows-1256",
|
||||
6));
|
||||
s_list.add(new TTCodePage("windows-1257",
|
||||
"Windows Baltic",
|
||||
7));
|
||||
|
||||
// TODO: 16 Thai 874
|
||||
s_list.add(new TTCodePage(
|
||||
"Thai windows-874",
|
||||
16));
|
||||
|
||||
s_list.add(new TTCodePage("x-mswin-936",
|
||||
"Chinese: Simplified",
|
||||
18));
|
||||
|
||||
// TODO: 19 Korean Wansung
|
||||
s_list.add(new TTCodePage(
|
||||
"Korean Wansung",
|
||||
19));
|
||||
|
||||
s_list.add(new TTCodePage("x-windows-950",
|
||||
"Chinese: Traditional",
|
||||
20));
|
||||
}
|
||||
|
||||
|
||||
private String m_name;
|
||||
|
||||
/** http://www.microsoft.com/typography/otspec/os2.htm
|
||||
*/
|
||||
private int m_osTwoFlag = 0;
|
||||
private Charset m_charset = null;
|
||||
|
||||
public TTCodePage(String a_charsetName, String a_name,
|
||||
int a_osTwoFlag)
|
||||
{
|
||||
if (Charset.isSupported(a_charsetName)) {
|
||||
m_charset = Charset.forName(a_charsetName);
|
||||
} // if
|
||||
|
||||
m_name = a_name;
|
||||
m_osTwoFlag = a_osTwoFlag;
|
||||
}
|
||||
|
||||
public TTCodePage(String a_name,
|
||||
int a_osTwoFlag)
|
||||
{
|
||||
m_name = a_name;
|
||||
m_osTwoFlag = a_osTwoFlag;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
public Charset getCharset() {
|
||||
return m_charset;
|
||||
}
|
||||
|
||||
public int getOsTwoFlag() {
|
||||
return m_osTwoFlag;
|
||||
}
|
||||
}
|
||||
391
trunk/libsrc/ttf/src/org/doubletype/ossa/truetype/TTGlyph.java
Normal file
391
trunk/libsrc/ttf/src/org/doubletype/ossa/truetype/TTGlyph.java
Normal file
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* $Copyright: copyright (c) 2003-2008, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class TTGlyph {
|
||||
// --------------------------------------------------------------
|
||||
public static final int k_onCurve = 0x1;
|
||||
|
||||
public static final int ARG_1_AND_2_ARE_WORDS = 0x1;
|
||||
public static final int ARGS_ARE_XY_VALUES = 0x2;
|
||||
public static final int ROUND_XY_TO_GRID = 0x4;
|
||||
public static final int WE_HAVE_A_SCALE = 0x8;
|
||||
// 0x10 is obsolete
|
||||
public static final int MORE_COMPONENTS = 0x20;
|
||||
public static final int WE_HAVE_AN_X_AND_Y_SCALE = 0x40;
|
||||
public static final int WE_HAVE_A_TWO_BY_TWO = 0x80;
|
||||
public static final int WE_HAVE_INSTRUCTIONS = 0x100;
|
||||
public static final int USE_MY_METRICS = 0x200;
|
||||
public static final int OVERLAP_COMPOUND = 0x400;
|
||||
|
||||
/** Move Direct Absolute Point - do not round */
|
||||
public static final int MDAP0 = 0x2E;
|
||||
|
||||
/** Move Direct Absolute Point - round the value */
|
||||
public static final int MDAP1 = 0x2F;
|
||||
|
||||
/** Interpolate Untouched Points through the outline - y-direction */
|
||||
public static final int IUP0 = 0x30;
|
||||
|
||||
/** Interpolate Untouched Points through the outline - x-direction */
|
||||
public static final int IUP1 = 0x31;
|
||||
|
||||
/** push one byte */
|
||||
public static final int PUSHB000 = 0xB0;
|
||||
|
||||
/** push two bytes */
|
||||
public static final int PUSHB001 = 0xB1;
|
||||
|
||||
/** push three bytes */
|
||||
public static final int PUSHB010 = 0xB2;
|
||||
public static final int PUSHB011 = 0xB3;
|
||||
public static final int PUSHB100 = 0xB4;
|
||||
public static final int PUSHB101 = 0xB5;
|
||||
public static final int PUSHB110 = 0xB6;
|
||||
public static final int PUSHB111 = 0xB7;
|
||||
|
||||
/** set vector to y-axis. */
|
||||
public static final int SVTCA0 = 0x00;
|
||||
|
||||
/** set vector to x-axis. */
|
||||
public static final int SVTCA1 = 0x01;
|
||||
public static final int SPVFS = 0x0A; // set projection vector
|
||||
public static final int SFVFS = 0x0B; // set freedom vector
|
||||
public static final int SFVTPV = 0x0E;
|
||||
public static final int DELTAP1 = 0x5D;
|
||||
public static final int DELTAP2 = 0x71;
|
||||
public static final int DELTAP3 = 0x72;
|
||||
|
||||
/** set delta base */
|
||||
public static final int SDB = 0x5E;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* converts double into F2Dot14, 16 bit fixed point format.
|
||||
* @param a_value
|
||||
* @return
|
||||
*/
|
||||
public static int toF2Dot14(double a_value) {
|
||||
int retval = 0;
|
||||
|
||||
if (a_value >= 2.0 || a_value < -2.0) {
|
||||
throw new RuntimeException(Double.toString(a_value) + " out of range");
|
||||
} // if
|
||||
|
||||
int mantissa = (int) Math.floor(a_value);
|
||||
int fraction = (int) Math.floor((a_value - mantissa) * 16384);
|
||||
|
||||
int twoBitPart = mantissa;
|
||||
if (mantissa < 0) {
|
||||
twoBitPart = 4 + mantissa;
|
||||
} // if
|
||||
|
||||
retval = (twoBitPart << 14) | fraction;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static int toDeltaArg(int a_relativePpem, int a_step) {
|
||||
int retval = 0;
|
||||
|
||||
if (a_step < -8 || a_step > 8 || a_step == 0) {
|
||||
throw new RuntimeException("Out of range");
|
||||
} // if
|
||||
|
||||
int selector = 0;
|
||||
if (a_step > 0) {
|
||||
selector = a_step + 7;
|
||||
} else {
|
||||
selector = a_step + 8;
|
||||
} // if
|
||||
|
||||
retval = (a_relativePpem << 4) | (selector);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
private ArrayList<Point> m_points = new ArrayList<>();
|
||||
private ArrayList<Integer> m_endPtsOfContours = new ArrayList<>();
|
||||
private ArrayList<Integer> m_instructions = new ArrayList<>();
|
||||
private ArrayList<Integer> m_flags = new ArrayList<>();
|
||||
private ArrayList<Integer> m_glyfIndeces = new ArrayList<>();
|
||||
private ArrayList<Integer> m_arg1s = new ArrayList<>();
|
||||
private ArrayList<Integer> m_arg2s = new ArrayList<>();
|
||||
|
||||
private boolean m_isSimple = true;
|
||||
private int m_advanceWidth = 512;
|
||||
|
||||
private int m_numOfCompositePoints = 0;
|
||||
private int m_numOfCompositeContours = 0;
|
||||
private int m_componentDepth = 0;
|
||||
|
||||
private Point m_min = null;
|
||||
private Point m_max = null;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
public TTGlyph() {
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
m_isSimple = true;
|
||||
m_points.clear();
|
||||
m_endPtsOfContours.clear();
|
||||
m_instructions.clear();
|
||||
m_flags.clear();
|
||||
m_glyfIndeces.clear();
|
||||
m_arg1s.clear();
|
||||
m_arg2s.clear();
|
||||
m_advanceWidth = 512;
|
||||
}
|
||||
|
||||
public void buildCompound() {
|
||||
init();
|
||||
|
||||
m_isSimple = false;
|
||||
|
||||
addFlag(ARG_1_AND_2_ARE_WORDS
|
||||
| ARGS_ARE_XY_VALUES
|
||||
| ROUND_XY_TO_GRID
|
||||
| MORE_COMPONENTS);
|
||||
addFlag(ARG_1_AND_2_ARE_WORDS
|
||||
| ARGS_ARE_XY_VALUES
|
||||
| ROUND_XY_TO_GRID);
|
||||
|
||||
addGlyfIndex(3);
|
||||
addGlyfIndex(3);
|
||||
|
||||
addArg1(0);
|
||||
addArg2(0);
|
||||
addArg1(0);
|
||||
addArg2(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* add the index of the last point in the contour
|
||||
* @param a_index
|
||||
*/
|
||||
public void addEndPoint(int a_value) {
|
||||
m_endPtsOfContours.add(a_value);
|
||||
}
|
||||
|
||||
public int getNumOfContours() {
|
||||
if (isSimple()) {
|
||||
return m_endPtsOfContours.size();
|
||||
} else {
|
||||
return -1;
|
||||
} // if-else
|
||||
}
|
||||
|
||||
public int getEndPoint(int a_index) {
|
||||
return m_endPtsOfContours.get(a_index);
|
||||
}
|
||||
|
||||
public int getAdvanceWidth() {
|
||||
return m_advanceWidth;
|
||||
}
|
||||
|
||||
public void setAdvanceWidth(int a_value) {
|
||||
m_advanceWidth = a_value;
|
||||
}
|
||||
|
||||
public Point getMax() {
|
||||
if (m_max == null) {
|
||||
m_max = new Point(0, 0);
|
||||
} // if
|
||||
|
||||
return m_max;
|
||||
}
|
||||
|
||||
public Point getMin() {
|
||||
if (m_min == null) {
|
||||
m_min = new Point(0, 0);
|
||||
} // if
|
||||
|
||||
return m_min;
|
||||
}
|
||||
|
||||
public boolean isSimple() {
|
||||
return m_isSimple;
|
||||
}
|
||||
|
||||
public void setSimple(boolean a_isSimple) {
|
||||
m_isSimple = a_isSimple;
|
||||
}
|
||||
|
||||
public void addInstruction(int a_value) {
|
||||
m_instructions.add(a_value);
|
||||
}
|
||||
|
||||
public int getInstruction(int a_index) {
|
||||
return m_instructions.get(a_index);
|
||||
}
|
||||
|
||||
public int getNumOfInstructions() {
|
||||
return m_instructions.size();
|
||||
}
|
||||
|
||||
public void addFlag(int a_value) {
|
||||
m_flags.add(a_value);
|
||||
}
|
||||
|
||||
public int getFlag(int a_index) {
|
||||
return m_flags.get(a_index);
|
||||
}
|
||||
|
||||
public int getNumOfFlags() {
|
||||
return m_flags.size();
|
||||
}
|
||||
|
||||
public void addPoint(Point a_value) {
|
||||
m_points.add(a_value);
|
||||
updateMinMax(a_value);
|
||||
}
|
||||
|
||||
private void updateMinMax(Point a_value) {
|
||||
if (m_max == null) {
|
||||
m_max = new Point(a_value);
|
||||
} // if
|
||||
|
||||
if (m_min == null) {
|
||||
m_min = new Point(a_value);
|
||||
} // if
|
||||
|
||||
if (a_value.x > m_max.x) {
|
||||
m_max.x = a_value.x;
|
||||
} // if
|
||||
|
||||
if (a_value.x < m_min.x) {
|
||||
m_min.x = a_value.x;
|
||||
} // if
|
||||
|
||||
if (a_value.y > m_max.y) {
|
||||
m_max.y = a_value.y;
|
||||
} // if
|
||||
|
||||
if (a_value.y < m_min.y) {
|
||||
m_min.y = a_value.y;
|
||||
} // if
|
||||
}
|
||||
|
||||
public Point getPoint(int a_index) {
|
||||
return m_points.get(a_index);
|
||||
}
|
||||
|
||||
public int getNumOfPoints() {
|
||||
return m_points.size();
|
||||
}
|
||||
|
||||
public int getLastIndex() {
|
||||
return m_points.size() - 1;
|
||||
}
|
||||
|
||||
public void addGlyfIndex(int a_value) {
|
||||
m_glyfIndeces.add(a_value);
|
||||
}
|
||||
|
||||
public int getGlyfIndex(int a_index) {
|
||||
return m_glyfIndeces.get(a_index);
|
||||
}
|
||||
|
||||
public void addArg1(int a_value) {
|
||||
m_arg1s.add(a_value);
|
||||
}
|
||||
|
||||
public int getArg1(int a_index) {
|
||||
return m_arg1s.get(a_index);
|
||||
}
|
||||
|
||||
public void addArg2(int a_value) {
|
||||
m_arg2s.add(a_value);
|
||||
}
|
||||
|
||||
public int getArg2(int a_index) {
|
||||
return m_arg2s.get(a_index);
|
||||
}
|
||||
|
||||
public int getNumOfCompositePoints() {
|
||||
if (isSimple()) {
|
||||
return getNumOfPoints();
|
||||
} else {
|
||||
return m_numOfCompositePoints;
|
||||
}
|
||||
}
|
||||
|
||||
public void setNumOfCompositePoints(int a_value) {
|
||||
m_numOfCompositePoints = a_value;
|
||||
}
|
||||
|
||||
public int getNumOfCompositeContours() {
|
||||
if (isSimple()) {
|
||||
return getNumOfContours();
|
||||
} else {
|
||||
return m_numOfCompositeContours;
|
||||
} // if-else
|
||||
}
|
||||
|
||||
public void setNumOfCompositeContours(int a_value) {
|
||||
m_numOfCompositeContours = a_value;
|
||||
}
|
||||
|
||||
public int getComponentDepth() {
|
||||
if (isSimple()) {
|
||||
return 0;
|
||||
} else {
|
||||
return m_componentDepth;
|
||||
} // if-else
|
||||
}
|
||||
|
||||
public void setComponentDepth(int a_value) {
|
||||
m_componentDepth = a_value;
|
||||
}
|
||||
|
||||
public int getLeftSideBearing() {
|
||||
return getMin().x;
|
||||
}
|
||||
|
||||
public int getRightSideBearing() {
|
||||
return getAdvanceWidth() - getMax().x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* $Id: TTName.java,v 1.2 2005/01/21 05:37:26 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
public class TTName {
|
||||
public static final int k_unicode = 0;
|
||||
public static final int k_unicodeDefaultEncode = 0;
|
||||
|
||||
public static final int k_macintosh = 1;
|
||||
public static final int k_macRomanEncode = 0;
|
||||
public static final int k_macEnglishLang = 0;
|
||||
|
||||
public static final int k_microsoft = 3;
|
||||
public static final int k_winSymbolEncode = 0;
|
||||
public static final int k_winUnicodeEncode = 1;
|
||||
public static final int k_winShiftJisEncode = 2;
|
||||
public static final int k_winEnglishLang = 0x409;
|
||||
private int m_platformId;
|
||||
private int m_encodingId;
|
||||
private int m_languageId;
|
||||
private int m_nameId;
|
||||
private byte m_bytes[];
|
||||
|
||||
public TTName(int a_platformId,
|
||||
int a_encodingId,
|
||||
int a_languageId,
|
||||
int a_nameId,
|
||||
byte a_bytes[]) {
|
||||
m_platformId = a_platformId;
|
||||
m_encodingId = a_encodingId;
|
||||
m_languageId = a_languageId;
|
||||
m_nameId = a_nameId;
|
||||
m_bytes = a_bytes;
|
||||
}
|
||||
|
||||
public int getPlatformId() {
|
||||
return m_platformId;
|
||||
}
|
||||
|
||||
public int getEncodingId() {
|
||||
return m_encodingId;
|
||||
}
|
||||
|
||||
public int getLanguageId() {
|
||||
return m_languageId;
|
||||
}
|
||||
|
||||
public int getNameId() {
|
||||
return m_nameId;
|
||||
}
|
||||
|
||||
// BUGFIX 958996
|
||||
public byte[] getBytes() {
|
||||
return m_bytes;
|
||||
}
|
||||
|
||||
public int getStringLength() {
|
||||
return m_bytes.length;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TTPixelSize {
|
||||
static private int s_em = 1024;
|
||||
static private boolean s_isInitialized = false;
|
||||
static private ArrayList<TTPixelSize> s_list = new ArrayList<>();
|
||||
|
||||
static public int getEm() {
|
||||
return s_em;
|
||||
}
|
||||
|
||||
static public ArrayList<TTPixelSize> getList() {
|
||||
initList();
|
||||
return s_list;
|
||||
}
|
||||
|
||||
static private void initList() {
|
||||
if (s_isInitialized)
|
||||
return;
|
||||
|
||||
s_isInitialized = true;
|
||||
|
||||
// s_list.add(new TTPixelSize(9, "9px: 7pt(96dpi)/9pt(72dpi)"));
|
||||
// s_list.add(new TTPixelSize(10, "10px: 7.5pt(96dpi)/10pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(11, "11px: 8pt(96dpi)/11pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(12, "12px: 9pt(96dpi)/12pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(13, "13px: 10pt(96dpi)/13pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(14, "14px: 10.5pt(96dpi)/14pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(15, "15px: 11pt(96dpi)/15pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(16, "16px: 12pt(96dpi)/16pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(17, "17px: 13pt(96dpi)/17pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(18, "18px: 13.5pt(96dpi)/18pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(19, "19px: 14pt(96dpi)/14pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(20, "20px: 15pt(96dpi)/20pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(21, "21px: 16pt(96dpi)/21pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(22, "22px: 16.5pt(96dpi)/22pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(23, "23px: 17pt(96dpi)/23pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(24, "24px: 18pt(96dpi)/24pt(72dpi)"));
|
||||
s_list.add(new TTPixelSize(27, "27px: 20pt(96dpi)"));
|
||||
s_list.add(new TTPixelSize(29, "29px: 22pt(96dpi)"));
|
||||
s_list.add(new TTPixelSize(32, "32px: 24pt(96dpi)"));
|
||||
s_list.add(new TTPixelSize(33, "33px: 8pt(300dpi) "));
|
||||
// s_list.add(new TTPixelSize(35, "35px: 26pt(96dpi) "));
|
||||
s_list.add(new TTPixelSize(37, "37px: 28pt(96dpi)"));
|
||||
// s_list.add(new TTPixelSize(38, "38px: 9pt(300dpi)");
|
||||
s_list.add(new TTPixelSize(42, "42px: 10pt(300dpi)"));
|
||||
// s_list.add(new TTPixelSize(44, "44px: 10.5pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(46, "46px: 11pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(50, "50px: 12pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(54, "54px: 13pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(58, "58px: 14pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(67, "67px: 16pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(75, "75px: 18pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(83, "83px: 20pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(92, "92px: 22pt(300dpi)"));
|
||||
s_list.add(new TTPixelSize(100, "100px: 24pt(300dpi)"));
|
||||
}
|
||||
|
||||
private int m_pixel;
|
||||
private String m_description;
|
||||
private int m_pixelWidths[];
|
||||
private int m_maxPixelWidth = 0;
|
||||
|
||||
public TTPixelSize(int a_pixel, String a_description)
|
||||
{
|
||||
m_pixel = a_pixel;
|
||||
m_description = a_description;
|
||||
}
|
||||
|
||||
public int getPixel() {
|
||||
return m_pixel;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return m_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the size of the pixel widths. Use num of glyphs.
|
||||
* @param a_size
|
||||
*/
|
||||
public void setPixelWidthsSize(int a_size) {
|
||||
m_pixelWidths = new int[a_size];
|
||||
m_maxPixelWidth = 0;
|
||||
}
|
||||
|
||||
public void setPixelWidth(int a_glyphIndex, int a_value) {
|
||||
m_pixelWidths[a_glyphIndex] = a_value;
|
||||
if (a_value > m_maxPixelWidth) {
|
||||
m_maxPixelWidth = a_value;
|
||||
} // if
|
||||
}
|
||||
|
||||
public int [] getPixelWidths() {
|
||||
return m_pixelWidths;
|
||||
}
|
||||
|
||||
public int getPixelWidth(int a_glyphIndex) {
|
||||
return m_pixelWidths[a_glyphIndex];
|
||||
}
|
||||
|
||||
public int getMaxPixelWidth() {
|
||||
return m_maxPixelWidth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
* $Id: TTUnicodeRange.java,v 1.1 2004/01/25 11:00:10 eed3si9n Exp $
|
||||
*
|
||||
* $Copyright: copyright (c) 2003-2004, e.e d3si9n $
|
||||
* $License:
|
||||
* This source code is part of DoubleType.
|
||||
* DoubleType is a graphical typeface designer.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This Program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, e.e d3si9n gives permission to
|
||||
* link the code of this program with any Java Platform that is available
|
||||
* to public with free of charge, including but not limited to
|
||||
* Sun Microsystem's JAVA(TM) 2 RUNTIME ENVIRONMENT (J2RE),
|
||||
* and distribute linked combinations including the two.
|
||||
* You must obey the GNU General Public License in all respects for all
|
||||
* of the code used other than Java Platform. If you modify this file,
|
||||
* you may extend this exception to your version of the file, but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version.
|
||||
* $
|
||||
*/
|
||||
|
||||
package org.doubletype.ossa.truetype;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.lang.Character.UnicodeBlock;
|
||||
|
||||
/**
|
||||
* @author e.e
|
||||
*/
|
||||
public class TTUnicodeRange implements Comparable {
|
||||
public static final long k_notDef = 0x0001;
|
||||
public static final long k_null = 0x0000;
|
||||
public static final long k_cr = 0x000D;
|
||||
public static final long k_space = 0x0020;
|
||||
|
||||
static private boolean s_isInitialized = false;
|
||||
static private ArrayList<TTUnicodeRange> s_list = new ArrayList<>();
|
||||
static private TTUnicodeRange s_selected = null;
|
||||
|
||||
static public TTUnicodeRange of(long a_unicode) {
|
||||
initList();
|
||||
|
||||
TTUnicodeRange retval = null;
|
||||
UnicodeBlock block = UnicodeBlock.of((int)a_unicode);
|
||||
if (block == null)
|
||||
return retval;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < s_list.size(); i++) {
|
||||
TTUnicodeRange range = s_list.get(i);
|
||||
if (range.m_block.equals(block)) {
|
||||
return range;
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static public TTUnicodeRange getLastFound() {
|
||||
return s_selected;
|
||||
}
|
||||
|
||||
static private void initList() {
|
||||
if (s_isInitialized)
|
||||
return;
|
||||
|
||||
s_isInitialized = true;
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.BASIC_LATIN, 0x0020, 0x007F, 0, 63));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.LATIN_1_SUPPLEMENT, 0x0080, 0x00FF, 1, 0));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.LATIN_EXTENDED_A, 0x0100, 0x017f, 2));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.LATIN_EXTENDED_B, 0x0180, 0x024f, 3));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.IPA_EXTENSIONS, 0x0250, 0x02af, 4));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.SPACING_MODIFIER_LETTERS, 0x02B0, 0x02FF, 5));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.COMBINING_DIACRITICAL_MARKS, 0x0300, 0x036F, 6));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.GREEK, 0x0370, 0x03FF, 7, 3));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CYRILLIC, 0x0400, 0x04FF, 9, 2));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ARMENIAN, 0x0530, 0x058F, 10));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HEBREW, 0x0590, 0x05FF, 11, 5));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ARABIC, 0x0600, 0x06FF, 13, 6));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.SYRIAC, 0x0700, 0x074F, 71));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.THAANA, 0x0780, 0x07BF, 72));
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.DEVANAGARI, 0x0900, 0x097F, 15));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.BENGALI, 0x0980, 0x09FF, 16));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.GURMUKHI, 0x0A00, 0x0A7F, 17));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.GUJARATI, 0x0A80, 0x0AFF, 18));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ORIYA, 0x0B00, 0x0B7F, 19));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.TAMIL, 0x0B80, 0x0BFF, 20));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.TELUGU, 0x0C00, 0x0C7F, 21));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.KANNADA, 0x0C80, 0x0CFF, 22));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.MALAYALAM, 0x0D00, 0x0D7F, 23));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.SINHALA, 0x0D80, 0x0DFF, 73));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.THAI, 0x0E00, 0x0E7F, 24, 16));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.LAO, 0x0E80, 0x0EFF, 25));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.TIBETAN, 0x0F00, 0x0FFF, 70));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.MYANMAR, 0x1000, 0x109F, 74));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.GEORGIAN, 0x10A0, 0x10FF, 26));
|
||||
// TODO: wansung or johab?
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HANGUL_JAMO, 0x1100, 0x11FF, 28, 19));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ETHIOPIC, 0x1200, 0x137F, 75));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CHEROKEE, 0x13A0, 0x13FF, 76));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, 0x1400, 0x167F, 77));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.OGHAM, 0x1680, 0x169F, 78));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.RUNIC, 0x16A0, 0x16FF, 79));
|
||||
|
||||
// TODO: tagalog, hanunoo, buhid, tagbanwa
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.KHMER, 0x1780, 0x17FF, 80));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.MONGOLIAN, 0x1800, 0x18AF, 81));
|
||||
|
||||
// linbu, tai le, khmer symbol, phonetic extensions,
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, 0x1E00, 0x1EFF, 29));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.GREEK_EXTENDED, 0x1F00, 0x1FFF, 30));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.GENERAL_PUNCTUATION, 0x2000, 0x206F, 31));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, 0x2070, 0x209F, 32));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CURRENCY_SYMBOLS, 0x20A0, 0x20CF, 33));
|
||||
|
||||
// combining diacritical marks
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, 0x20D0, 0x20FF, 34));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.LETTERLIKE_SYMBOLS, 0x2100, 0x214F, 35));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.NUMBER_FORMS, 0x2150, 0x218F, 36));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ARROWS, 0x2190, 0x21FF, 37));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.MATHEMATICAL_OPERATORS, 0x2200, 0x22FF, 38));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.MISCELLANEOUS_TECHNICAL, 0x2300, 0x23FF, 39));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CONTROL_PICTURES, 0x2400, 0x243F, 40));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, 0x2440, 0x245F, 41));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ENCLOSED_ALPHANUMERICS, 0x2460, 0x24FF, 42));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.BOX_DRAWING, 0x2500, 0x257F, 43));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.BLOCK_ELEMENTS, 0x2580, 0x259F, 44));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.GEOMETRIC_SHAPES, 0x25A0, 0x25FF, 45));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.MISCELLANEOUS_SYMBOLS, 0x2600, 0x26FF, 46));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.DINGBATS, 0x2700, 0x27BF, 47));
|
||||
|
||||
// TODO: mics. math symbols A, supplemental arrows A
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.BRAILLE_PATTERNS, 0x2800, 0x28FF, 82));
|
||||
|
||||
// TODO: supplemental arrows B, mics. math symbols B,
|
||||
// supplemental math op., mics. symbols and arrows
|
||||
|
||||
|
||||
// CJKV supplements
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CJK_RADICALS_SUPPLEMENT, 0x2E80, 0x2EFF, 59));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.KANGXI_RADICALS, 0x2F00, 0x2FDF, 59));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, 0x2FF0, 0x2FFF, 59));
|
||||
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, 0x3000, 0x303f, 48));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HIRAGANA, 0x3040, 0x309f, 49, 17));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.KATAKANA, 0x30a0, 0x30ff, 50, 17));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.BOPOMOFO, 0x3100, 0x312f, 51));
|
||||
// TODO: wansung or johab?
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, 0x3130, 0x0318F, 52, 19));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.KANBUN, 0x3190, 0x319F, 59));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.BOPOMOFO_EXTENDED, 0x31A0, 0x31BF, 51));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, 0x31F0, 0x31FF, 50, 17));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, 0x3200, 0x32FF, 54));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CJK_COMPATIBILITY, 0x3300, 0x33ff, 55));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, 0x03400, 0x4dbf, 59));
|
||||
// TODO: yijing hex symbols
|
||||
|
||||
// the kanji characters
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, 0x4e00, 0x9fff, 59, 17));
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.YI_SYLLABLES, 0xA000, 0xA48F, 83));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.YI_RADICALS, 0xA490, 0xA4CF, 83));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HANGUL_SYLLABLES, 0xAC00, 0xD7AF, 56));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HIGH_SURROGATES, 0xD800, 0xDB7F, 0));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, 0xDB80, 0xDBFF, 0));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.LOW_SURROGATES, 0xDC00, 0xDFFF, 0));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.PRIVATE_USE_AREA, 0xE000, 0xF8FF, 60));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, 0xf900, 0xfaff, 61));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, 0xFB00, 0xFB4F, 62));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, 0xFB50, 0xFDFF, 62));
|
||||
|
||||
// TODO: variation selectors
|
||||
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.COMBINING_HALF_MARKS, 0xFE20, 0xFE2F, 64));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.CJK_COMPATIBILITY_FORMS, 0xFE30, 0xFE4F, 65));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.SMALL_FORM_VARIANTS, 0xFE50, 0xFE6F, 66));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, 0xFE70, 0xFEFF, 67));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, 0xFF00, 0xFFEF, 68, 17));
|
||||
s_list.add(new TTUnicodeRange(
|
||||
UnicodeBlock.SPECIALS, 0xFFF0, 0xFFFF, 69));
|
||||
}
|
||||
|
||||
static public boolean find(String a_unicodeRange) {
|
||||
initList();
|
||||
|
||||
s_selected = null;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < s_list.size(); i++) {
|
||||
TTUnicodeRange range = (TTUnicodeRange) s_list.get(i);
|
||||
if (range.m_block.toString().equals(a_unicodeRange)) {
|
||||
s_selected = range;
|
||||
|
||||
return true;
|
||||
} // if
|
||||
} // for i
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private UnicodeBlock m_block = null;
|
||||
private long m_start = 0;
|
||||
private long m_end = 0;
|
||||
|
||||
/** http://www.microsoft.com/typography/otspec/os2.htm
|
||||
*/
|
||||
private int m_osTwoFlag = 0;
|
||||
|
||||
/** http://www.microsoft.com/typography/otspec/os2.htm
|
||||
*/
|
||||
private int m_codePageFlag = 0;
|
||||
|
||||
public TTUnicodeRange(UnicodeBlock a_block,
|
||||
long a_start,
|
||||
long a_end,
|
||||
int a_osTwoFlag)
|
||||
{
|
||||
m_block = a_block;
|
||||
m_start = a_start;
|
||||
m_end = a_end;
|
||||
m_osTwoFlag = a_osTwoFlag;
|
||||
}
|
||||
|
||||
public TTUnicodeRange(UnicodeBlock a_block,
|
||||
long a_start,
|
||||
long a_end,
|
||||
int a_osTwoFlag,
|
||||
int a_codePageFlag)
|
||||
{
|
||||
m_block = a_block;
|
||||
m_start = a_start;
|
||||
m_end = a_end;
|
||||
m_osTwoFlag = a_osTwoFlag;
|
||||
m_codePageFlag = a_codePageFlag;
|
||||
}
|
||||
|
||||
public boolean equals(Object a_object) {
|
||||
TTUnicodeRange object = (TTUnicodeRange) a_object;
|
||||
return (m_start == object.m_start);
|
||||
}
|
||||
|
||||
public int compareTo(Object a_object) {
|
||||
TTUnicodeRange object = (TTUnicodeRange) a_object;
|
||||
if (this.m_start < object.m_start) {
|
||||
return -1;
|
||||
} else if (this.m_start == object.m_start) {
|
||||
return 0;
|
||||
} else
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return m_block.toString();
|
||||
}
|
||||
|
||||
public long getStartCode() {
|
||||
return m_start;
|
||||
}
|
||||
|
||||
public long getEndCode() {
|
||||
return m_end;
|
||||
}
|
||||
|
||||
public int getOsTwoFlag() {
|
||||
return m_osTwoFlag;
|
||||
}
|
||||
|
||||
public int getCodeRangeFlag() {
|
||||
return m_codePageFlag;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,394 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
/**
|
||||
* DefaultGlyphFactory is generated by Relaxer based on glyph.rng.
|
||||
*
|
||||
* @version glyph.rng 1.0 (Tue Nov 09 20:22:48 EST 2004)
|
||||
* @author Relaxer 1.1b (http://www.relaxer.org)
|
||||
*/
|
||||
public class DefaultGlyphFactory extends AbstractGlyphFactory {
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XParamListParam</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXParamListParamClass() {
|
||||
return (XParamListParam.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XHeadGlobal</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXHeadGlobalClass() {
|
||||
return (XHeadGlobal.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XHeadLocal</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXHeadLocalClass() {
|
||||
return (XHeadLocal.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XHead</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXHeadClass() {
|
||||
return (XHead.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XGlyphFile</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXGlyphFileClass() {
|
||||
return (XGlyphFile.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XContour</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXContourClass() {
|
||||
return (XContour.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XPoint2d</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXPoint2dClass() {
|
||||
return (XPoint2d.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XInvokePos</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXInvokePosClass() {
|
||||
return (XInvokePos.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XInvokeArg</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXInvokeArgClass() {
|
||||
return (XInvokeArg.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XInvokeVarg</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXInvokeVargClass() {
|
||||
return (XInvokeVarg.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XInvoke</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXInvokeClass() {
|
||||
return (XInvoke.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XInclude</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXIncludeClass() {
|
||||
return (XInclude.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XModule</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXModuleClass() {
|
||||
return (XModule.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XBody</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXBodyClass() {
|
||||
return (XBody.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XStartGlyphElement</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXStartGlyphElementClass() {
|
||||
return (XStartGlyphElement.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XControlPoint</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXControlPointClass() {
|
||||
return (XControlPoint.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XHint</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXHintClass() {
|
||||
return (XHint.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XContourPoint</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXContourPointClass() {
|
||||
return (XContourPoint.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Class of <code>XParamList</code>.
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class getXParamListClass() {
|
||||
return (XParamList.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XParamListParam</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XParamListParam
|
||||
*/
|
||||
public XParamListParam createXParamListParam() {
|
||||
return (new XParamListParam());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XHeadGlobal</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XHeadGlobal
|
||||
*/
|
||||
public XHeadGlobal createXHeadGlobal() {
|
||||
return (new XHeadGlobal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XHeadLocal</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XHeadLocal
|
||||
*/
|
||||
public XHeadLocal createXHeadLocal() {
|
||||
return (new XHeadLocal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XHead</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XHead
|
||||
*/
|
||||
public XHead createXHead() {
|
||||
return (new XHead());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XGlyphFile</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XGlyphFile
|
||||
*/
|
||||
public XGlyphFile createXGlyphFile() {
|
||||
return (new XGlyphFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XContour</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XContour
|
||||
*/
|
||||
public XContour createXContour() {
|
||||
return (new XContour());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XPoint2d</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XPoint2d
|
||||
*/
|
||||
public XPoint2d createXPoint2d() {
|
||||
return (new XPoint2d());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XInvokePos</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XInvokePos
|
||||
*/
|
||||
public XInvokePos createXInvokePos() {
|
||||
return (new XInvokePos());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XInvokeArg</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XInvokeArg
|
||||
*/
|
||||
public XInvokeArg createXInvokeArg() {
|
||||
return (new XInvokeArg());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XInvokeVarg</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XInvokeVarg
|
||||
*/
|
||||
public XInvokeVarg createXInvokeVarg() {
|
||||
return (new XInvokeVarg());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XInvoke</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XInvoke
|
||||
*/
|
||||
public XInvoke createXInvoke() {
|
||||
return (new XInvoke());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XInclude</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XInclude
|
||||
*/
|
||||
public XInclude createXInclude() {
|
||||
return (new XInclude());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XModule</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XModule
|
||||
*/
|
||||
public XModule createXModule() {
|
||||
return (new XModule());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XBody</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XBody
|
||||
*/
|
||||
public XBody createXBody() {
|
||||
return (new XBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XStartGlyphElement</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XStartGlyphElement
|
||||
*/
|
||||
public XStartGlyphElement createXStartGlyphElement() {
|
||||
return (new XStartGlyphElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XControlPoint</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XControlPoint
|
||||
*/
|
||||
public XControlPoint createXControlPoint() {
|
||||
return (new XControlPoint());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XHint</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XHint
|
||||
*/
|
||||
public XHint createXHint() {
|
||||
return (new XHint());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XContourPoint</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XContourPoint
|
||||
*/
|
||||
public XContourPoint createXContourPoint() {
|
||||
return (new XContourPoint());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default <code>XParamList</code>.
|
||||
* This method is a hook method of the AbstractGlyphFactory.
|
||||
*
|
||||
* @return XParamList
|
||||
*/
|
||||
public XParamList createXParamList() {
|
||||
return (new XParamList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
/**
|
||||
* GlyphFactory is generated by Relaxer based on glyph.rng.
|
||||
*
|
||||
* @version glyph.rng 1.0 (Tue Nov 09 20:22:48 EST 2004)
|
||||
* @author Relaxer 1.1b (http://www.relaxer.org)
|
||||
*/
|
||||
public class GlyphFactory {
|
||||
private static IGlyphFactory factory;
|
||||
|
||||
/**
|
||||
* Sets a factory.
|
||||
*
|
||||
* @param newFactory
|
||||
*/
|
||||
public static void setFactory(IGlyphFactory newFactory) {
|
||||
factory = newFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the factory.
|
||||
*
|
||||
* @return IGlyphFactory
|
||||
*/
|
||||
public static IGlyphFactory getFactory() {
|
||||
if (factory == null) {
|
||||
factory = new DefaultGlyphFactory();
|
||||
}
|
||||
return (factory);
|
||||
}
|
||||
}
|
||||
2279
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/IGlyphFactory.java
Normal file
2279
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/IGlyphFactory.java
Normal file
File diff suppressed because it is too large
Load Diff
51
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/IRNode.java
Normal file
51
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/IRNode.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
/**
|
||||
* @version glyph.rng 1.0 (Tue Nov 09 20:22:48 EST 2004)
|
||||
* @author Relaxer 1.1b (http://www.relaxer.org)
|
||||
*/
|
||||
public interface IRNode {
|
||||
/**
|
||||
* Sets parent RNode.
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
void rSetParentRNode(IRNode parent);
|
||||
|
||||
/**
|
||||
* Gets parent RNode.
|
||||
*
|
||||
* @return IRNode
|
||||
*/
|
||||
IRNode rGetParentRNode();
|
||||
|
||||
/**
|
||||
* Gets child RNodes.
|
||||
*
|
||||
* @return IRNode[]
|
||||
*/
|
||||
IRNode[] rGetRNodes();
|
||||
}
|
||||
757
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/RInterleave.java
Normal file
757
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/RInterleave.java
Normal file
@@ -0,0 +1,757 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
import java.util.*;
|
||||
import java.net.URL;
|
||||
import java.math.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
/**
|
||||
* RInterleave
|
||||
*
|
||||
* @since May. 13, 2002
|
||||
* @version Oct. 22, 2003
|
||||
* @author ASAMI, Tomoharu (asami@relaxer.org)
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public final class RInterleave {
|
||||
private RStack rstack_;
|
||||
private List<Entry> entries_ = new ArrayList<>();
|
||||
private Map<Class,Entry> entryByStateClass_ = new HashMap<>();
|
||||
private Map<String,Entry> entryByElementName_ = new HashMap<>();
|
||||
private Boolean isMatch_ = null;
|
||||
|
||||
public RInterleave(RStack rstack) {
|
||||
rstack_ = rstack;
|
||||
}
|
||||
|
||||
public Object getProperty(Class stateClass) {
|
||||
StateClassEntry entry = _getEntryByStateClass(stateClass);
|
||||
return (entry.getObject());
|
||||
}
|
||||
|
||||
public Object[] getPropertyList(Class stateClass) {
|
||||
StateClassEntry entry = _getEntryByStateClass(stateClass);
|
||||
return (entry.getObjects());
|
||||
}
|
||||
|
||||
public String getElementPropertyAsString(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsString(element));
|
||||
}
|
||||
|
||||
public boolean getElementPropertyAsBoolean(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsBoolean(element));
|
||||
}
|
||||
|
||||
public Boolean getElementPropertyAsBooleanObject(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsBooleanObject(element));
|
||||
}
|
||||
|
||||
public byte getElementPropertyAsByte(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (-1);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsByte(element));
|
||||
}
|
||||
|
||||
public Byte getElementPropertyAsByteObject(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsByteObject(element));
|
||||
}
|
||||
|
||||
public short getElementPropertyAsShort(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (-1);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsShort(element));
|
||||
}
|
||||
|
||||
public Short getElementPropertyAsShortObject(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsShortObject(element));
|
||||
}
|
||||
|
||||
public int getElementPropertyAsInt(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (-1);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsInt(element));
|
||||
}
|
||||
|
||||
public Integer getElementPropertyAsIntObject(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsIntObject(element));
|
||||
}
|
||||
|
||||
public long getElementPropertyAsLong(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (-1);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsLong(element));
|
||||
}
|
||||
|
||||
public Long getElementPropertyAsLongObject(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsLongObject(element));
|
||||
}
|
||||
|
||||
public float getElementPropertyAsFloat(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (Float.NaN);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsFloat(element));
|
||||
}
|
||||
|
||||
public Float getElementPropertyAsFloatObject(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsFloatObject(element));
|
||||
}
|
||||
|
||||
public double getElementPropertyAsDouble(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (Double.NaN);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsDouble(element));
|
||||
}
|
||||
|
||||
public Double getElementPropertyAsDoubleObject(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsDoubleObject(element));
|
||||
}
|
||||
|
||||
public BigDecimal getElementPropertyAsBigDecimal(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsBigDecimal(element));
|
||||
}
|
||||
|
||||
public BigInteger getElementPropertyAsBigInteger(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsBigInteger(element));
|
||||
}
|
||||
|
||||
public Date getElementPropertyAsDate(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsDate(element));
|
||||
}
|
||||
|
||||
public Locale getElementPropertyAsLocale(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsLocale(element));
|
||||
}
|
||||
|
||||
public URL getElementPropertyAsURL(String elementName) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsURL(element));
|
||||
}
|
||||
|
||||
public java.sql.Timestamp getElementPropertyAsSQLTimestamp(
|
||||
String elementName
|
||||
) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsSQLTimestamp(element));
|
||||
}
|
||||
|
||||
public java.sql.Time getElementPropertyAsSQLTime(
|
||||
String elementName
|
||||
) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsSQLTime(element));
|
||||
}
|
||||
|
||||
public java.sql.Date getElementPropertyAsSQLDate(
|
||||
String elementName
|
||||
) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsSQLDate(element));
|
||||
}
|
||||
|
||||
public byte[] getElementPropertyAsBinaryBASE64(
|
||||
String elementName
|
||||
) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsBinaryBASE64(element));
|
||||
}
|
||||
|
||||
public byte[] getElementPropertyAsBinaryHEX(
|
||||
String elementName
|
||||
) {
|
||||
Element element = _getElementByElementName(elementName);
|
||||
if (element == null) {
|
||||
return (null);
|
||||
}
|
||||
return (URelaxer.getElementPropertyAsBinaryHEX(element));
|
||||
}
|
||||
|
||||
public List getElementPropertyAsStringList(String elementName) {
|
||||
List list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<String> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsString(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Boolean> getElementPropertyAsBooleanList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Boolean> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsBooleanObject(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Byte> getElementPropertyAsByteList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Byte> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsByteObject(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Short> getElementPropertyAsShortList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Short> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsShortObject(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Integer> getElementPropertyAsIntList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsIntObject(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Long> getElementPropertyAsLongList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Long> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsLongObject(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Float> getElementPropertyAsFloatList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Float> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsFloatObject(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Double> getElementPropertyAsDoubleList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Double> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsDoubleObject(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<BigDecimal> getElementPropertyAsBigDecimalList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<BigDecimal> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsBigDecimal(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<BigInteger> getElementPropertyAsBigIntegerList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<BigInteger> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsBigInteger(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Date> getElementPropertyAsDateList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Date> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsDate(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Locale> getElementPropertyAsLocaleList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Locale> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsLocale(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<URL> getElementPropertyAsURLList(String elementName) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<URL> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsURL(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Timestamp> getElementPropertyAsSQLTimestampList(
|
||||
String elementName
|
||||
) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Timestamp> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsSQLTimestamp(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Time> getElementPropertyAsSQLTimeList(
|
||||
String elementName
|
||||
) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Time> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsSQLTime(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<Date> getElementPropertyAsSQLDateList(
|
||||
String elementName
|
||||
) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<Date> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsSQLDate(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<byte[]> getElementPropertyAsBinaryBASE64List(
|
||||
String elementName
|
||||
) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<byte[]> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsBinaryBASE64(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
public List<byte[]> getElementPropertyAsBinaryHEXList(
|
||||
String elementName
|
||||
) {
|
||||
List<Element> list = _getElementListByElementName(elementName);
|
||||
int size = list.size();
|
||||
List<byte[]> result = new ArrayList<>();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Element element = (Element)list.get(i);
|
||||
result.add(URelaxer.getElementPropertyAsBinaryHEX(element));
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
private StateClassEntry _getEntryByStateClass(Class stateClass) {
|
||||
if (!isMatch()) {
|
||||
throw (new IllegalStateException());
|
||||
}
|
||||
StateClassEntry entry
|
||||
= (StateClassEntry)entryByStateClass_.get(stateClass);
|
||||
if (entry == null) {
|
||||
throw (new IllegalStateException());
|
||||
}
|
||||
return (entry);
|
||||
}
|
||||
|
||||
private ElementNameEntry _getEntryByElementName(String elementName) {
|
||||
if (!isMatch()) {
|
||||
throw (new IllegalStateException());
|
||||
}
|
||||
ElementNameEntry entry
|
||||
= (ElementNameEntry)entryByElementName_.get(elementName);
|
||||
if (entry == null) {
|
||||
throw (new IllegalStateException());
|
||||
}
|
||||
return (entry);
|
||||
}
|
||||
|
||||
private Element _getElementByElementName(String elementName) {
|
||||
ElementNameEntry entry = _getEntryByElementName(elementName);
|
||||
if (entry.elements.size() == 0) {
|
||||
return (null);
|
||||
} else {
|
||||
return ((Element)entry.elements.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
private List<Element> _getElementListByElementName(String elementName) {
|
||||
ElementNameEntry entry = _getEntryByElementName(elementName);
|
||||
return (entry.elements);
|
||||
}
|
||||
|
||||
public void addElementSlot(String elementName, String occurs) {
|
||||
Entry entry = new ElementNameEntry(elementName, occurs);
|
||||
entries_.add(entry);
|
||||
entryByElementName_.put(elementName, entry);
|
||||
}
|
||||
|
||||
public void addElementSlot(Class stateClass, String occurs) {
|
||||
Entry entry = new StateClassEntry(stateClass, occurs);
|
||||
entries_.add(entry);
|
||||
entryByStateClass_.put(stateClass, entry);
|
||||
}
|
||||
|
||||
public void addHedgeSlot(Class stateClass, String occurs) {
|
||||
Entry entry = new StateClassEntry(stateClass, occurs);
|
||||
entries_.add(entry);
|
||||
entryByStateClass_.put(stateClass, entry);
|
||||
}
|
||||
|
||||
public void addAttributeSlot(Class stateClass, String occurs) {
|
||||
Entry entry = new StateClassEntry(stateClass, occurs);
|
||||
entries_.add(entry);
|
||||
entryByStateClass_.put(stateClass, entry);
|
||||
}
|
||||
|
||||
public boolean isMatch() {
|
||||
if (isMatch_ == null) {
|
||||
isMatch_ = new Boolean(_isMatch());
|
||||
}
|
||||
return (isMatch_.booleanValue());
|
||||
}
|
||||
|
||||
private boolean _isMatch() {
|
||||
Entry[] entries = _getEntries();
|
||||
for (;;) {
|
||||
if (!_isMatchHungry(entries)) {
|
||||
if (_isNoMatch(entries)) {
|
||||
return (false);
|
||||
}
|
||||
return (_isStable(entries));
|
||||
}
|
||||
if (_isUnmatch(entries)) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Entry[] _getEntries() {
|
||||
int size = entries_.size();
|
||||
Entry[] entries = new Entry[size];
|
||||
for (int i = 0;i < size;i++) {
|
||||
entries[i] = (Entry)entries_.get(i);
|
||||
}
|
||||
return (entries);
|
||||
}
|
||||
|
||||
private boolean _isNoMatch(Entry[] entries) {
|
||||
for (int i = 0;i < entries.length;i++) {
|
||||
if (entries[i].count > 0) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
private boolean _isStable(Entry[] entries) {
|
||||
for (int i = 0;i < entries.length;i++) {
|
||||
Entry entry = entries[i];
|
||||
switch (entry.occurs) {
|
||||
case "":
|
||||
if (entry.count != 1) {
|
||||
return (false);
|
||||
} break;
|
||||
case "?":
|
||||
break;
|
||||
case "+":
|
||||
if (entry.count == 0) {
|
||||
return (false);
|
||||
} break;
|
||||
case "*":
|
||||
break;
|
||||
default:
|
||||
throw (new InternalError());
|
||||
}
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
private boolean _isUnmatch(Entry[] entries) {
|
||||
for (int i = 0;i < entries.length;i++) {
|
||||
Entry entry = entries[i];
|
||||
switch (entry.occurs) {
|
||||
case "":
|
||||
if (entry.count > 1) {
|
||||
return (true);
|
||||
} break;
|
||||
case "?":
|
||||
if (entry.count > 1) {
|
||||
return (true);
|
||||
} break;
|
||||
case "+":
|
||||
break;
|
||||
case "*":
|
||||
break;
|
||||
default:
|
||||
throw (new InternalError());
|
||||
}
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
private boolean _isMatchHungry(Entry[] entries) {
|
||||
for (int i = 0;i < entries.length;i++) {
|
||||
Entry entry = entries[i];
|
||||
if (entry.isMatchHungry(rstack_)) {
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
static abstract class Entry {
|
||||
public String occurs;
|
||||
public int count = 0;
|
||||
|
||||
protected Entry(String occurs) {
|
||||
this.occurs = occurs;
|
||||
}
|
||||
|
||||
public abstract boolean isMatchHungry(RStack stack);
|
||||
}
|
||||
|
||||
static class StateClassEntry extends Entry {
|
||||
public Class stateClass;
|
||||
public List<RStack> stacks = new ArrayList<>();
|
||||
|
||||
public StateClassEntry(Class stateClass, String occurs) {
|
||||
super(occurs);
|
||||
this.stateClass = stateClass;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean isMatchHungry(RStack stack) {
|
||||
//System.out.println("enter:isMatchHungry [" + stateClass + "] - " + stack);
|
||||
try {
|
||||
RStack backup = stack.makeClone();
|
||||
Method method = stateClass.getMethod(
|
||||
"isMatchHungry",
|
||||
new Class[] { RStack.class }
|
||||
);
|
||||
Boolean result = (Boolean)method.invoke(
|
||||
null,
|
||||
new Object[] { stack }
|
||||
);
|
||||
boolean match = result.booleanValue();
|
||||
if (match) {
|
||||
count++;
|
||||
stacks.add(backup);
|
||||
}
|
||||
//System.out.println("leave:isMatchHungry [" + stateClass + "]- " + stack + " = " + match);
|
||||
return (match);
|
||||
} catch ( NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw (new IllegalArgumentException());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getObject() {
|
||||
if (stacks.size() == 0) {
|
||||
return (null);
|
||||
}
|
||||
RStack stack = (RStack)stacks.get(0);
|
||||
try {
|
||||
Constructor constructor = stateClass.getConstructor(
|
||||
new Class[] { RStack.class }
|
||||
);
|
||||
Object result = constructor.newInstance(
|
||||
new Object[] { stack }
|
||||
);
|
||||
return (result);
|
||||
} catch ( NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw (new IllegalArgumentException());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] getObjects() {
|
||||
int size = stacks.size();
|
||||
Object array = Array.newInstance(stateClass, size);
|
||||
for (int i = 0;i < size;i++) {
|
||||
RStack stack = (RStack)stacks.get(i);
|
||||
try {
|
||||
Constructor constructor = stateClass.getConstructor(
|
||||
new Class[] { RStack.class }
|
||||
);
|
||||
Object result = constructor.newInstance(
|
||||
new Object[] { stack }
|
||||
);
|
||||
Array.set(array, i, result);
|
||||
} catch ( NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw (new IllegalArgumentException());
|
||||
}
|
||||
}
|
||||
return ((Object[])array);
|
||||
}
|
||||
}
|
||||
|
||||
static class ElementNameEntry extends Entry {
|
||||
public String elementName;
|
||||
public List<Element> elements = new ArrayList<>();
|
||||
|
||||
public ElementNameEntry(String elementName, String occurs) {
|
||||
super(occurs);
|
||||
this.elementName = elementName;
|
||||
}
|
||||
|
||||
public boolean isMatch(Element element) {
|
||||
String localName = element.getTagName(); // DOM1
|
||||
int index = localName.indexOf(':');
|
||||
if (index != -1) {
|
||||
localName = localName.substring(index + 1);
|
||||
}
|
||||
return (elementName.equals(localName));
|
||||
}
|
||||
|
||||
public boolean isMatchHungry(RStack stack) {
|
||||
Element element = stack.peekElement();
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
boolean result = isMatch(element);
|
||||
if (result) {
|
||||
stack.popElement();
|
||||
count++;
|
||||
elements.add(element);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
}
|
||||
287
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/RStack.java
Normal file
287
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/RStack.java
Normal file
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
import java.util.*;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
/**
|
||||
* RStack
|
||||
*
|
||||
* @since Mar. 8, 2000
|
||||
* @version May. 22, 2003
|
||||
* @author ASAMI, Tomoharu (asami@relaxer.org)
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public final class RStack {
|
||||
private Element element_;
|
||||
private Object[] children_;
|
||||
// Set<String>
|
||||
// private HashSet consumedAttrs_ = new HashSet();
|
||||
// Set<Attr>
|
||||
private HashSet<Attr> consumedAttrNodes_ = null;
|
||||
// Set<Element>
|
||||
private HashSet<Attr> consumedElementNodes_ = null;
|
||||
// Map<String, String>
|
||||
private HashMap<String,String> pi_ = new HashMap<>();
|
||||
private int index_;
|
||||
// private Element lastPoppedElemnt_ = null;
|
||||
|
||||
protected RStack() {
|
||||
}
|
||||
|
||||
public RStack(Element element) {
|
||||
element_ = element;
|
||||
NodeList nodes = element.getChildNodes();
|
||||
List<Object> list = new ArrayList<>();
|
||||
_makeList(nodes, list);
|
||||
int size = list.size();
|
||||
children_ = new Object[size];
|
||||
children_ = list.toArray(children_);
|
||||
index_ = 0;
|
||||
}
|
||||
|
||||
private void _makeList(NodeList nodes, List<Object> list) {
|
||||
int size = nodes.getLength();
|
||||
StringBuffer buffer = null;
|
||||
for (int i = 0;i < size;i++) {
|
||||
Node node = nodes.item(i);
|
||||
if (node instanceof Element) {
|
||||
if (buffer != null) {
|
||||
list.add(new String(buffer));
|
||||
buffer = null;
|
||||
}
|
||||
list.add(node);
|
||||
} else if (node instanceof Text) {
|
||||
if (buffer == null) {
|
||||
buffer = new StringBuffer();
|
||||
}
|
||||
buffer.append(((Text)node).getData());
|
||||
} else if (node instanceof ProcessingInstruction) {
|
||||
ProcessingInstruction pi = (ProcessingInstruction)node;
|
||||
pi_.put(pi.getTarget(), pi.getData());
|
||||
} else if (node instanceof EntityReference) {
|
||||
_makeList(node.getChildNodes(), list);
|
||||
}
|
||||
}
|
||||
if (buffer != null) {
|
||||
list.add(new String(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
public Element getContextElement() {
|
||||
return (element_);
|
||||
}
|
||||
|
||||
/*
|
||||
public Element getLastPoppedElement() {
|
||||
return (lastPoppedElemnt_);
|
||||
}
|
||||
*/
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (index_ == children_.length);
|
||||
}
|
||||
|
||||
public boolean isEmptyElement() {
|
||||
if (index_ == children_.length) {
|
||||
return (true);
|
||||
}
|
||||
for (int i = index_;i < children_.length;i++) {
|
||||
if (children_[i] instanceof Element) {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
public Object pop() {
|
||||
return (children_[index_++]);
|
||||
}
|
||||
|
||||
public Object peek() {
|
||||
if (index_ == children_.length) {
|
||||
return (null);
|
||||
}
|
||||
return (children_[index_]);
|
||||
}
|
||||
|
||||
public Element popElement() {
|
||||
if (index_ == children_.length) {
|
||||
return (null);
|
||||
}
|
||||
while (index_ < children_.length) {
|
||||
Object node = children_[index_++];
|
||||
if (node instanceof Element) {
|
||||
// lastPoppedElemnt_ = (Element)node;
|
||||
// return (lastPoppedElemnt_);
|
||||
return ((Element)node);
|
||||
}
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
public Element peekElement() {
|
||||
if (index_ == children_.length) {
|
||||
return (null);
|
||||
}
|
||||
for (int i = index_;i < children_.length;i++) {
|
||||
Object node = children_[i];
|
||||
if (node instanceof Element) {
|
||||
return ((Element)node);
|
||||
}
|
||||
}
|
||||
return (null);
|
||||
}
|
||||
|
||||
public Element[] peekElements() {
|
||||
if (index_ == children_.length) {
|
||||
return (null);
|
||||
}
|
||||
List<Element> list = new ArrayList<>();
|
||||
for (int i = index_;i < children_.length;i++) {
|
||||
Object node = children_[i];
|
||||
if (node instanceof Element) {
|
||||
list.add((Element)node);
|
||||
}
|
||||
}
|
||||
Element[] elements = new Element[list.size()];
|
||||
return ((Element[])list.toArray(elements));
|
||||
}
|
||||
|
||||
/*
|
||||
public boolean hasAttributeHungry(String name) {
|
||||
if (isConsumedAttribute(name)) {
|
||||
return (false);
|
||||
}
|
||||
setCosumedAttribute(name);
|
||||
return (URelaxer.hasAttribute(element_, name));
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public boolean isConsumedAttribute(String name) {
|
||||
return (consumedAttrs_.contains(name));
|
||||
}
|
||||
|
||||
public boolean isConsumedAttribute(String uri, String name) {
|
||||
return (consumedAttrs_.contains(uri + "$" + name));
|
||||
}
|
||||
|
||||
public void setConsumedAttribute(String name) {
|
||||
if (isConsumedAttribute(name)) {
|
||||
throw (new InternalError());
|
||||
}
|
||||
consumedAttrs_.add(name);
|
||||
}
|
||||
|
||||
public void setConsumedAttribute(String uri, String name) {
|
||||
String fullname = uri + "$" + name;
|
||||
if (isConsumedAttribute(fullname)) {
|
||||
throw (new InternalError());
|
||||
}
|
||||
consumedAttrs_.add(fullname);
|
||||
}
|
||||
*/
|
||||
|
||||
public Map getPIMap() {
|
||||
return ((Map)pi_.clone());
|
||||
}
|
||||
|
||||
public boolean isConsumedElement(Attr attr) {
|
||||
if (consumedElementNodes_ == null) {
|
||||
return (false);
|
||||
}
|
||||
return (consumedElementNodes_.contains(attr));
|
||||
}
|
||||
|
||||
public void consumeElement(Attr attr) {
|
||||
if (consumedElementNodes_ == null) {
|
||||
consumedElementNodes_ = new HashSet<>();
|
||||
}
|
||||
consumedElementNodes_.add(attr);
|
||||
}
|
||||
|
||||
public boolean isConsumedAttribute(Attr attr) {
|
||||
if (consumedAttrNodes_ == null) {
|
||||
return (false);
|
||||
}
|
||||
return (consumedAttrNodes_.contains(attr));
|
||||
}
|
||||
|
||||
public void consumeAttribute(Attr attr) {
|
||||
if (attr == null) {
|
||||
return;
|
||||
}
|
||||
if (consumedAttrNodes_ == null) {
|
||||
consumedAttrNodes_ = new HashSet<>();
|
||||
}
|
||||
consumedAttrNodes_.add(attr);
|
||||
}
|
||||
|
||||
public void addDirectAttributes(Map<String,String> map) {
|
||||
NamedNodeMap attrs = element_.getAttributes();
|
||||
int size = attrs.getLength();
|
||||
for (int i = 0;i < size;i++) {
|
||||
Attr attr = (Attr)attrs.item(i);
|
||||
if (!isConsumedAttribute(attr)) {
|
||||
map.put(attr.getName(), attr.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public RStack makeClone() {
|
||||
RStack newStack = new RStack();
|
||||
newStack.element_ = element_;
|
||||
newStack.children_ = (Object[])children_.clone();
|
||||
if (consumedAttrNodes_ != null) {
|
||||
newStack.consumedAttrNodes_
|
||||
= (HashSet<Attr>)consumedAttrNodes_.clone();
|
||||
}
|
||||
if (consumedElementNodes_ != null) {
|
||||
newStack.consumedElementNodes_
|
||||
= (HashSet<Attr>)consumedElementNodes_.clone();
|
||||
}
|
||||
newStack.pi_ = (HashMap<String,String>)pi_.clone();
|
||||
newStack.index_ = index_;
|
||||
return (newStack);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("[");
|
||||
if (index_ < children_.length) {
|
||||
Object object = children_[index_];
|
||||
buffer.append(object);
|
||||
for (int i = index_ + 1;i < children_.length;i++) {
|
||||
buffer.append(",");
|
||||
object = children_[i];
|
||||
buffer.append(object);
|
||||
}
|
||||
}
|
||||
buffer.append("]");
|
||||
return (new String(buffer));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Copyright(c) 2000-2004 ASAMI,Tomoharu. All rights reserved.
|
||||
Relaxer Version 1.1b (20040122) by asami@relaxer.org
|
||||
@@ -0,0 +1,2 @@
|
||||
Copyright(c) 2000-2004 ASAMI,Tomoharu. All rights reserved.
|
||||
Relaxer Version 1.1b (20040510) by asami@relaxer.org
|
||||
@@ -0,0 +1,8 @@
|
||||
#Relaxer properties
|
||||
#Sat May 01 17:44:29 EDT 2004
|
||||
java.pattern.composite=true
|
||||
java.pattern.factory=true
|
||||
java.jaxp=true
|
||||
java.package=org.doubletype.ossa.xml
|
||||
relaxer.eclipse=true
|
||||
java.name.class.prefix=X
|
||||
1018
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/UJAXP.java
Normal file
1018
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/UJAXP.java
Normal file
File diff suppressed because it is too large
Load Diff
8791
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/URelaxer.java
Normal file
8791
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/URelaxer.java
Normal file
File diff suppressed because it is too large
Load Diff
1193
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XBody.java
Normal file
1193
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XBody.java
Normal file
File diff suppressed because it is too large
Load Diff
758
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XContour.java
Normal file
758
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XContour.java
Normal file
@@ -0,0 +1,758 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import javax.xml.parsers.*;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
/**
|
||||
* <b>XContour</b> is generated from glyph.rng by Relaxer.
|
||||
* This class is derived from:
|
||||
*
|
||||
* <!-- for programmer
|
||||
* <element name="contour" ns="http://doubletype.org/ns/glyph/0.0">
|
||||
* <optional>
|
||||
* <attribute name="type"/>
|
||||
* </optional>
|
||||
* <oneOrMore>
|
||||
* <ref name="contourPoint"/>
|
||||
* </oneOrMore>
|
||||
* </element>-->
|
||||
* <!-- for javadoc -->
|
||||
* <pre> <element name="contour" ns="http://doubletype.org/ns/glyph/0.0">
|
||||
* <optional>
|
||||
* <attribute name="type"/>
|
||||
* </optional>
|
||||
* <oneOrMore>
|
||||
* <ref name="contourPoint"/>
|
||||
* </oneOrMore>
|
||||
* </element></pre>
|
||||
*
|
||||
* @version glyph.rng (Tue Nov 09 20:22:48 EST 2004)
|
||||
* @author Relaxer 1.1b (http://www.relaxer.org)
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class XContour implements java.io.Serializable, Cloneable, IRNode {
|
||||
private String type_;
|
||||
// List<XContourPoint>
|
||||
private java.util.List<XContourPoint> contourPoint_ = new java.util.ArrayList<>();
|
||||
private IRNode parentRNode_;
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code>.
|
||||
*
|
||||
*/
|
||||
public XContour() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code>.
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public XContour(XContour source) {
|
||||
setup(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the Stack <code>stack</code>
|
||||
* that contains Elements.
|
||||
* This constructor is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
*/
|
||||
public XContour(RStack stack) {
|
||||
setup(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the Document <code>doc</code>.
|
||||
*
|
||||
* @param doc
|
||||
*/
|
||||
public XContour(Document doc) {
|
||||
setup(doc.getDocumentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the Element <code>element</code>.
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public XContour(Element element) {
|
||||
setup(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the File <code>file</code>.
|
||||
*
|
||||
* @param file
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XContour(File file) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code>
|
||||
* by the String representation of URI <code>uri</code>.
|
||||
*
|
||||
* @param uri
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XContour(String uri) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the URL <code>url</code>.
|
||||
*
|
||||
* @param url
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XContour(URL url) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the InputStream <code>in</code>.
|
||||
*
|
||||
* @param in
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XContour(InputStream in) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the InputSource <code>is</code>.
|
||||
*
|
||||
* @param is
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XContour(InputSource is) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XContour</code> by the Reader <code>reader</code>.
|
||||
*
|
||||
* @param reader
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XContour(Reader reader) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the XContour <code>source</code>.
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public void setup(XContour source) {
|
||||
int size;
|
||||
type_ = source.type_;
|
||||
this.contourPoint_.clear();
|
||||
size = source.contourPoint_.size();
|
||||
for (int i = 0;i < size;i++) {
|
||||
addContourPoint((XContourPoint)source.getContourPoint(i).clone());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the Document <code>doc</code>.
|
||||
*
|
||||
* @param doc
|
||||
*/
|
||||
public void setup(Document doc) {
|
||||
setup(doc.getDocumentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the Element <code>element</code>.
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public void setup(Element element) {
|
||||
init(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the Stack <code>stack</code>
|
||||
* that contains Elements.
|
||||
* This constructor is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
*/
|
||||
public void setup(RStack stack) {
|
||||
init(stack.popElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
*/
|
||||
private void init(Element element) {
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
RStack stack = new RStack(element);
|
||||
type_ = URelaxer.getAttributePropertyAsString(element, "type");
|
||||
contourPoint_.clear();
|
||||
while (true) {
|
||||
if (XContourPoint.isMatch(stack)) {
|
||||
addContourPoint(factory.createXContourPoint(stack));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Object
|
||||
*/
|
||||
public Object clone() {
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
return (factory.createXContour((XContour)this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DOM representation of the object.
|
||||
* Result is appended to the Node <code>parent</code>.
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
public void makeElement(Node parent) {
|
||||
Document doc;
|
||||
if (parent instanceof Document) {
|
||||
doc = (Document)parent;
|
||||
} else {
|
||||
doc = parent.getOwnerDocument();
|
||||
}
|
||||
Element element = doc.createElement("contour");
|
||||
int size;
|
||||
if (this.type_ != null) {
|
||||
URelaxer.setAttributePropertyByString(element, "type", this.type_);
|
||||
}
|
||||
size = this.contourPoint_.size();
|
||||
for (int i = 0;i < size;i++) {
|
||||
XContourPoint value = (XContourPoint)this.contourPoint_.get(i);
|
||||
value.makeElement(element);
|
||||
}
|
||||
parent.appendChild(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the File <code>file</code>.
|
||||
*
|
||||
* @param file
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(File file) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(file.toURI().toURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code>
|
||||
* by the String representation of URI <code>uri</code>.
|
||||
*
|
||||
* @param uri
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(String uri) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(uri, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the URL <code>url</code>.
|
||||
*
|
||||
* @param url
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(URL url) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(url, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the InputStream <code>in</code>.
|
||||
*
|
||||
* @param in
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(InputStream in) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(in, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the InputSource <code>is</code>.
|
||||
*
|
||||
* @param is
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(InputSource is) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(is, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XContour</code> by the Reader <code>reader</code>.
|
||||
*
|
||||
* @param reader
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(Reader reader) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(reader, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DOM document representation of the object.
|
||||
*
|
||||
* @exception ParserConfigurationException
|
||||
* @return Document
|
||||
*/
|
||||
public Document makeDocument() throws ParserConfigurationException {
|
||||
Document doc = UJAXP.makeDocument();
|
||||
makeElement(doc);
|
||||
return (doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the String property <b>type</b>.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getType() {
|
||||
return (type_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the String property <b>type</b>.
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type_ = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @return XContourPoint[]
|
||||
*/
|
||||
public XContourPoint[] getContourPoint() {
|
||||
XContourPoint[] array = new XContourPoint[contourPoint_.size()];
|
||||
return ((XContourPoint[])contourPoint_.toArray(array));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void setContourPoint(XContourPoint[] contourPoint) {
|
||||
this.contourPoint_.clear();
|
||||
for (int i = 0;i < contourPoint.length;i++) {
|
||||
addContourPoint(contourPoint[i]);
|
||||
}
|
||||
for (int i = 0;i < contourPoint.length;i++) {
|
||||
contourPoint[i].rSetParentRNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void setContourPoint(XContourPoint contourPoint) {
|
||||
this.contourPoint_.clear();
|
||||
addContourPoint(contourPoint);
|
||||
if (contourPoint != null) {
|
||||
contourPoint.rSetParentRNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void addContourPoint(XContourPoint contourPoint) {
|
||||
this.contourPoint_.add(contourPoint);
|
||||
if (contourPoint != null) {
|
||||
contourPoint.rSetParentRNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void addContourPoint(XContourPoint[] contourPoint) {
|
||||
for (int i = 0;i < contourPoint.length;i++) {
|
||||
addContourPoint(contourPoint[i]);
|
||||
}
|
||||
for (int i = 0;i < contourPoint.length;i++) {
|
||||
contourPoint[i].rSetParentRNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int sizeContourPoint() {
|
||||
return (contourPoint_.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the XContourPoint property <b>contourPoint</b> by index.
|
||||
*
|
||||
* @param index
|
||||
* @return XContourPoint
|
||||
*/
|
||||
public XContourPoint getContourPoint(int index) {
|
||||
return ((XContourPoint)contourPoint_.get(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the XContourPoint property <b>contourPoint</b> by index.
|
||||
*
|
||||
* @param index
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void setContourPoint(int index, XContourPoint contourPoint) {
|
||||
this.contourPoint_.set(index, contourPoint);
|
||||
if (contourPoint != null) {
|
||||
contourPoint.rSetParentRNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the XContourPoint property <b>contourPoint</b> by index.
|
||||
*
|
||||
* @param index
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void addContourPoint(int index, XContourPoint contourPoint) {
|
||||
this.contourPoint_.add(index, contourPoint);
|
||||
if (contourPoint != null) {
|
||||
contourPoint.rSetParentRNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the XContourPoint property <b>contourPoint</b> by index.
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void removeContourPoint(int index) {
|
||||
this.contourPoint_.remove(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the XContourPoint property <b>contourPoint</b> by object.
|
||||
*
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void removeContourPoint(XContourPoint contourPoint) {
|
||||
this.contourPoint_.remove(contourPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
*/
|
||||
public void clearContourPoint() {
|
||||
this.contourPoint_.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String makeTextDocument() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
makeTextElement(buffer);
|
||||
return (new String(buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextElement(StringBuffer buffer) {
|
||||
int size;
|
||||
buffer.append("<contour");
|
||||
if (type_ != null) {
|
||||
buffer.append(" type=\"");
|
||||
buffer.append(URelaxer.escapeAttrQuot(URelaxer.getString(getType())));
|
||||
buffer.append("\"");
|
||||
}
|
||||
buffer.append(">");
|
||||
size = this.contourPoint_.size();
|
||||
for (int i = 0;i < size;i++) {
|
||||
XContourPoint value = (XContourPoint)this.contourPoint_.get(i);
|
||||
value.makeTextElement(buffer);
|
||||
}
|
||||
buffer.append("</contour>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
* @exception IOException
|
||||
*/
|
||||
public void makeTextElement(Writer buffer) throws IOException {
|
||||
int size;
|
||||
buffer.write("<contour");
|
||||
if (type_ != null) {
|
||||
buffer.write(" type=\"");
|
||||
buffer.write(URelaxer.escapeAttrQuot(URelaxer.getString(getType())));
|
||||
buffer.write("\"");
|
||||
}
|
||||
buffer.write(">");
|
||||
size = this.contourPoint_.size();
|
||||
for (int i = 0;i < size;i++) {
|
||||
XContourPoint value = (XContourPoint)this.contourPoint_.get(i);
|
||||
value.makeTextElement(buffer);
|
||||
}
|
||||
buffer.write("</contour>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextElement(PrintWriter buffer) {
|
||||
int size;
|
||||
buffer.print("<contour");
|
||||
if (type_ != null) {
|
||||
buffer.print(" type=\"");
|
||||
buffer.print(URelaxer.escapeAttrQuot(URelaxer.getString(getType())));
|
||||
buffer.print("\"");
|
||||
}
|
||||
buffer.print(">");
|
||||
size = this.contourPoint_.size();
|
||||
for (int i = 0;i < size;i++) {
|
||||
XContourPoint value = (XContourPoint)this.contourPoint_.get(i);
|
||||
value.makeTextElement(buffer);
|
||||
}
|
||||
buffer.print("</contour>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextAttribute(StringBuffer buffer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
* @exception IOException
|
||||
*/
|
||||
public void makeTextAttribute(Writer buffer) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextAttribute(PrintWriter buffer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property value as String.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getTypeAsString() {
|
||||
return (URelaxer.getString(getType()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value by String.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void setTypeByString(String string) {
|
||||
setType(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of this object.
|
||||
* While this method informs as XML format representaion,
|
||||
* it's purpose is just information, not making
|
||||
* a rigid XML documentation.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toString() {
|
||||
try {
|
||||
return (makeTextDocument());
|
||||
} catch (Exception e) {
|
||||
return (super.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the IRNode property <b>parentRNode</b>.
|
||||
*
|
||||
* @return IRNode
|
||||
*/
|
||||
public IRNode rGetParentRNode() {
|
||||
return (parentRNode_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the IRNode property <b>parentRNode</b>.
|
||||
*
|
||||
* @param parentRNode
|
||||
*/
|
||||
public void rSetParentRNode(IRNode parentRNode) {
|
||||
this.parentRNode_ = parentRNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets child RNodes.
|
||||
*
|
||||
* @return IRNode[]
|
||||
*/
|
||||
public IRNode[] rGetRNodes() {
|
||||
java.util.List<IRNode> classNodes = new java.util.ArrayList<>();
|
||||
classNodes.addAll(contourPoint_);
|
||||
IRNode[] nodes = new IRNode[classNodes.size()];
|
||||
return ((IRNode[])classNodes.toArray(nodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a Element <code>element</code> is valid
|
||||
* for the <code>XContour</code>.
|
||||
*
|
||||
* @param element
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatch(Element element) {
|
||||
if (!URelaxer.isTargetElement(element, "contour")) {
|
||||
return (false);
|
||||
}
|
||||
RStack target = new RStack(element);
|
||||
boolean $match$ = false;
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
Element child;
|
||||
if (!XContourPoint.isMatchHungry(target)) {
|
||||
return (false);
|
||||
}
|
||||
$match$ = true;
|
||||
while (true) {
|
||||
if (!XContourPoint.isMatchHungry(target)) {
|
||||
break;
|
||||
}
|
||||
$match$ = true;
|
||||
}
|
||||
if (!target.isEmptyElement()) {
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if elements contained in a Stack <code>stack</code>
|
||||
* is valid for the <code>XContour</code>.
|
||||
* This mehtod is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatch(RStack stack) {
|
||||
Element element = stack.peekElement();
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
return (isMatch(element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if elements contained in a Stack <code>stack</code>
|
||||
* is valid for the <code>XContour</code>.
|
||||
* This method consumes the stack contents during matching operation.
|
||||
* This mehtod is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatchHungry(RStack stack) {
|
||||
Element element = stack.peekElement();
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
if (isMatch(element)) {
|
||||
stack.popElement();
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
1014
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XContourPoint.java
Normal file
1014
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XContourPoint.java
Normal file
File diff suppressed because it is too large
Load Diff
665
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XControlPoint.java
Normal file
665
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XControlPoint.java
Normal file
@@ -0,0 +1,665 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import javax.xml.parsers.*;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
/**
|
||||
* <b>XControlPoint</b> is generated from glyph.rng by Relaxer.
|
||||
* This class is derived from:
|
||||
*
|
||||
* <!-- for programmer
|
||||
* <element name="controlPoint" ns="http://doubletype.org/ns/glyph/0.0">
|
||||
* <attribute name="first">
|
||||
* <data type="boolean"/>
|
||||
* </attribute>
|
||||
* <attribute name="smooth">
|
||||
* <data type="boolean"/>
|
||||
* </attribute>
|
||||
* <ref name="contourPoint"/>
|
||||
* </element>-->
|
||||
* <!-- for javadoc -->
|
||||
* <pre> <element name="controlPoint" ns="http://doubletype.org/ns/glyph/0.0">
|
||||
* <attribute name="first">
|
||||
* <data type="boolean"/>
|
||||
* </attribute>
|
||||
* <attribute name="smooth">
|
||||
* <data type="boolean"/>
|
||||
* </attribute>
|
||||
* <ref name="contourPoint"/>
|
||||
* </element></pre>
|
||||
*
|
||||
* @version glyph.rng (Tue Nov 09 20:22:48 EST 2004)
|
||||
* @author Relaxer 1.1b (http://www.relaxer.org)
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class XControlPoint implements java.io.Serializable, Cloneable, IRNode {
|
||||
private boolean first_;
|
||||
private boolean smooth_;
|
||||
private XContourPoint contourPoint_;
|
||||
private IRNode parentRNode_;
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code>.
|
||||
*
|
||||
*/
|
||||
public XControlPoint() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code>.
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public XControlPoint(XControlPoint source) {
|
||||
setup(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the Stack <code>stack</code>
|
||||
* that contains Elements.
|
||||
* This constructor is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
*/
|
||||
public XControlPoint(RStack stack) {
|
||||
setup(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the Document <code>doc</code>.
|
||||
*
|
||||
* @param doc
|
||||
*/
|
||||
public XControlPoint(Document doc) {
|
||||
setup(doc.getDocumentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the Element <code>element</code>.
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public XControlPoint(Element element) {
|
||||
setup(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the File <code>file</code>.
|
||||
*
|
||||
* @param file
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XControlPoint(File file) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code>
|
||||
* by the String representation of URI <code>uri</code>.
|
||||
*
|
||||
* @param uri
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XControlPoint(String uri) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the URL <code>url</code>.
|
||||
*
|
||||
* @param url
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XControlPoint(URL url) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the InputStream <code>in</code>.
|
||||
*
|
||||
* @param in
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XControlPoint(InputStream in) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the InputSource <code>is</code>.
|
||||
*
|
||||
* @param is
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XControlPoint(InputSource is) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XControlPoint</code> by the Reader <code>reader</code>.
|
||||
*
|
||||
* @param reader
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XControlPoint(Reader reader) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the XControlPoint <code>source</code>.
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public void setup(XControlPoint source) {
|
||||
int size;
|
||||
first_ = source.first_;
|
||||
smooth_ = source.smooth_;
|
||||
if (source.contourPoint_ != null) {
|
||||
setContourPoint((XContourPoint)source.getContourPoint().clone());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the Document <code>doc</code>.
|
||||
*
|
||||
* @param doc
|
||||
*/
|
||||
public void setup(Document doc) {
|
||||
setup(doc.getDocumentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the Element <code>element</code>.
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public void setup(Element element) {
|
||||
init(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the Stack <code>stack</code>
|
||||
* that contains Elements.
|
||||
* This constructor is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
*/
|
||||
public void setup(RStack stack) {
|
||||
init(stack.popElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
*/
|
||||
private void init(Element element) {
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
RStack stack = new RStack(element);
|
||||
first_ = URelaxer.getAttributePropertyAsBoolean(element, "first");
|
||||
smooth_ = URelaxer.getAttributePropertyAsBoolean(element, "smooth");
|
||||
setContourPoint(factory.createXContourPoint(stack));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Object
|
||||
*/
|
||||
public Object clone() {
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
return (factory.createXControlPoint((XControlPoint)this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DOM representation of the object.
|
||||
* Result is appended to the Node <code>parent</code>.
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
public void makeElement(Node parent) {
|
||||
Document doc;
|
||||
if (parent instanceof Document) {
|
||||
doc = (Document)parent;
|
||||
} else {
|
||||
doc = parent.getOwnerDocument();
|
||||
}
|
||||
Element element = doc.createElement("controlPoint");
|
||||
int size;
|
||||
URelaxer.setAttributePropertyByBoolean(element, "first", this.first_);
|
||||
URelaxer.setAttributePropertyByBoolean(element, "smooth", this.smooth_);
|
||||
this.contourPoint_.makeElement(element);
|
||||
parent.appendChild(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the File <code>file</code>.
|
||||
*
|
||||
* @param file
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(File file) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(file.toURI().toURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code>
|
||||
* by the String representation of URI <code>uri</code>.
|
||||
*
|
||||
* @param uri
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(String uri) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(uri, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the URL <code>url</code>.
|
||||
*
|
||||
* @param url
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(URL url) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(url, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the InputStream <code>in</code>.
|
||||
*
|
||||
* @param in
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(InputStream in) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(in, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the InputSource <code>is</code>.
|
||||
*
|
||||
* @param is
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(InputSource is) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(is, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XControlPoint</code> by the Reader <code>reader</code>.
|
||||
*
|
||||
* @param reader
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(Reader reader) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(reader, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DOM document representation of the object.
|
||||
*
|
||||
* @exception ParserConfigurationException
|
||||
* @return Document
|
||||
*/
|
||||
public Document makeDocument() throws ParserConfigurationException {
|
||||
Document doc = UJAXP.makeDocument();
|
||||
makeElement(doc);
|
||||
return (doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the boolean property <b>first</b>.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean getFirst() {
|
||||
return (first_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boolean property <b>first</b>.
|
||||
*
|
||||
* @param first
|
||||
*/
|
||||
public void setFirst(boolean first) {
|
||||
this.first_ = first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the boolean property <b>smooth</b>.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean getSmooth() {
|
||||
return (smooth_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the boolean property <b>smooth</b>.
|
||||
*
|
||||
* @param smooth
|
||||
*/
|
||||
public void setSmooth(boolean smooth) {
|
||||
this.smooth_ = smooth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @return XContourPoint
|
||||
*/
|
||||
public XContourPoint getContourPoint() {
|
||||
return (contourPoint_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the XContourPoint property <b>contourPoint</b>.
|
||||
*
|
||||
* @param contourPoint
|
||||
*/
|
||||
public void setContourPoint(XContourPoint contourPoint) {
|
||||
this.contourPoint_ = contourPoint;
|
||||
if (contourPoint != null) {
|
||||
contourPoint.rSetParentRNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String makeTextDocument() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
makeTextElement(buffer);
|
||||
return (new String(buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextElement(StringBuffer buffer) {
|
||||
int size;
|
||||
buffer.append("<controlPoint");
|
||||
buffer.append(" first=\"");
|
||||
buffer.append(URelaxer.getString(getFirst()));
|
||||
buffer.append("\"");
|
||||
buffer.append(" smooth=\"");
|
||||
buffer.append(URelaxer.getString(getSmooth()));
|
||||
buffer.append("\"");
|
||||
buffer.append(">");
|
||||
contourPoint_.makeTextElement(buffer);
|
||||
buffer.append("</controlPoint>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
* @exception IOException
|
||||
*/
|
||||
public void makeTextElement(Writer buffer) throws IOException {
|
||||
int size;
|
||||
buffer.write("<controlPoint");
|
||||
buffer.write(" first=\"");
|
||||
buffer.write(URelaxer.getString(getFirst()));
|
||||
buffer.write("\"");
|
||||
buffer.write(" smooth=\"");
|
||||
buffer.write(URelaxer.getString(getSmooth()));
|
||||
buffer.write("\"");
|
||||
buffer.write(">");
|
||||
contourPoint_.makeTextElement(buffer);
|
||||
buffer.write("</controlPoint>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextElement(PrintWriter buffer) {
|
||||
int size;
|
||||
buffer.print("<controlPoint");
|
||||
buffer.print(" first=\"");
|
||||
buffer.print(URelaxer.getString(getFirst()));
|
||||
buffer.print("\"");
|
||||
buffer.print(" smooth=\"");
|
||||
buffer.print(URelaxer.getString(getSmooth()));
|
||||
buffer.print("\"");
|
||||
buffer.print(">");
|
||||
contourPoint_.makeTextElement(buffer);
|
||||
buffer.print("</controlPoint>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextAttribute(StringBuffer buffer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
* @exception IOException
|
||||
*/
|
||||
public void makeTextAttribute(Writer buffer) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextAttribute(PrintWriter buffer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property value as String.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getFirstAsString() {
|
||||
return (URelaxer.getString(getFirst()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property value as String.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getSmoothAsString() {
|
||||
return (URelaxer.getString(getSmooth()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value by String.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void setFirstByString(String string) {
|
||||
setFirst(new Boolean(string).booleanValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value by String.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void setSmoothByString(String string) {
|
||||
setSmooth(new Boolean(string).booleanValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of this object.
|
||||
* While this method informs as XML format representaion,
|
||||
* it's purpose is just information, not making
|
||||
* a rigid XML documentation.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toString() {
|
||||
try {
|
||||
return (makeTextDocument());
|
||||
} catch (Exception e) {
|
||||
return (super.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the IRNode property <b>parentRNode</b>.
|
||||
*
|
||||
* @return IRNode
|
||||
*/
|
||||
public IRNode rGetParentRNode() {
|
||||
return (parentRNode_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the IRNode property <b>parentRNode</b>.
|
||||
*
|
||||
* @param parentRNode
|
||||
*/
|
||||
public void rSetParentRNode(IRNode parentRNode) {
|
||||
this.parentRNode_ = parentRNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets child RNodes.
|
||||
*
|
||||
* @return IRNode[]
|
||||
*/
|
||||
public IRNode[] rGetRNodes() {
|
||||
java.util.List<IRNode> classNodes = new java.util.ArrayList<>();
|
||||
if (contourPoint_ != null) {
|
||||
classNodes.add(contourPoint_);
|
||||
}
|
||||
IRNode[] nodes = new IRNode[classNodes.size()];
|
||||
return ((IRNode[])classNodes.toArray(nodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a Element <code>element</code> is valid
|
||||
* for the <code>XControlPoint</code>.
|
||||
*
|
||||
* @param element
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatch(Element element) {
|
||||
if (!URelaxer.isTargetElement(element, "controlPoint")) {
|
||||
return (false);
|
||||
}
|
||||
RStack target = new RStack(element);
|
||||
boolean $match$ = false;
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
Element child;
|
||||
if (!URelaxer.hasAttributeHungry(target, "first")) {
|
||||
return (false);
|
||||
}
|
||||
$match$ = true;
|
||||
if (!URelaxer.hasAttributeHungry(target, "smooth")) {
|
||||
return (false);
|
||||
}
|
||||
$match$ = true;
|
||||
if (!XContourPoint.isMatchHungry(target)) {
|
||||
return (false);
|
||||
}
|
||||
$match$ = true;
|
||||
if (!target.isEmptyElement()) {
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if elements contained in a Stack <code>stack</code>
|
||||
* is valid for the <code>XControlPoint</code>.
|
||||
* This mehtod is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatch(RStack stack) {
|
||||
Element element = stack.peekElement();
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
return (isMatch(element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if elements contained in a Stack <code>stack</code>
|
||||
* is valid for the <code>XControlPoint</code>.
|
||||
* This method consumes the stack contents during matching operation.
|
||||
* This mehtod is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatchHungry(RStack stack) {
|
||||
Element element = stack.peekElement();
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
if (isMatch(element)) {
|
||||
stack.popElement();
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
631
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XGlyphFile.java
Normal file
631
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XGlyphFile.java
Normal file
@@ -0,0 +1,631 @@
|
||||
/*
|
||||
* The Relaxer artifact
|
||||
* Copyright (c) 2000-2004, ASAMI Tomoharu, All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.doubletype.ossa.xml;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import javax.xml.parsers.*;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
/**
|
||||
* <b>XGlyphFile</b> is generated from glyph.rng by Relaxer.
|
||||
* This class is derived from:
|
||||
*
|
||||
* <!-- for programmer
|
||||
* <element name="glyphFile" ns="http://doubletype.org/ns/glyph/0.0">
|
||||
* <attribute name="href"/>
|
||||
* <attribute name="unicode">
|
||||
* <data type="long"/>
|
||||
* </attribute>
|
||||
* </element>-->
|
||||
* <!-- for javadoc -->
|
||||
* <pre> <element name="glyphFile" ns="http://doubletype.org/ns/glyph/0.0">
|
||||
* <attribute name="href"/>
|
||||
* <attribute name="unicode">
|
||||
* <data type="long"/>
|
||||
* </attribute>
|
||||
* </element></pre>
|
||||
*
|
||||
* @version glyph.rng (Tue Nov 09 20:22:48 EST 2004)
|
||||
* @author Relaxer 1.1b (http://www.relaxer.org)
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class XGlyphFile implements java.io.Serializable, Cloneable, IRNode {
|
||||
private String href_;
|
||||
private long unicode_;
|
||||
private IRNode parentRNode_;
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code>.
|
||||
*
|
||||
*/
|
||||
public XGlyphFile() {
|
||||
href_ = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code>.
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public XGlyphFile(XGlyphFile source) {
|
||||
setup(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the Stack <code>stack</code>
|
||||
* that contains Elements.
|
||||
* This constructor is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
*/
|
||||
public XGlyphFile(RStack stack) {
|
||||
setup(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the Document <code>doc</code>.
|
||||
*
|
||||
* @param doc
|
||||
*/
|
||||
public XGlyphFile(Document doc) {
|
||||
setup(doc.getDocumentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the Element <code>element</code>.
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public XGlyphFile(Element element) {
|
||||
setup(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the File <code>file</code>.
|
||||
*
|
||||
* @param file
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XGlyphFile(File file) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code>
|
||||
* by the String representation of URI <code>uri</code>.
|
||||
*
|
||||
* @param uri
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XGlyphFile(String uri) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the URL <code>url</code>.
|
||||
*
|
||||
* @param url
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XGlyphFile(URL url) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the InputStream <code>in</code>.
|
||||
*
|
||||
* @param in
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XGlyphFile(InputStream in) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the InputSource <code>is</code>.
|
||||
*
|
||||
* @param is
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XGlyphFile(InputSource is) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a <code>XGlyphFile</code> by the Reader <code>reader</code>.
|
||||
*
|
||||
* @param reader
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public XGlyphFile(Reader reader) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the XGlyphFile <code>source</code>.
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public void setup(XGlyphFile source) {
|
||||
int size;
|
||||
href_ = source.href_;
|
||||
unicode_ = source.unicode_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the Document <code>doc</code>.
|
||||
*
|
||||
* @param doc
|
||||
*/
|
||||
public void setup(Document doc) {
|
||||
setup(doc.getDocumentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the Element <code>element</code>.
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
public void setup(Element element) {
|
||||
init(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the Stack <code>stack</code>
|
||||
* that contains Elements.
|
||||
* This constructor is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
*/
|
||||
public void setup(RStack stack) {
|
||||
init(stack.popElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
*/
|
||||
private void init(Element element) {
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
RStack stack = new RStack(element);
|
||||
href_ = URelaxer.getAttributePropertyAsString(element, "href");
|
||||
unicode_ = URelaxer.getAttributePropertyAsLong(element, "unicode");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Object
|
||||
*/
|
||||
public Object clone() {
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
return (factory.createXGlyphFile((XGlyphFile)this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DOM representation of the object.
|
||||
* Result is appended to the Node <code>parent</code>.
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
public void makeElement(Node parent) {
|
||||
Document doc;
|
||||
if (parent instanceof Document) {
|
||||
doc = (Document)parent;
|
||||
} else {
|
||||
doc = parent.getOwnerDocument();
|
||||
}
|
||||
Element element = doc.createElement("glyphFile");
|
||||
int size;
|
||||
if (this.href_ != null) {
|
||||
URelaxer.setAttributePropertyByString(element, "href", this.href_);
|
||||
}
|
||||
URelaxer.setAttributePropertyByLong(element, "unicode", this.unicode_);
|
||||
parent.appendChild(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the File <code>file</code>.
|
||||
*
|
||||
* @param file
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(File file) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(file.toURI().toURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code>
|
||||
* by the String representation of URI <code>uri</code>.
|
||||
*
|
||||
* @param uri
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(String uri) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(uri, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the URL <code>url</code>.
|
||||
*
|
||||
* @param url
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(URL url) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(url, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the InputStream <code>in</code>.
|
||||
*
|
||||
* @param in
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(InputStream in) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(in, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the InputSource <code>is</code>.
|
||||
*
|
||||
* @param is
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(InputSource is) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(is, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the <code>XGlyphFile</code> by the Reader <code>reader</code>.
|
||||
*
|
||||
* @param reader
|
||||
* @exception IOException
|
||||
* @exception SAXException
|
||||
* @exception ParserConfigurationException
|
||||
*/
|
||||
public void setup(Reader reader) throws IOException, SAXException, ParserConfigurationException {
|
||||
setup(UJAXP.getDocument(reader, UJAXP.FLAG_NONE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DOM document representation of the object.
|
||||
*
|
||||
* @exception ParserConfigurationException
|
||||
* @return Document
|
||||
*/
|
||||
public Document makeDocument() throws ParserConfigurationException {
|
||||
Document doc = UJAXP.makeDocument();
|
||||
makeElement(doc);
|
||||
return (doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the String property <b>href</b>.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getHref() {
|
||||
return (href_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the String property <b>href</b>.
|
||||
*
|
||||
* @param href
|
||||
*/
|
||||
public void setHref(String href) {
|
||||
this.href_ = href;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the long property <b>unicode</b>.
|
||||
*
|
||||
* @return long
|
||||
*/
|
||||
public long getUnicode() {
|
||||
return (unicode_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the long property <b>unicode</b>.
|
||||
*
|
||||
* @param unicode
|
||||
*/
|
||||
public void setUnicode(long unicode) {
|
||||
this.unicode_ = unicode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String makeTextDocument() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
makeTextElement(buffer);
|
||||
return (new String(buffer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextElement(StringBuffer buffer) {
|
||||
int size;
|
||||
buffer.append("<glyphFile");
|
||||
if (href_ != null) {
|
||||
buffer.append(" href=\"");
|
||||
buffer.append(URelaxer.escapeAttrQuot(URelaxer.getString(getHref())));
|
||||
buffer.append("\"");
|
||||
}
|
||||
buffer.append(" unicode=\"");
|
||||
buffer.append(URelaxer.getString(getUnicode()));
|
||||
buffer.append("\"");
|
||||
buffer.append(">");
|
||||
buffer.append("</glyphFile>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
* @exception IOException
|
||||
*/
|
||||
public void makeTextElement(Writer buffer) throws IOException {
|
||||
int size;
|
||||
buffer.write("<glyphFile");
|
||||
if (href_ != null) {
|
||||
buffer.write(" href=\"");
|
||||
buffer.write(URelaxer.escapeAttrQuot(URelaxer.getString(getHref())));
|
||||
buffer.write("\"");
|
||||
}
|
||||
buffer.write(" unicode=\"");
|
||||
buffer.write(URelaxer.getString(getUnicode()));
|
||||
buffer.write("\"");
|
||||
buffer.write(">");
|
||||
buffer.write("</glyphFile>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextElement(PrintWriter buffer) {
|
||||
int size;
|
||||
buffer.print("<glyphFile");
|
||||
if (href_ != null) {
|
||||
buffer.print(" href=\"");
|
||||
buffer.print(URelaxer.escapeAttrQuot(URelaxer.getString(getHref())));
|
||||
buffer.print("\"");
|
||||
}
|
||||
buffer.print(" unicode=\"");
|
||||
buffer.print(URelaxer.getString(getUnicode()));
|
||||
buffer.print("\"");
|
||||
buffer.print(">");
|
||||
buffer.print("</glyphFile>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextAttribute(StringBuffer buffer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
* @exception IOException
|
||||
*/
|
||||
public void makeTextAttribute(Writer buffer) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an XML text representation.
|
||||
*
|
||||
* @param buffer
|
||||
*/
|
||||
public void makeTextAttribute(PrintWriter buffer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property value as String.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getHrefAsString() {
|
||||
return (URelaxer.getString(getHref()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property value as String.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getUnicodeAsString() {
|
||||
return (URelaxer.getString(getUnicode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value by String.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void setHrefByString(String string) {
|
||||
setHref(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property value by String.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void setUnicodeByString(String string) {
|
||||
setUnicode(Long.parseLong(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of this object.
|
||||
* While this method informs as XML format representaion,
|
||||
* it's purpose is just information, not making
|
||||
* a rigid XML documentation.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toString() {
|
||||
try {
|
||||
return (makeTextDocument());
|
||||
} catch (Exception e) {
|
||||
return (super.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the IRNode property <b>parentRNode</b>.
|
||||
*
|
||||
* @return IRNode
|
||||
*/
|
||||
public IRNode rGetParentRNode() {
|
||||
return (parentRNode_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the IRNode property <b>parentRNode</b>.
|
||||
*
|
||||
* @param parentRNode
|
||||
*/
|
||||
public void rSetParentRNode(IRNode parentRNode) {
|
||||
this.parentRNode_ = parentRNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets child RNodes.
|
||||
*
|
||||
* @return IRNode[]
|
||||
*/
|
||||
public IRNode[] rGetRNodes() {
|
||||
java.util.List<IRNode> classNodes = new java.util.ArrayList<>();
|
||||
IRNode[] nodes = new IRNode[classNodes.size()];
|
||||
return ((IRNode[])classNodes.toArray(nodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a Element <code>element</code> is valid
|
||||
* for the <code>XGlyphFile</code>.
|
||||
*
|
||||
* @param element
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatch(Element element) {
|
||||
if (!URelaxer.isTargetElement(element, "glyphFile")) {
|
||||
return (false);
|
||||
}
|
||||
RStack target = new RStack(element);
|
||||
boolean $match$ = false;
|
||||
IGlyphFactory factory = GlyphFactory.getFactory();
|
||||
Element child;
|
||||
if (!URelaxer.hasAttributeHungry(target, "href")) {
|
||||
return (false);
|
||||
}
|
||||
$match$ = true;
|
||||
if (!URelaxer.hasAttributeHungry(target, "unicode")) {
|
||||
return (false);
|
||||
}
|
||||
$match$ = true;
|
||||
if (!target.isEmptyElement()) {
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if elements contained in a Stack <code>stack</code>
|
||||
* is valid for the <code>XGlyphFile</code>.
|
||||
* This mehtod is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatch(RStack stack) {
|
||||
Element element = stack.peekElement();
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
return (isMatch(element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if elements contained in a Stack <code>stack</code>
|
||||
* is valid for the <code>XGlyphFile</code>.
|
||||
* This method consumes the stack contents during matching operation.
|
||||
* This mehtod is supposed to be used internally
|
||||
* by the Relaxer system.
|
||||
*
|
||||
* @param stack
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isMatchHungry(RStack stack) {
|
||||
Element element = stack.peekElement();
|
||||
if (element == null) {
|
||||
return (false);
|
||||
}
|
||||
if (isMatch(element)) {
|
||||
stack.popElement();
|
||||
return (true);
|
||||
} else {
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
2545
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XHead.java
Normal file
2545
trunk/libsrc/ttf/src/org/doubletype/ossa/xml/XHead.java
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user