mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-15 00:02:49 +03:00
Removed no more used 'core' project
This commit is contained in:
@ -24,11 +24,6 @@
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile sources">
|
||||
<condition property="core-built">
|
||||
<available file="../core/core.jar" />
|
||||
</condition>
|
||||
<fail unless="core-built" message="Please build the core library first and make sure it sits in ../core/core.jar" />
|
||||
|
||||
<mkdir dir="bin" />
|
||||
|
||||
<!-- ant seems to nuke ${java.home} for some reason, pointing at the JRE
|
||||
|
@ -39,7 +39,6 @@
|
||||
|
||||
<!-- Libraries required for running arduino -->
|
||||
<fileset dir=".." id="runtime.jars">
|
||||
<include name="core/core.jar" />
|
||||
<include name="app/pde.jar" />
|
||||
<include name="app/lib/commons-codec-1.7.jar" />
|
||||
<include name="app/lib/commons-exec-1.1.jar" />
|
||||
@ -84,12 +83,10 @@
|
||||
<!-- - - - - - - - - - - - - - - - - - -->
|
||||
|
||||
<target name="subprojects-clean">
|
||||
<subant buildpath="../core" target="clean"/>
|
||||
<subant buildpath="../app" target="clean"/>
|
||||
</target>
|
||||
|
||||
<target name="subprojects-build">
|
||||
<subant buildpath="../core" target="build"/>
|
||||
<subant buildpath="../app" target="build"/>
|
||||
</target>
|
||||
|
||||
|
@ -94,7 +94,7 @@
|
||||
<!-- In 0149, removed /System/Library/Java from the CLASSPATH because
|
||||
it can cause problems if users have installed weird files there.
|
||||
http://dev.processing.org/bugs/show_bug.cgi?id=1045 -->
|
||||
<string>$JAVAROOT/pde.jar:$JAVAROOT/core.jar:$JAVAROOT/antlr.jar:$JAVAROOT/apple.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/jssc-2.8.0.jar:$JAVAROOT/commons-codec-1.7.jar:$JAVAROOT/commons-exec-1.1.jar:$JAVAROOT/commons-httpclient-3.1.jar:$JAVAROOT/commons-logging-1.0.4.jar:$JAVAROOT/jmdns-3.4.1.jar:$JAVAROOT/jsch-0.1.50.jar:$JAVAROOT/jna.jar</string>
|
||||
<string>$JAVAROOT/pde.jar:$JAVAROOT/antlr.jar:$JAVAROOT/apple.jar:$JAVAROOT/ecj.jar:$JAVAROOT/registry.jar:$JAVAROOT/quaqua.jar:$JAVAROOT/jssc-2.8.0.jar:$JAVAROOT/commons-codec-1.7.jar:$JAVAROOT/commons-exec-1.1.jar:$JAVAROOT/commons-httpclient-3.1.jar:$JAVAROOT/commons-logging-1.0.4.jar:$JAVAROOT/jmdns-3.4.1.jar:$JAVAROOT/jsch-0.1.50.jar:$JAVAROOT/jna.jar</string>
|
||||
|
||||
<key>JVMArchs</key>
|
||||
<array>
|
||||
|
@ -16,7 +16,6 @@
|
||||
<classPath>
|
||||
<mainClass>processing.app.Base</mainClass>
|
||||
<cp>lib/pde.jar</cp>
|
||||
<cp>lib/core.jar</cp>
|
||||
<cp>lib/jna.jar</cp>
|
||||
<cp>lib/ecj.jar</cp>
|
||||
<cp>lib/jssc-2.8.0.jar</cp>
|
||||
|
@ -16,7 +16,6 @@
|
||||
<classPath>
|
||||
<mainClass>processing.app.Base</mainClass>
|
||||
<cp>lib/pde.jar</cp>
|
||||
<cp>lib/core.jar</cp>
|
||||
<cp>lib/jna.jar</cp>
|
||||
<cp>lib/ecj.jar</cp>
|
||||
<cp>lib/jssc-2.8.0.jar</cp>
|
||||
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>processing-core</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,271 +0,0 @@
|
||||
#Sat Dec 31 13:42:35 CET 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=18
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=18
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
|
||||
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=18
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=18
|
||||
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_method=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_header=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_html=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_source_code=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.comment.line_length=80
|
||||
org.eclipse.jdt.core.formatter.compact_else_if=true
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation=2
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
|
||||
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_empty_lines=false
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
|
||||
org.eclipse.jdt.core.formatter.indentation.size=4
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
|
||||
org.eclipse.jdt.core.formatter.join_wrapped_lines=true
|
||||
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.lineSplit=80
|
||||
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
|
||||
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
|
||||
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
|
||||
org.eclipse.jdt.core.formatter.tabulation.char=space
|
||||
org.eclipse.jdt.core.formatter.tabulation.size=2
|
||||
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
|
||||
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=false
|
@ -1,5 +0,0 @@
|
||||
#Fri Dec 30 18:14:57 CET 2011
|
||||
eclipse.preferences.version=1
|
||||
formatter_profile=_Arduino
|
||||
formatter_settings_version=11
|
||||
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates/>
|
413
core/api.txt
413
core/api.txt
@ -1,413 +0,0 @@
|
||||
|
||||
public void setParent(PApplet parent)
|
||||
public void setPrimary(boolean primary)
|
||||
public void setPath(String path)
|
||||
public void setSize(int iwidth, int iheight)
|
||||
protected void allocate()
|
||||
public void dispose()
|
||||
|
||||
public boolean canDraw()
|
||||
public void beginDraw()
|
||||
public void endDraw()
|
||||
|
||||
protected void checkSettings()
|
||||
protected void defaultSettings()
|
||||
protected void reapplySettings()
|
||||
|
||||
public void hint(int which)
|
||||
|
||||
public void beginShape()
|
||||
public void beginShape(int kind)
|
||||
public void edge(boolean e)
|
||||
public void normal(float nx, float ny, float nz)
|
||||
public void textureMode(int mode)
|
||||
public void texture(PImage image)
|
||||
public void vertex(float x, float y)
|
||||
public void vertex(float x, float y, float z)
|
||||
public void vertex(float x, float y, float u, float v)
|
||||
public void vertex(float x, float y, float z, float u, float v)
|
||||
protected void vertexTexture(float u, float v);
|
||||
public void breakShape()
|
||||
public void endShape()
|
||||
public void endShape(int mode)
|
||||
|
||||
protected void bezierVertexCheck();
|
||||
public void bezierVertex(float x2, float y2,
|
||||
float x3, float y3,
|
||||
float x4, float y4)
|
||||
public void bezierVertex(float x2, float y2, float z2,
|
||||
float x3, float y3, float z3,
|
||||
float x4, float y4, float z4)
|
||||
|
||||
protected void curveVertexCheck();
|
||||
public void curveVertex(float x, float y)
|
||||
public void curveVertex(float x, float y, float z)
|
||||
protected void curveVertexSegment(float x1, float y1,
|
||||
float x2, float y2,
|
||||
float x3, float y3,
|
||||
float x4, float y4)
|
||||
protected void curveVertexSegment(float x1, float y1, float z1,
|
||||
float x2, float y2, float z2,
|
||||
float x3, float y3, float z3,
|
||||
float x4, float y4, float z4)
|
||||
|
||||
protected void renderPoints(int start, int stop) // P3D
|
||||
protected void rawPoints(int start, int stop) // P3D
|
||||
|
||||
protected void renderLines(int start, int stop) // P3D
|
||||
protected void rawLines(int start, int stop) // P3D
|
||||
|
||||
protected void renderTriangles(int start, int stop) // P3D
|
||||
protected void rawTriangles(int start, int stop) // P3D
|
||||
|
||||
public void flush()
|
||||
protected void render()
|
||||
proected void sort()
|
||||
|
||||
public void point(float x, float y)
|
||||
public void point(float x, float y, float z)
|
||||
public void line(float x1, float y1, float x2, float y2)
|
||||
public void line(float x1, float y1, float z1,
|
||||
float x2, float y2, float z2)
|
||||
public void triangle(float x1, float y1,
|
||||
float x2, float y2,
|
||||
float x3, float y3)
|
||||
public void quad(float x1, float y1, float x2, float y2,
|
||||
float x3, float y3, float x4, float y4)
|
||||
|
||||
public void rectMode(int mode)
|
||||
public void rect(float a, float b, float c, float d)
|
||||
protected void rectImpl(float x1, float y1, float x2, float y2)
|
||||
|
||||
public void ellipseMode(int mode)
|
||||
public void ellipse(float a, float b, float c, float d)
|
||||
protected void ellipseImpl(float x, float y, float w, float h)
|
||||
|
||||
public void arc(float a, float b, float c, float d,
|
||||
float start, float stop)
|
||||
protected void arcImpl(float x, float y, float w, float h,
|
||||
float start, float stop)
|
||||
|
||||
public void box(float size)
|
||||
public void box(float w, float h, float d)
|
||||
|
||||
public void sphereDetail(int res)
|
||||
public void sphereDetail(int ures, int vres)
|
||||
public void sphere(float r)
|
||||
|
||||
public float bezierPoint(float a, float b, float c, float d, float t)
|
||||
public float bezierTangent(float a, float b, float c, float d, float t)
|
||||
protected void bezierInitCheck()
|
||||
protected void bezierInit()
|
||||
public void bezierDetail(int detail)
|
||||
public void bezier(float x1, float y1,
|
||||
float x2, float y2,
|
||||
float x3, float y3,
|
||||
float x4, float y4)
|
||||
public void bezier(float x1, float y1, float z1,
|
||||
float x2, float y2, float z2,
|
||||
float x3, float y3, float z3,
|
||||
float x4, float y4, float z4)
|
||||
|
||||
public float curvePoint(float a, float b, float c, float d, float t)
|
||||
public float curveTangent(float a, float b, float c, float d, float t)
|
||||
public void curveDetail(int detail)
|
||||
public void curveTightness(float tightness)
|
||||
protected void curveInitCheck()
|
||||
protected void curveInit()
|
||||
public void curve(float x1, float y1,
|
||||
float x2, float y2,
|
||||
float x3, float y3,
|
||||
float x4, float y4)
|
||||
public void curve(float x1, float y1, float z1,
|
||||
float x2, float y2, float z2,
|
||||
float x3, float y3, float z3,
|
||||
float x4, float y4, float z4)
|
||||
|
||||
protected void splineForward(int segments, PMatrix3D matrix)
|
||||
|
||||
public void smooth()
|
||||
public void noSmooth()
|
||||
|
||||
public void imageMode(int mode)
|
||||
public void image(PImage image, float x, float y)
|
||||
public void image(PImage image, float x, float y, float c, float d)
|
||||
public void image(PImage image,
|
||||
float a, float b, float c, float d,
|
||||
int u1, int v1, int u2, int v2)
|
||||
protected void imageImpl(PImage image,
|
||||
float x1, float y1, float x2, float y2,
|
||||
int u1, int v1, int u2, int v2)
|
||||
|
||||
public void shapeMode(int mode)
|
||||
public void shape(PShape shape)
|
||||
public void shape(PShape shape, float x, float y)
|
||||
public void shape(PShape shape, float x, float y, float c, float d)
|
||||
|
||||
public void textAlign(int align)
|
||||
public void textAlign(int alignX, int alignY)
|
||||
public float textAscent()
|
||||
public float textDescent()
|
||||
public void textFont(PFont which)
|
||||
public void textFont(PFont which, float size)
|
||||
public void textLeading(float leading)
|
||||
public void textMode(int mode)
|
||||
protected boolean textModeCheck(int mode)
|
||||
public void textSize(float size)
|
||||
public float textWidth(char c)
|
||||
public float textWidth(String str)
|
||||
protected float textWidthImpl(char buffer[], int start, int stop)
|
||||
|
||||
public void text(char c)
|
||||
public void text(char c, float x, float y)
|
||||
public void text(char c, float x, float y, float z)
|
||||
public void text(String str)
|
||||
public void text(String str, float x, float y)
|
||||
public void text(String str, float x, float y, float z)
|
||||
public void text(String str, float x1, float y1, float x2, float y2)
|
||||
public void text(String s, float x1, float y1, float x2, float y2, float z)
|
||||
public void text(int num, float x, float y)
|
||||
public void text(int num, float x, float y, float z)
|
||||
public void text(float num, float x, float y)
|
||||
public void text(float num, float x, float y, float z)
|
||||
|
||||
protected void textLineAlignImpl(char buffer[], int start, int stop,
|
||||
float x, float y)
|
||||
protected void textLineImpl(char buffer[], int start, int stop,
|
||||
float x, float y)
|
||||
protected void textCharImpl(char ch, float x, float y)
|
||||
protected void textCharModelImpl(PImage glyph,
|
||||
float x1, float y1, //float z1,
|
||||
float x2, float y2, //float z2,
|
||||
int u2, int v2)
|
||||
protected void textCharScreenImpl(PImage glyph,
|
||||
int xx, int yy,
|
||||
int w0, int h0)
|
||||
|
||||
public void pushMatrix()
|
||||
public void popMatrix()
|
||||
|
||||
public void translate(float tx, float ty)
|
||||
public void translate(float tx, float ty, float tz)
|
||||
public void rotate(float angle)
|
||||
public void rotateX(float angle)
|
||||
public void rotateY(float angle)
|
||||
public void rotateZ(float angle)
|
||||
public void rotate(float angle, float vx, float vy, float vz)
|
||||
public void scale(float s)
|
||||
public void scale(float sx, float sy)
|
||||
public void scale(float x, float y, float z)
|
||||
|
||||
public void resetMatrix()
|
||||
public void applyMatrix(PMatrix2D source)
|
||||
public void applyMatrix(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12)
|
||||
public void applyMatrix(PMatrix3D source)
|
||||
public void applyMatrix(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33)
|
||||
|
||||
public getMatrix(PMatrix2D target)
|
||||
public getMatrix(PMatrix3D target)
|
||||
public void setMatrix(PMatrix2D source)
|
||||
public void setMatrix(PMatrix3D source)
|
||||
public void printMatrix()
|
||||
|
||||
public void beginCamera()
|
||||
public void endCamera()
|
||||
public void camera()
|
||||
public void camera(float eyeX, float eyeY, float eyeZ,
|
||||
float centerX, float centerY, float centerZ,
|
||||
float upX, float upY, float upZ)
|
||||
public void printCamera()
|
||||
|
||||
public void ortho()
|
||||
public void ortho(float left, float right,
|
||||
float bottom, float top,
|
||||
float near, float far)
|
||||
public void perspective()
|
||||
public void perspective(float fov, float aspect, float near, float far)
|
||||
public void frustum(float left, float right,
|
||||
float bottom, float top,
|
||||
float near, float far)
|
||||
public void printProjection()
|
||||
|
||||
public float screenX(float x, float y)
|
||||
public float screenY(float x, float y)
|
||||
public float screenX(float x, float y, float z)
|
||||
public float screenY(float x, float y, float z)
|
||||
public float screenZ(float x, float y, float z)
|
||||
public float modelX(float x, float y, float z)
|
||||
public float modelY(float x, float y, float z)
|
||||
public float modelZ(float x, float y, float z)
|
||||
|
||||
public void pushStyle()
|
||||
public void popStyle()
|
||||
public void style(PStyle)
|
||||
public PStyle getStyle()
|
||||
public void getStyle(PStyle)
|
||||
|
||||
public void strokeCap(int cap)
|
||||
public void strokeJoin(int join)
|
||||
public void strokeWeight(float weight)
|
||||
|
||||
public void noStroke()
|
||||
public void stroke(int rgb)
|
||||
public void stroke(int rgb, float alpha)
|
||||
public void stroke(float gray)
|
||||
public void stroke(float gray, float alpha)
|
||||
public void stroke(float x, float y, float z)
|
||||
public void stroke(float x, float y, float z, float a)
|
||||
protected void strokeFromCalc()
|
||||
|
||||
public void noTint()
|
||||
public void tint(int rgb)
|
||||
public void tint(int rgb, float alpha)
|
||||
public void tint(float gray)
|
||||
public void tint(float gray, float alpha)
|
||||
public void tint(float x, float y, float z)
|
||||
public void tint(float x, float y, float z, float a)
|
||||
protected void tintFromCalc()
|
||||
|
||||
public void noFill()
|
||||
public void fill(int rgb)
|
||||
public void fill(int rgb, float alpha)
|
||||
public void fill(float gray)
|
||||
public void fill(float gray, float alpha)
|
||||
public void fill(float x, float y, float z)
|
||||
public void fill(float x, float y, float z, float a)
|
||||
protected void fillFromCalc()
|
||||
|
||||
public void ambient(int rgb)
|
||||
public void ambient(float gray)
|
||||
public void ambient(float x, float y, float z)
|
||||
protected void ambientFromCalc()
|
||||
public void specular(int rgb)
|
||||
public void specular(float gray)
|
||||
public void specular(float x, float y, float z)
|
||||
protected void specularFromCalc()
|
||||
public void shininess(float shine)
|
||||
public void emissive(int rgb)
|
||||
public void emissive(float gray)
|
||||
public void emissive(float x, float y, float z )
|
||||
protected void emissiveFromCalc()
|
||||
|
||||
public void lights()
|
||||
public void noLights()
|
||||
public void ambientLight(float red, float green, float blue)
|
||||
public void ambientLight(float red, float green, float blue,
|
||||
float x, float y, float z)
|
||||
public void directionalLight(float red, float green, float blue,
|
||||
float nx, float ny, float nz)
|
||||
public void pointLight(float red, float green, float blue,
|
||||
float x, float y, float z)
|
||||
public void spotLight(float red, float green, float blue,
|
||||
float x, float y, float z,
|
||||
float nx, float ny, float nz,
|
||||
float angle, float concentration)
|
||||
public void lightFalloff(float constant, float linear, float quadratic)
|
||||
public void lightSpecular(float x, float y, float z)
|
||||
protected void lightPosition(int num, float x, float y, float z)
|
||||
protected void lightDirection(int num, float x, float y, float z)
|
||||
|
||||
public void background(int rgb)
|
||||
public void background(int rgb, float alpha)
|
||||
public void background(float gray)
|
||||
public void background(float gray, float alpha)
|
||||
public void background(float x, float y, float z)
|
||||
public void background(float x, float y, float z, float a)
|
||||
public void background(PImage image)
|
||||
protected void backgroundFromCalc()
|
||||
protected void backgroundImpl(PImage image)
|
||||
protected void backgroundImpl()
|
||||
|
||||
public void colorMode(int mode)
|
||||
public void colorMode(int mode, float max)
|
||||
public void colorMode(int mode, float maxX, float maxY, float maxZ)
|
||||
public void colorMode(int mode, float maxX, float maxY, float maxZ, float maxA)
|
||||
|
||||
protected void colorCalc(int rgb)
|
||||
protected void colorCalc(int rgb, float alpha)
|
||||
protected void colorCalc(float gray)
|
||||
protected void colorCalc(float gray, float alpha)
|
||||
protected void colorCalc(float x, float y, float z)
|
||||
protected void colorCalc(float x, float y, float z, float a)
|
||||
protected void colorCalcARGB(int argb, float alpha)
|
||||
|
||||
public final int color(int gray)
|
||||
public final int color(int gray, int alpha)
|
||||
public final int color(int rgb, float alpha)
|
||||
public final int color(int x, int y, int z)
|
||||
|
||||
public final float alpha(int what)
|
||||
public final float red(int what)
|
||||
public final float green(int what)
|
||||
public final float blue(int what)
|
||||
public final float hue(int what)
|
||||
public final float saturation(int what)
|
||||
public final float brightness(int what)
|
||||
|
||||
public int lerpColor(int c1, int c2, float amt)
|
||||
static public int lerpColor(int c1, int c2, float amt, int mode)
|
||||
|
||||
public void beginRaw(PGraphics rawGraphics)
|
||||
public void endRaw()
|
||||
|
||||
static public void showWarning(String msg)
|
||||
static public void showException(String msg)
|
||||
|
||||
public boolean displayable()
|
||||
public boolean is2D()
|
||||
public boolean is3D()
|
||||
|
||||
//
|
||||
|
||||
These are the methods found in PImage, which are inherited by PGraphics.
|
||||
|
||||
public PImage(Image)
|
||||
public Image getImage()
|
||||
|
||||
public void setCache(Object parent, Object storage)
|
||||
public void getCache(Object parent)
|
||||
public void removeCache(Object parent)
|
||||
|
||||
public boolean isModified();
|
||||
public void setModified();
|
||||
public void setModified(boolean state);
|
||||
|
||||
public void loadPixels()
|
||||
public void updatePixels()
|
||||
public void updatePixels(int x, int y, int w, int h)
|
||||
|
||||
public void resize(int wide, int high)
|
||||
|
||||
public int get(int x, int y)
|
||||
public PImage get(int x, int y, int w, int h)
|
||||
protected PImage getImpl(int x, int y, int w, int h)
|
||||
public PImage get()
|
||||
public void set(int x, int y, int c)
|
||||
public void set(int x, int y, PImage src)
|
||||
protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh,
|
||||
PImage src)
|
||||
|
||||
public void mask(int alpha[])
|
||||
public void mask(PImage alpha)
|
||||
|
||||
public void filter(int kind)
|
||||
public void filter(int kind, float param)
|
||||
|
||||
public void copy(int sx, int sy, int sw, int sh,
|
||||
int dx, int dy, int dw, int dh)
|
||||
public void copy(PImage src,
|
||||
int sx, int sy, int sw, int sh,
|
||||
int dx, int dy, int dw, int dh)
|
||||
|
||||
static public int blendColor(int c1, int c2, int mode)
|
||||
public void blend(int sx, int sy, int sw, int sh,
|
||||
int dx, int dy, int dw, int dh, int mode)
|
||||
public void blend(PImage src,
|
||||
int sx, int sy, int sw, int sh,
|
||||
int dx, int dy, int dw, int dh, int mode)
|
||||
|
||||
public void save(String path)
|
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<project name="Processing Core" default="build">
|
||||
|
||||
<target name="clean" description="Clean out the build directories">
|
||||
<delete dir="bin" />
|
||||
<delete file="core.jar" />
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile">
|
||||
<taskdef name="methods"
|
||||
classname="PAppletMethods"
|
||||
classpath="methods/methods.jar" />
|
||||
<methods dir="${basedir}/src/processing/core" />
|
||||
|
||||
<mkdir dir="bin" />
|
||||
<javac source="1.6" target="1.6"
|
||||
encoding="UTF-8"
|
||||
includeAntRuntime="false"
|
||||
srcdir="src" destdir="bin"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile" description="Build core library">
|
||||
<jar basedir="bin" destfile="core.jar" />
|
||||
</target>
|
||||
|
||||
</project>
|
3009
core/done.txt
3009
core/done.txt
File diff suppressed because it is too large
Load Diff
456
core/license.txt
456
core/license.txt
@ -1,456 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[ This is the first released version of the Lesser GPL.
|
||||
It also counts as the successor of the GNU Library Public
|
||||
License, version 2, hence the version number 2.1. ]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#javadoc -public -d doc *.java
|
||||
#javadoc -private -d doc *.java
|
||||
chmod +x preproc.pl
|
||||
./preproc.pl
|
||||
jikes -d . +D *.java
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/usr/share/ant/lib/ant.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>preproc</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,28 +0,0 @@
|
||||
<project name="methods" default="task-lib">
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="bin" />
|
||||
<!-- <javac target="1.5" srcdir="src" destdir="bin" classpath="../ant/ant.jar" debug="true"/>-->
|
||||
<!-- <javac target="1.5" srcdir="src" destdir="bin" classpath="/usr/share/ant/ant.jar" debug="true"/>-->
|
||||
<javac target="1.5"
|
||||
srcdir="src" destdir="bin"
|
||||
debug="true"
|
||||
includeantruntime="true" />
|
||||
</target>
|
||||
|
||||
<target name="task-lib" depends="compile">
|
||||
<jar basedir="bin" destfile="methods.jar" />
|
||||
</target>
|
||||
|
||||
<target name="demo">
|
||||
<taskdef name="methods"
|
||||
classname="PAppletMethods"
|
||||
classpath="methods.jar" />
|
||||
<preproc dir="demo"/>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="bin" />
|
||||
<delete file="methods.jar" />
|
||||
</target>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,272 +0,0 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
||||
|
||||
/**
|
||||
* Ant Task for copying the PImage and PGraphics methods into PApplet.
|
||||
*/
|
||||
public class PAppletMethods extends Task {
|
||||
|
||||
private File baseDir;
|
||||
|
||||
|
||||
public PAppletMethods() {
|
||||
}
|
||||
|
||||
|
||||
public void setDir(String dir) {
|
||||
baseDir = new File(dir);
|
||||
}
|
||||
|
||||
|
||||
public void execute() throws BuildException {
|
||||
// Do a bunch of checks...
|
||||
if (baseDir == null) {
|
||||
throw new BuildException("dir parameter must be set!");
|
||||
}
|
||||
|
||||
//System.out.println("using basedir " + baseDir);
|
||||
File graphicsFile = new File(baseDir, "PGraphics.java");
|
||||
File appletFile = new File(baseDir, "PApplet.java");
|
||||
File imageFile = new File(baseDir, "PImage.java");
|
||||
|
||||
if (!graphicsFile.exists() || !graphicsFile.canRead()) {
|
||||
throw new BuildException("PGraphics file not readable: " +
|
||||
graphicsFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (!appletFile.exists() ||
|
||||
!appletFile.canRead() ||
|
||||
!appletFile.canWrite()) {
|
||||
throw new BuildException("PApplet file not read/writeable: " +
|
||||
appletFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (!imageFile.exists() || !imageFile.canRead()) {
|
||||
throw new BuildException("PImage file not readable: " +
|
||||
imageFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
// Looking good, let's do this!
|
||||
//ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
|
||||
//PrintStream out = new PrintStream(outBytes, "UTF-8");
|
||||
StringBuffer out = new StringBuffer();
|
||||
StringBuffer content = new StringBuffer();
|
||||
|
||||
try{
|
||||
BufferedReader applet = createReader(appletFile);
|
||||
String line;
|
||||
while ((line = applet.readLine()) != null) {
|
||||
out.append(line);
|
||||
out.append('\n'); // to avoid Windows CRs
|
||||
content.append(line);
|
||||
content.append('\n'); // for efficiency
|
||||
|
||||
if (line.indexOf("public functions for processing.core") >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// read the rest of the file and append it to the
|
||||
while ((line = applet.readLine()) != null) {
|
||||
content.append(line);
|
||||
content.append('\n');
|
||||
}
|
||||
|
||||
applet.close();
|
||||
process(out, graphicsFile);
|
||||
process(out, imageFile);
|
||||
|
||||
out.append('}');
|
||||
out.append('\n');
|
||||
|
||||
//} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
|
||||
} catch (Exception e) {
|
||||
//ex.printStackTrace();
|
||||
throw new BuildException(e);
|
||||
}
|
||||
//out.flush();
|
||||
|
||||
String outString = out.toString();
|
||||
if (content.toString().equals(outString)) {
|
||||
System.out.println("No changes to PApplet API.");
|
||||
} else {
|
||||
System.out.println("Updating PApplet with API changes " +
|
||||
"from PImage or PGraphics.");
|
||||
try {
|
||||
PrintStream temp = new PrintStream(appletFile, "UTF-8");
|
||||
temp.print(outString);
|
||||
temp.flush();
|
||||
temp.close();
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void process(StringBuffer out, File input) throws IOException {
|
||||
BufferedReader in = createReader(input);
|
||||
int comments = 0;
|
||||
String line = null;
|
||||
StringBuffer commentBuffer = new StringBuffer();
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String decl = "";
|
||||
|
||||
// Keep track of comments
|
||||
//if (line.matches(Pattern.quote("/*"))) {
|
||||
if (line.indexOf("/*") != -1) {
|
||||
comments++;
|
||||
}
|
||||
|
||||
//if (line.matches(Pattern.quote("*/"))) {
|
||||
if (line.indexOf("*/") != -1) {
|
||||
commentBuffer.append(line);
|
||||
commentBuffer.append('\n');
|
||||
//System.out.println("comment is: " + commentBuffer.toString());
|
||||
comments--;
|
||||
// otherwise gotSomething will be false, and nuke the comment
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore everything inside comments
|
||||
if (comments > 0) {
|
||||
commentBuffer.append(line);
|
||||
commentBuffer.append('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean gotSomething = false;
|
||||
boolean gotStatic = false;
|
||||
|
||||
Matcher result;
|
||||
|
||||
if ((result = Pattern.compile("^\\s*public ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
|
||||
} else if ((result = Pattern.compile("^\\s*abstract public ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
|
||||
} else if ((result = Pattern.compile("^\\s*public final ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
|
||||
} else if ((result = Pattern.compile("^\\s*static public ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
gotStatic = true;
|
||||
}
|
||||
|
||||
// if function is marked "// ignore" then, uh, ignore it.
|
||||
if (gotSomething && line.indexOf("// ignore") >= 0) {
|
||||
gotSomething = false;
|
||||
}
|
||||
|
||||
String returns = "";
|
||||
if (gotSomething) {
|
||||
if (result.group(1).equals("void")) {
|
||||
returns = "";
|
||||
} else {
|
||||
returns = "return ";
|
||||
}
|
||||
|
||||
// remove the abstract modifier
|
||||
line = line.replaceFirst(Pattern.quote("abstract"), " ");
|
||||
|
||||
// replace semicolons with a start def
|
||||
line = line.replaceAll(Pattern.quote(";"), " {\n");
|
||||
|
||||
//out.println("\n\n" + line);
|
||||
out.append('\n');
|
||||
out.append('\n');
|
||||
// end has its own newline
|
||||
//out.print(commentBuffer.toString()); // TODO disabled for now XXXX
|
||||
out.append(commentBuffer.toString()); // duplicates all comments
|
||||
commentBuffer.setLength(0);
|
||||
out.append(line);
|
||||
out.append('\n');
|
||||
|
||||
decl += line;
|
||||
while(line.indexOf(')') == -1) {
|
||||
line = in.readLine();
|
||||
decl += line;
|
||||
line = line.replaceAll("\\;\\s*$", " {\n");
|
||||
out.append(line);
|
||||
out.append('\n');
|
||||
}
|
||||
|
||||
result = Pattern.compile(".*?\\s(\\S+)\\(.*?").matcher(decl);
|
||||
// try to match. don't remove this or things will stop working!
|
||||
result.matches();
|
||||
String declName = result.group(1);
|
||||
String gline = "";
|
||||
String rline = "";
|
||||
if (gotStatic) {
|
||||
gline = " " + returns + "PGraphics." + declName + "(";
|
||||
} else {
|
||||
rline = " if (recorder != null) recorder." + declName + "(";
|
||||
gline = " " + returns + "g." + declName + "(";
|
||||
}
|
||||
|
||||
decl = decl.replaceAll("\\s+", " "); // smush onto a single line
|
||||
decl = decl.replaceFirst("^.*\\(", "");
|
||||
decl = decl.replaceFirst("\\).*$", "");
|
||||
|
||||
int prev = 0;
|
||||
String parts[] = decl.split("\\, ");
|
||||
|
||||
for (String part : parts) {
|
||||
if (!part.trim().equals("")) {
|
||||
String blargh[] = part.split(" ");
|
||||
String theArg = blargh[1].replaceAll("[\\[\\]]", "");
|
||||
|
||||
if (prev != 0) {
|
||||
gline += ", ";
|
||||
rline += ", ";
|
||||
}
|
||||
|
||||
gline += theArg;
|
||||
rline += theArg;
|
||||
prev = 1;
|
||||
}
|
||||
}
|
||||
|
||||
gline += ");";
|
||||
rline += ");";
|
||||
|
||||
if (!gotStatic && returns.equals("")) {
|
||||
out.append(rline);
|
||||
out.append('\n');
|
||||
}
|
||||
out.append(gline);
|
||||
out.append('\n');
|
||||
out.append(" }");
|
||||
out.append('\n');
|
||||
|
||||
} else {
|
||||
commentBuffer.setLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
|
||||
|
||||
static BufferedReader createReader(File file) throws IOException {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
return new BufferedReader(new InputStreamReader(fis, "UTF-8"));
|
||||
}
|
||||
}
|
186
core/preproc.pl
186
core/preproc.pl
@ -1,186 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
$basedir = 'src/processing/core';
|
||||
|
||||
@contents = ();
|
||||
|
||||
# next slurp methods from PGraphics
|
||||
open(F, "$basedir/PGraphics.java") || die $!;
|
||||
foreach $line (<F>) {
|
||||
push @contents, $line;
|
||||
}
|
||||
close(F);
|
||||
|
||||
# PGraphics subclasses PImage.. now get those methods
|
||||
open(F, "$basedir/PImage.java") || die $!;
|
||||
foreach $line (<F>) {
|
||||
push @contents, $line;
|
||||
}
|
||||
close(F);
|
||||
|
||||
#open(DEBUG, ">debug.java") || die $!;
|
||||
#print DEBUG @contents;
|
||||
#close(DEBUG);
|
||||
#exit;
|
||||
|
||||
|
||||
open(APPLET, "$basedir/PApplet.java") || die $!;
|
||||
@applet = <APPLET>;
|
||||
close(APPLET);
|
||||
|
||||
|
||||
$insert = 'public functions for processing.core';
|
||||
|
||||
# an improved version of this would only rewrite if changes made
|
||||
open(OUT, ">$basedir/PApplet.new") || die $!;
|
||||
foreach $line (@applet) {
|
||||
print OUT $line;
|
||||
last if ($line =~ /$insert/);
|
||||
}
|
||||
|
||||
$comments = 0;
|
||||
|
||||
while ($line = shift(@contents)) {
|
||||
$decl = "";
|
||||
|
||||
if ($line =~ /\/\*/) {
|
||||
$comments++;
|
||||
#print "+[$comments] $line";
|
||||
}
|
||||
if ($line =~ /\*\//) {
|
||||
$comments--;
|
||||
#print "-[$comments] $line";
|
||||
}
|
||||
next if ($comments > 0);
|
||||
|
||||
$got_something = 0; # so it's ugly, back off
|
||||
$got_static = 0;
|
||||
$got_interface = 0;
|
||||
|
||||
if ($line =~ /^\s*public ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
|
||||
$got_something = 1;
|
||||
$got_interface = 1;
|
||||
} elsif ($line =~ /^\s*abstract public ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
|
||||
$got_something = 1;
|
||||
} elsif ($line =~ /^\s*public final ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
|
||||
$got_something = 1;
|
||||
} elsif ($line =~ /^\s*static public ([\w\[\]]+) [a-zA-z_]+\(.*$/) {
|
||||
$got_something = 1;
|
||||
$got_static = 1;
|
||||
}
|
||||
# if function is marked "// ignore" then, uh, ignore it.
|
||||
if (($got_something == 1) && ($line =~ /\/\/ ignore/)) {
|
||||
$got_something = 0;
|
||||
}
|
||||
#if ($line =~ /^\s*public (\w+) [a-zA-z_]+\(.*$/) {
|
||||
if ($got_something == 1) {
|
||||
if ($1 ne 'void') {
|
||||
$returns = 'return ';
|
||||
} else {
|
||||
$returns = '';
|
||||
}
|
||||
|
||||
# if ($line =~ /^(\s+)abstract\s+([^;]+);/) {
|
||||
# $line = $1 . $2 . " {\n";
|
||||
# #print "found $1\n";
|
||||
# # hrm
|
||||
# }
|
||||
# remove the 'abstract' modifier
|
||||
$line =~ s/\sabstract\s/ /;
|
||||
|
||||
# replace semicolons with a start def
|
||||
$line =~ s/\;\s*$/ {\n/;
|
||||
|
||||
print OUT "\n\n$line";
|
||||
|
||||
# if ($got_interface == 1) {
|
||||
# $iline = $line;
|
||||
# $iline =~ s/ \{/\;/;
|
||||
## print INTF "\n$iline";
|
||||
# }
|
||||
|
||||
$decl .= $line;
|
||||
while (!($line =~ /\)/)) {
|
||||
$line = shift (@contents);
|
||||
$decl .= $line;
|
||||
$line =~ s/\;\s*$/ {\n/;
|
||||
print OUT $line;
|
||||
|
||||
# if ($got_interface == 1) {
|
||||
# $iline = $line;
|
||||
# $iline =~ s/ \{/\;/;
|
||||
## print INTF $iline;
|
||||
# }
|
||||
}
|
||||
|
||||
#$g_line = '';
|
||||
#$r_line = '';
|
||||
|
||||
$decl =~ /\s(\S+)\(/;
|
||||
$decl_name = $1;
|
||||
if ($got_static == 1) {
|
||||
#print OUT " ${returns}PGraphics.${decl_name}(";
|
||||
$g_line = " ${returns}PGraphics.${decl_name}(";
|
||||
} else {
|
||||
#if ($returns eq '') {
|
||||
#print OUT " if (recorder != null) recorder.${decl_name}(";
|
||||
$r_line = " if (recorder != null) recorder.${decl_name}(";
|
||||
#}
|
||||
#print OUT " ${returns}g.${decl_name}(";
|
||||
$g_line = " ${returns}g.${decl_name}(";
|
||||
}
|
||||
|
||||
$decl =~ s/\s+/ /g; # smush onto a single line
|
||||
$decl =~ s/^.*\(//;
|
||||
$decl =~ s/\).*$//;
|
||||
|
||||
$prev = 0;
|
||||
@parts = split(', ', $decl);
|
||||
foreach $part (@parts) {
|
||||
#($the_type, $the_arg) = split(' ', $part);
|
||||
@blargh = split(' ', $part);
|
||||
$the_arg = $blargh[1];
|
||||
$the_arg =~ s/[\[\]]//g;
|
||||
if ($prev != 0) {
|
||||
#print OUT ", ";
|
||||
$g_line .= ", ";
|
||||
$r_line .= ", ";
|
||||
}
|
||||
#print OUT "${the_arg}";
|
||||
$g_line .= "${the_arg}";
|
||||
$r_line .= "${the_arg}";
|
||||
$prev = 1;
|
||||
}
|
||||
#print OUT ");\n";
|
||||
$g_line .= ");\n";
|
||||
$r_line .= ");\n";
|
||||
|
||||
if (($got_static != 1) && ($returns eq '')) {
|
||||
print OUT $r_line;
|
||||
}
|
||||
print OUT $g_line;
|
||||
print OUT " }\n";
|
||||
}
|
||||
}
|
||||
print OUT "}\n";
|
||||
#print INTF "}\n";
|
||||
|
||||
close(OUT);
|
||||
#close(INTF);
|
||||
|
||||
$oldguy = join(' ', @applet);
|
||||
|
||||
open(NEWGUY, "$basedir/PApplet.new") || die $!;
|
||||
@newbie = <NEWGUY>;
|
||||
$newguy = join(' ', @newbie);
|
||||
close(NEWGUY);
|
||||
|
||||
if ($oldguy ne $newguy) {
|
||||
# replace him
|
||||
print "updating PApplet with PGraphics api changes\n";
|
||||
`mv $basedir/PApplet.new $basedir/PApplet.java`;
|
||||
} else {
|
||||
# just kill the new guy
|
||||
#print "no changes to applet\n";
|
||||
`rm -f $basedir/PApplet.new`;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/usr/share/ant/lib/ant.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>preproc</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,22 +0,0 @@
|
||||
<project name="preproc" default="task-lib">
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="bin" />
|
||||
<!-- <javac target="1.5" srcdir="src" destdir="bin" classpath="../ant/ant.jar" debug="true"/>-->
|
||||
<javac target="1.5" srcdir="src" destdir="bin" classpath="/usr/share/ant/ant.jar" debug="true"/>
|
||||
</target>
|
||||
|
||||
<target name="task-lib" depends="compile">
|
||||
<jar basedir="bin" destfile="preproc.jar" />
|
||||
</target>
|
||||
|
||||
<target name="demo">
|
||||
<taskdef name="preproc" classname="processing.build.PAppletMethods" classpath="preproc.jar" />
|
||||
<preproc dir="demo"/>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="bin" />
|
||||
<delete file="preproc.jar" />
|
||||
</target>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,236 +0,0 @@
|
||||
package processing.build;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Task;
|
||||
|
||||
|
||||
/**
|
||||
* Ant Task for copying the PImage and PGraphics methods into PApplet.
|
||||
*/
|
||||
public class PAppletMethods extends Task {
|
||||
|
||||
private File baseDir;
|
||||
|
||||
|
||||
public PAppletMethods() {
|
||||
}
|
||||
|
||||
|
||||
public void setDir(String dir) {
|
||||
baseDir = new File(dir);
|
||||
}
|
||||
|
||||
|
||||
public void execute() throws BuildException {
|
||||
// Do a bunch of checks...
|
||||
if (baseDir == null) {
|
||||
throw new BuildException("dir parameter must be set!");
|
||||
}
|
||||
|
||||
File graphicsFile = new File(baseDir, "PGraphics.java");
|
||||
File appletFile = new File(baseDir, "PApplet.java");
|
||||
File imageFile = new File(baseDir, "PImage.java");
|
||||
|
||||
if (!graphicsFile.exists() || !graphicsFile.canRead()) {
|
||||
throw new BuildException("PGraphics file not readable: " +
|
||||
graphicsFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (!appletFile.exists() || !appletFile.canRead() || !appletFile.canWrite()) {
|
||||
throw new BuildException("PApplet file not read/writeable: " +
|
||||
appletFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (!imageFile.exists() || !imageFile.canRead()) {
|
||||
throw new BuildException("PImage file not readable: " +
|
||||
imageFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
// Looking good, let's do this!
|
||||
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
|
||||
PrintStream out = new PrintStream(outBytes);
|
||||
StringBuffer content = new StringBuffer();
|
||||
|
||||
try{
|
||||
BufferedReader applet = createReader(appletFile);
|
||||
String line;
|
||||
while ((line = applet.readLine()) != null) {
|
||||
out.println(line);
|
||||
content.append(line + "\n");
|
||||
|
||||
if (line.indexOf("public functions for processing.core") >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// read the rest of the file and append it to the
|
||||
while ((line = applet.readLine()) != null) {
|
||||
content.append(line + "\n");
|
||||
}
|
||||
|
||||
applet.close();
|
||||
process(out, graphicsFile);
|
||||
process(out, imageFile);
|
||||
|
||||
out.println("}");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
out.flush();
|
||||
|
||||
if (content.toString().equals(outBytes.toString())) {
|
||||
System.out.println("No changes to PApplet API.");
|
||||
} else {
|
||||
System.out.println("Updating PApplet with API changes from PImage or PGraphics.");
|
||||
try {
|
||||
PrintStream temp = new PrintStream(appletFile);
|
||||
temp.print(outBytes.toString());
|
||||
temp.flush();
|
||||
temp.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void process(PrintStream out, File input) throws IOException {
|
||||
BufferedReader in = createReader(input);
|
||||
int comments = 0;
|
||||
String line = null;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
String decl = "";
|
||||
|
||||
// Keep track of comments
|
||||
if (line.matches(Pattern.quote("/*"))) {
|
||||
comments ++;
|
||||
}
|
||||
|
||||
if (line.matches(Pattern.quote("*/"))) {
|
||||
comments --;
|
||||
}
|
||||
|
||||
// Ignore everything inside comments
|
||||
if (comments > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean gotSomething = false;
|
||||
boolean gotStatic = false;
|
||||
|
||||
Matcher result;
|
||||
|
||||
if ((result = Pattern.compile("^\\s*public ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
}
|
||||
else if ((result = Pattern.compile("^\\s*abstract public ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
}
|
||||
else if ((result = Pattern.compile("^\\s*public final ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
}
|
||||
else if ((result = Pattern.compile("^\\s*static public ([\\w\\[\\]]+) [a-zA-z_]+\\(.*$").matcher(line)).matches()) {
|
||||
gotSomething = true;
|
||||
gotStatic = true;
|
||||
}
|
||||
|
||||
// if function is marked "// ignore" then, uh, ignore it.
|
||||
if (gotSomething && line.indexOf("// ignore") >= 0) {
|
||||
gotSomething = false;
|
||||
}
|
||||
|
||||
String returns = "";
|
||||
if (gotSomething) {
|
||||
if (result.group(1).equals("void")) {
|
||||
returns = "";
|
||||
} else {
|
||||
returns = "return ";
|
||||
}
|
||||
|
||||
// remove the abstract modifier
|
||||
line = line.replaceFirst(Pattern.quote("abstract"), " ");
|
||||
|
||||
// replace semicolons with a start def
|
||||
line = line.replaceAll(Pattern.quote(";"), " {\n");
|
||||
|
||||
out.println("\n\n" + line);
|
||||
|
||||
decl += line;
|
||||
while(line.indexOf(')') == -1) {
|
||||
line = in.readLine();
|
||||
decl += line;
|
||||
line = line.replaceAll("\\;\\s*$", " {\n");
|
||||
out.println(line);
|
||||
}
|
||||
|
||||
result = Pattern.compile(".*?\\s(\\S+)\\(.*?").matcher(decl);
|
||||
result.matches(); // try to match. DON't remove this or things will stop working!
|
||||
String declName = result.group(1);
|
||||
String gline = "";
|
||||
String rline = "";
|
||||
if (gotStatic) {
|
||||
gline = " " + returns + "PGraphics." + declName + "(";
|
||||
} else {
|
||||
rline = " if (recorder != null) recorder." + declName + "(";
|
||||
gline = " " + returns + "g." + declName + "(";
|
||||
}
|
||||
|
||||
decl = decl.replaceAll("\\s+", " "); // smush onto a single line
|
||||
decl = decl.replaceFirst("^.*\\(", "");
|
||||
decl = decl.replaceFirst("\\).*$", "");
|
||||
|
||||
int prev = 0;
|
||||
String parts[] = decl.split("\\, ");
|
||||
|
||||
for (String part : parts) {
|
||||
if (!part.trim().equals("")) {
|
||||
String blargh[] = part.split(" ");
|
||||
String theArg = blargh[1].replaceAll("[\\[\\]]", "");
|
||||
|
||||
if (prev != 0) {
|
||||
gline += ", ";
|
||||
rline += ", ";
|
||||
}
|
||||
|
||||
gline += theArg;
|
||||
rline += theArg;
|
||||
prev = 1;
|
||||
}
|
||||
}
|
||||
|
||||
gline += ");";
|
||||
rline += ");";
|
||||
|
||||
if (!gotStatic && returns.equals("")) {
|
||||
out.println(rline);
|
||||
}
|
||||
|
||||
out.println(gline);
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
|
||||
|
||||
private static BufferedReader createReader(File f) throws FileNotFoundException {
|
||||
return new BufferedReader(new InputStreamReader(new FileInputStream(f)));
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,504 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Numbers shared throughout processing.core.
|
||||
* <P>
|
||||
* An attempt is made to keep the constants as short/non-verbose
|
||||
* as possible. For instance, the constant is TIFF instead of
|
||||
* FILE_TYPE_TIFF. We'll do this as long as we can get away with it.
|
||||
*
|
||||
* @usage Web & Application
|
||||
*/
|
||||
public interface PConstants {
|
||||
|
||||
static public final int X = 0; // model coords xyz (formerly MX/MY/MZ)
|
||||
static public final int Y = 1;
|
||||
static public final int Z = 2;
|
||||
|
||||
static public final int R = 3; // actual rgb, after lighting
|
||||
static public final int G = 4; // fill stored here, transform in place
|
||||
static public final int B = 5; // TODO don't do that anymore (?)
|
||||
static public final int A = 6;
|
||||
|
||||
static public final int U = 7; // texture
|
||||
static public final int V = 8;
|
||||
|
||||
static public final int NX = 9; // normal
|
||||
static public final int NY = 10;
|
||||
static public final int NZ = 11;
|
||||
|
||||
static public final int EDGE = 12;
|
||||
|
||||
|
||||
// stroke
|
||||
|
||||
/** stroke argb values */
|
||||
static public final int SR = 13;
|
||||
static public final int SG = 14;
|
||||
static public final int SB = 15;
|
||||
static public final int SA = 16;
|
||||
|
||||
/** stroke weight */
|
||||
static public final int SW = 17;
|
||||
|
||||
|
||||
// transformations (2D and 3D)
|
||||
|
||||
static public final int TX = 18; // transformed xyzw
|
||||
static public final int TY = 19;
|
||||
static public final int TZ = 20;
|
||||
|
||||
static public final int VX = 21; // view space coords
|
||||
static public final int VY = 22;
|
||||
static public final int VZ = 23;
|
||||
static public final int VW = 24;
|
||||
|
||||
|
||||
// material properties
|
||||
|
||||
// Ambient color (usually to be kept the same as diffuse)
|
||||
// fill(_) sets both ambient and diffuse.
|
||||
static public final int AR = 25;
|
||||
static public final int AG = 26;
|
||||
static public final int AB = 27;
|
||||
|
||||
// Diffuse is shared with fill.
|
||||
static public final int DR = 3; // TODO needs to not be shared, this is a material property
|
||||
static public final int DG = 4;
|
||||
static public final int DB = 5;
|
||||
static public final int DA = 6;
|
||||
|
||||
// specular (by default kept white)
|
||||
static public final int SPR = 28;
|
||||
static public final int SPG = 29;
|
||||
static public final int SPB = 30;
|
||||
|
||||
static public final int SHINE = 31;
|
||||
|
||||
// emissive (by default kept black)
|
||||
static public final int ER = 32;
|
||||
static public final int EG = 33;
|
||||
static public final int EB = 34;
|
||||
|
||||
// has this vertex been lit yet
|
||||
static public final int BEEN_LIT = 35;
|
||||
|
||||
static public final int VERTEX_FIELD_COUNT = 36;
|
||||
|
||||
|
||||
// renderers known to processing.core
|
||||
|
||||
static final String P2D = "processing.core.PGraphics2D";
|
||||
static final String P3D = "processing.core.PGraphics3D";
|
||||
static final String JAVA2D = "processing.core.PGraphicsJava2D";
|
||||
static final String OPENGL = "processing.opengl.PGraphicsOpenGL";
|
||||
static final String PDF = "processing.pdf.PGraphicsPDF";
|
||||
static final String DXF = "processing.dxf.RawDXF";
|
||||
|
||||
|
||||
// platform IDs for PApplet.platform
|
||||
|
||||
static final int OTHER = 0;
|
||||
static final int WINDOWS = 1;
|
||||
static final int MACOSX = 2;
|
||||
static final int LINUX = 3;
|
||||
|
||||
static final String[] platformNames = {
|
||||
"other", "windows", "macosx", "linux"
|
||||
};
|
||||
|
||||
|
||||
static final float EPSILON = 0.0001f;
|
||||
|
||||
|
||||
// max/min values for numbers
|
||||
|
||||
/**
|
||||
* Same as Float.MAX_VALUE, but included for parity with MIN_VALUE,
|
||||
* and to avoid teaching static methods on the first day.
|
||||
*/
|
||||
static final float MAX_FLOAT = Float.MAX_VALUE;
|
||||
/**
|
||||
* Note that Float.MIN_VALUE is the smallest <EM>positive</EM> value
|
||||
* for a floating point number, not actually the minimum (negative) value
|
||||
* for a float. This constant equals 0xFF7FFFFF, the smallest (farthest
|
||||
* negative) value a float can have before it hits NaN.
|
||||
*/
|
||||
static final float MIN_FLOAT = -Float.MAX_VALUE;
|
||||
/** Largest possible (positive) integer value */
|
||||
static final int MAX_INT = Integer.MAX_VALUE;
|
||||
/** Smallest possible (negative) integer value */
|
||||
static final int MIN_INT = Integer.MIN_VALUE;
|
||||
|
||||
|
||||
// useful goodness
|
||||
|
||||
/**
|
||||
* PI is a mathematical constant with the value 3.14159265358979323846.
|
||||
* It is the ratio of the circumference of a circle to its diameter.
|
||||
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
|
||||
*
|
||||
* @webref constants
|
||||
* @see processing.core.PConstants#HALF_PI
|
||||
* @see processing.core.PConstants#TWO_PI
|
||||
* @see processing.core.PConstants#QUARTER_PI
|
||||
*
|
||||
*/
|
||||
static final float PI = (float) Math.PI;
|
||||
/**
|
||||
* HALF_PI is a mathematical constant with the value 1.57079632679489661923.
|
||||
* It is half the ratio of the circumference of a circle to its diameter.
|
||||
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
|
||||
*
|
||||
* @webref constants
|
||||
* @see processing.core.PConstants#PI
|
||||
* @see processing.core.PConstants#TWO_PI
|
||||
* @see processing.core.PConstants#QUARTER_PI
|
||||
*/
|
||||
static final float HALF_PI = PI / 2.0f;
|
||||
static final float THIRD_PI = PI / 3.0f;
|
||||
/**
|
||||
* QUARTER_PI is a mathematical constant with the value 0.7853982.
|
||||
* It is one quarter the ratio of the circumference of a circle to its diameter.
|
||||
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
|
||||
*
|
||||
* @webref constants
|
||||
* @see processing.core.PConstants#PI
|
||||
* @see processing.core.PConstants#TWO_PI
|
||||
* @see processing.core.PConstants#HALF_PI
|
||||
*/
|
||||
static final float QUARTER_PI = PI / 4.0f;
|
||||
/**
|
||||
* TWO_PI is a mathematical constant with the value 6.28318530717958647693.
|
||||
* It is twice the ratio of the circumference of a circle to its diameter.
|
||||
* It is useful in combination with the trigonometric functions <b>sin()</b> and <b>cos()</b>.
|
||||
*
|
||||
* @webref constants
|
||||
* @see processing.core.PConstants#PI
|
||||
* @see processing.core.PConstants#HALF_PI
|
||||
* @see processing.core.PConstants#QUARTER_PI
|
||||
*/
|
||||
static final float TWO_PI = PI * 2.0f;
|
||||
|
||||
static final float DEG_TO_RAD = PI/180.0f;
|
||||
static final float RAD_TO_DEG = 180.0f/PI;
|
||||
|
||||
|
||||
// angle modes
|
||||
|
||||
//static final int RADIANS = 0;
|
||||
//static final int DEGREES = 1;
|
||||
|
||||
|
||||
// used by split, all the standard whitespace chars
|
||||
// (also includes unicode nbsp, that little bostage)
|
||||
|
||||
static final String WHITESPACE = " \t\n\r\f\u00A0";
|
||||
|
||||
|
||||
// for colors and/or images
|
||||
|
||||
static final int RGB = 1; // image & color
|
||||
static final int ARGB = 2; // image
|
||||
static final int HSB = 3; // color
|
||||
static final int ALPHA = 4; // image
|
||||
static final int CMYK = 5; // image & color (someday)
|
||||
|
||||
|
||||
// image file types
|
||||
|
||||
static final int TIFF = 0;
|
||||
static final int TARGA = 1;
|
||||
static final int JPEG = 2;
|
||||
static final int GIF = 3;
|
||||
|
||||
|
||||
// filter/convert types
|
||||
|
||||
static final int BLUR = 11;
|
||||
static final int GRAY = 12;
|
||||
static final int INVERT = 13;
|
||||
static final int OPAQUE = 14;
|
||||
static final int POSTERIZE = 15;
|
||||
static final int THRESHOLD = 16;
|
||||
static final int ERODE = 17;
|
||||
static final int DILATE = 18;
|
||||
|
||||
|
||||
// blend mode keyword definitions
|
||||
// @see processing.core.PImage#blendColor(int,int,int)
|
||||
|
||||
public final static int REPLACE = 0;
|
||||
public final static int BLEND = 1 << 0;
|
||||
public final static int ADD = 1 << 1;
|
||||
public final static int SUBTRACT = 1 << 2;
|
||||
public final static int LIGHTEST = 1 << 3;
|
||||
public final static int DARKEST = 1 << 4;
|
||||
public final static int DIFFERENCE = 1 << 5;
|
||||
public final static int EXCLUSION = 1 << 6;
|
||||
public final static int MULTIPLY = 1 << 7;
|
||||
public final static int SCREEN = 1 << 8;
|
||||
public final static int OVERLAY = 1 << 9;
|
||||
public final static int HARD_LIGHT = 1 << 10;
|
||||
public final static int SOFT_LIGHT = 1 << 11;
|
||||
public final static int DODGE = 1 << 12;
|
||||
public final static int BURN = 1 << 13;
|
||||
|
||||
// colour component bitmasks
|
||||
|
||||
public static final int ALPHA_MASK = 0xff000000;
|
||||
public static final int RED_MASK = 0x00ff0000;
|
||||
public static final int GREEN_MASK = 0x0000ff00;
|
||||
public static final int BLUE_MASK = 0x000000ff;
|
||||
|
||||
|
||||
// for messages
|
||||
|
||||
static final int CHATTER = 0;
|
||||
static final int COMPLAINT = 1;
|
||||
static final int PROBLEM = 2;
|
||||
|
||||
|
||||
// types of projection matrices
|
||||
|
||||
static final int CUSTOM = 0; // user-specified fanciness
|
||||
static final int ORTHOGRAPHIC = 2; // 2D isometric projection
|
||||
static final int PERSPECTIVE = 3; // perspective matrix
|
||||
|
||||
|
||||
// shapes
|
||||
|
||||
// the low four bits set the variety,
|
||||
// higher bits set the specific shape type
|
||||
|
||||
//static final int GROUP = (1 << 2);
|
||||
|
||||
static final int POINT = 2; // shared with light (!)
|
||||
static final int POINTS = 2;
|
||||
|
||||
static final int LINE = 4;
|
||||
static final int LINES = 4;
|
||||
|
||||
static final int TRIANGLE = 8;
|
||||
static final int TRIANGLES = 9;
|
||||
static final int TRIANGLE_STRIP = 10;
|
||||
static final int TRIANGLE_FAN = 11;
|
||||
|
||||
static final int QUAD = 16;
|
||||
static final int QUADS = 16;
|
||||
static final int QUAD_STRIP = 17;
|
||||
|
||||
static final int POLYGON = 20;
|
||||
static final int PATH = 21;
|
||||
|
||||
static final int RECT = 30;
|
||||
static final int ELLIPSE = 31;
|
||||
static final int ARC = 32;
|
||||
|
||||
static final int SPHERE = 40;
|
||||
static final int BOX = 41;
|
||||
|
||||
|
||||
// shape closing modes
|
||||
|
||||
static final int OPEN = 1;
|
||||
static final int CLOSE = 2;
|
||||
|
||||
|
||||
// shape drawing modes
|
||||
|
||||
/** Draw mode convention to use (x, y) to (width, height) */
|
||||
static final int CORNER = 0;
|
||||
/** Draw mode convention to use (x1, y1) to (x2, y2) coordinates */
|
||||
static final int CORNERS = 1;
|
||||
/** Draw mode from the center, and using the radius */
|
||||
static final int RADIUS = 2;
|
||||
/** @deprecated Use RADIUS instead. */
|
||||
static final int CENTER_RADIUS = 2;
|
||||
/**
|
||||
* Draw from the center, using second pair of values as the diameter.
|
||||
* Formerly called CENTER_DIAMETER in alpha releases.
|
||||
*/
|
||||
static final int CENTER = 3;
|
||||
/**
|
||||
* Synonym for the CENTER constant. Draw from the center,
|
||||
* using second pair of values as the diameter.
|
||||
*/
|
||||
static final int DIAMETER = 3;
|
||||
/** @deprecated Use DIAMETER instead. */
|
||||
static final int CENTER_DIAMETER = 3;
|
||||
|
||||
|
||||
// vertically alignment modes for text
|
||||
|
||||
/** Default vertical alignment for text placement */
|
||||
static final int BASELINE = 0;
|
||||
/** Align text to the top */
|
||||
static final int TOP = 101;
|
||||
/** Align text from the bottom, using the baseline. */
|
||||
static final int BOTTOM = 102;
|
||||
|
||||
|
||||
// uv texture orientation modes
|
||||
|
||||
/** texture coordinates in 0..1 range */
|
||||
static final int NORMAL = 1;
|
||||
/** @deprecated use NORMAL instead */
|
||||
static final int NORMALIZED = 1;
|
||||
/** texture coordinates based on image width/height */
|
||||
static final int IMAGE = 2;
|
||||
|
||||
|
||||
// text placement modes
|
||||
|
||||
/**
|
||||
* textMode(MODEL) is the default, meaning that characters
|
||||
* will be affected by transformations like any other shapes.
|
||||
* <p/>
|
||||
* Changed value in 0093 to not interfere with LEFT, CENTER, and RIGHT.
|
||||
*/
|
||||
static final int MODEL = 4;
|
||||
|
||||
/**
|
||||
* textMode(SHAPE) draws text using the the glyph outlines of
|
||||
* individual characters rather than as textures. If the outlines are
|
||||
* not available, then textMode(SHAPE) will be ignored and textMode(MODEL)
|
||||
* will be used instead. For this reason, be sure to call textMode()
|
||||
* <EM>after</EM> calling textFont().
|
||||
* <p/>
|
||||
* Currently, textMode(SHAPE) is only supported by OPENGL mode.
|
||||
* It also requires Java 1.2 or higher (OPENGL requires 1.4 anyway)
|
||||
*/
|
||||
static final int SHAPE = 5;
|
||||
|
||||
|
||||
// text alignment modes
|
||||
// are inherited from LEFT, CENTER, RIGHT
|
||||
|
||||
|
||||
// stroke modes
|
||||
|
||||
static final int SQUARE = 1 << 0; // called 'butt' in the svg spec
|
||||
static final int ROUND = 1 << 1;
|
||||
static final int PROJECT = 1 << 2; // called 'square' in the svg spec
|
||||
static final int MITER = 1 << 3;
|
||||
static final int BEVEL = 1 << 5;
|
||||
|
||||
|
||||
// lighting
|
||||
|
||||
static final int AMBIENT = 0;
|
||||
static final int DIRECTIONAL = 1;
|
||||
//static final int POINT = 2; // shared with shape feature
|
||||
static final int SPOT = 3;
|
||||
|
||||
|
||||
// key constants
|
||||
|
||||
// only including the most-used of these guys
|
||||
// if people need more esoteric keys, they can learn about
|
||||
// the esoteric java KeyEvent api and of virtual keys
|
||||
|
||||
// both key and keyCode will equal these values
|
||||
// for 0125, these were changed to 'char' values, because they
|
||||
// can be upgraded to ints automatically by Java, but having them
|
||||
// as ints prevented split(blah, TAB) from working
|
||||
static final char BACKSPACE = 8;
|
||||
static final char TAB = 9;
|
||||
static final char ENTER = 10;
|
||||
static final char RETURN = 13;
|
||||
static final char ESC = 27;
|
||||
static final char DELETE = 127;
|
||||
|
||||
// i.e. if ((key == CODED) && (keyCode == UP))
|
||||
static final int CODED = 0xffff;
|
||||
|
||||
// key will be CODED and keyCode will be this value
|
||||
static final int UP = KeyEvent.VK_UP;
|
||||
static final int DOWN = KeyEvent.VK_DOWN;
|
||||
static final int LEFT = KeyEvent.VK_LEFT;
|
||||
static final int RIGHT = KeyEvent.VK_RIGHT;
|
||||
|
||||
// key will be CODED and keyCode will be this value
|
||||
static final int ALT = KeyEvent.VK_ALT;
|
||||
static final int CONTROL = KeyEvent.VK_CONTROL;
|
||||
static final int SHIFT = KeyEvent.VK_SHIFT;
|
||||
|
||||
|
||||
// cursor types
|
||||
|
||||
static final int ARROW = Cursor.DEFAULT_CURSOR;
|
||||
static final int CROSS = Cursor.CROSSHAIR_CURSOR;
|
||||
static final int HAND = Cursor.HAND_CURSOR;
|
||||
static final int MOVE = Cursor.MOVE_CURSOR;
|
||||
static final int TEXT = Cursor.TEXT_CURSOR;
|
||||
static final int WAIT = Cursor.WAIT_CURSOR;
|
||||
|
||||
|
||||
// hints - hint values are positive for the alternate version,
|
||||
// negative of the same value returns to the normal/default state
|
||||
|
||||
static final int DISABLE_OPENGL_2X_SMOOTH = 1;
|
||||
static final int ENABLE_OPENGL_2X_SMOOTH = -1;
|
||||
static final int ENABLE_OPENGL_4X_SMOOTH = 2;
|
||||
|
||||
static final int ENABLE_NATIVE_FONTS = 3;
|
||||
|
||||
static final int DISABLE_DEPTH_TEST = 4;
|
||||
static final int ENABLE_DEPTH_TEST = -4;
|
||||
|
||||
static final int ENABLE_DEPTH_SORT = 5;
|
||||
static final int DISABLE_DEPTH_SORT = -5;
|
||||
|
||||
static final int DISABLE_OPENGL_ERROR_REPORT = 6;
|
||||
static final int ENABLE_OPENGL_ERROR_REPORT = -6;
|
||||
|
||||
static final int ENABLE_ACCURATE_TEXTURES = 7;
|
||||
static final int DISABLE_ACCURATE_TEXTURES = -7;
|
||||
|
||||
static final int HINT_COUNT = 10;
|
||||
|
||||
|
||||
// error messages
|
||||
|
||||
static final String ERROR_BACKGROUND_IMAGE_SIZE =
|
||||
"background image must be the same size as your application";
|
||||
static final String ERROR_BACKGROUND_IMAGE_FORMAT =
|
||||
"background images should be RGB or ARGB";
|
||||
|
||||
static final String ERROR_TEXTFONT_NULL_PFONT =
|
||||
"A null PFont was passed to textFont()";
|
||||
|
||||
static final String ERROR_PUSHMATRIX_OVERFLOW =
|
||||
"Too many calls to pushMatrix().";
|
||||
static final String ERROR_PUSHMATRIX_UNDERFLOW =
|
||||
"Too many calls to popMatrix(), and not enough to pushMatrix().";
|
||||
}
|
@ -1,877 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-10 Ben Fry & Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of version 2.01 of the GNU Lesser General
|
||||
Public License as published by the Free Software Foundation.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* Grayscale bitmap font class used by Processing.
|
||||
* <P>
|
||||
* Awful (and by that, I mean awesome) ASCII (non-)art for how this works:
|
||||
* <PRE>
|
||||
* |
|
||||
* | height is the full used height of the image
|
||||
* |
|
||||
* | ..XX.. }
|
||||
* | ..XX.. }
|
||||
* | ...... }
|
||||
* | XXXX.. } topExtent (top y is baseline - topExtent)
|
||||
* | ..XX.. }
|
||||
* | ..XX.. } dotted areas are where the image data
|
||||
* | ..XX.. } is actually located for the character
|
||||
* +---XXXXXX---- } (it extends to the right and down
|
||||
* | for power of two texture sizes)
|
||||
* ^^^^ leftExtent (amount to move over before drawing the image
|
||||
*
|
||||
* ^^^^^^^^^^^^^^ setWidth (width displaced by char)
|
||||
* </PRE>
|
||||
*/
|
||||
public class PFont implements PConstants {
|
||||
|
||||
/** Number of character glyphs in this font. */
|
||||
protected int glyphCount;
|
||||
|
||||
/**
|
||||
* Actual glyph data. The length of this array won't necessarily be the
|
||||
* same size as glyphCount, in cases where lazy font loading is in use.
|
||||
*/
|
||||
protected Glyph[] glyphs;
|
||||
|
||||
/**
|
||||
* Name of the font as seen by Java when it was created.
|
||||
* If the font is available, the native version will be used.
|
||||
*/
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* Postscript name of the font that this bitmap was created from.
|
||||
*/
|
||||
protected String psname;
|
||||
|
||||
/**
|
||||
* The original size of the font when it was first created
|
||||
*/
|
||||
protected int size;
|
||||
|
||||
/** true if smoothing was enabled for this font, used for native impl */
|
||||
protected boolean smooth;
|
||||
|
||||
/**
|
||||
* The ascent of the font. If the 'd' character is present in this PFont,
|
||||
* this value is replaced with its pixel height, because the values returned
|
||||
* by FontMetrics.getAscent() seem to be terrible.
|
||||
*/
|
||||
protected int ascent;
|
||||
|
||||
/**
|
||||
* The descent of the font. If the 'p' character is present in this PFont,
|
||||
* this value is replaced with its lowest pixel height, because the values
|
||||
* returned by FontMetrics.getDescent() are gross.
|
||||
*/
|
||||
protected int descent;
|
||||
|
||||
/**
|
||||
* A more efficient array lookup for straight ASCII characters. For Unicode
|
||||
* characters, a QuickSort-style search is used.
|
||||
*/
|
||||
protected int[] ascii;
|
||||
|
||||
/**
|
||||
* True if this font is set to load dynamically. This is the default when
|
||||
* createFont() method is called without a character set. Bitmap versions of
|
||||
* characters are only created when prompted by an index() call.
|
||||
*/
|
||||
protected boolean lazy;
|
||||
|
||||
/**
|
||||
* Native Java version of the font. If possible, this allows the
|
||||
* PGraphics subclass to just use Java's font rendering stuff
|
||||
* in situations where that's faster.
|
||||
*/
|
||||
protected Font font;
|
||||
|
||||
/** True if this font was loaded from a stream, rather than from the OS. */
|
||||
protected boolean stream;
|
||||
|
||||
/**
|
||||
* True if we've already tried to find the native AWT version of this font.
|
||||
*/
|
||||
protected boolean fontSearched;
|
||||
|
||||
/**
|
||||
* Array of the native system fonts. Used to lookup native fonts by their
|
||||
* PostScript name. This is a workaround for a several year old Apple Java
|
||||
* bug that they can't be bothered to fix.
|
||||
*/
|
||||
static protected Font[] fonts;
|
||||
static protected HashMap<String,Font> fontDifferent;
|
||||
|
||||
|
||||
// objects to handle creation of font characters only as they're needed
|
||||
BufferedImage lazyImage;
|
||||
Graphics2D lazyGraphics;
|
||||
FontMetrics lazyMetrics;
|
||||
int[] lazySamples;
|
||||
|
||||
|
||||
public PFont() { } // for subclasses
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Processing font from a native font, but don't create all the
|
||||
* characters at once, instead wait until they're used to include them.
|
||||
* @param font
|
||||
* @param smooth
|
||||
*/
|
||||
public PFont(Font font, boolean smooth) {
|
||||
this(font, smooth, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new image-based font on the fly. If charset is set to null,
|
||||
* the characters will only be created as bitmaps when they're drawn.
|
||||
*
|
||||
* @param font the font object to create from
|
||||
* @param charset array of all unicode chars that should be included
|
||||
* @param smooth true to enable smoothing/anti-aliasing
|
||||
*/
|
||||
public PFont(Font font, boolean smooth, char charset[]) {
|
||||
// save this so that we can use the native version
|
||||
this.font = font;
|
||||
this.smooth = smooth;
|
||||
|
||||
name = font.getName();
|
||||
psname = font.getPSName();
|
||||
size = font.getSize();
|
||||
|
||||
// no, i'm not interested in getting off the couch
|
||||
lazy = true;
|
||||
// not sure what else to do here
|
||||
//mbox2 = 0;
|
||||
|
||||
int initialCount = 10;
|
||||
glyphs = new Glyph[initialCount];
|
||||
|
||||
ascii = new int[128];
|
||||
Arrays.fill(ascii, -1);
|
||||
|
||||
int mbox3 = size * 3;
|
||||
|
||||
lazyImage = new BufferedImage(mbox3, mbox3, BufferedImage.TYPE_INT_RGB);
|
||||
lazyGraphics = (Graphics2D) lazyImage.getGraphics();
|
||||
lazyGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
smooth ?
|
||||
RenderingHints.VALUE_ANTIALIAS_ON :
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
// adding this for post-1.0.9
|
||||
lazyGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
smooth ?
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON :
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
|
||||
lazyGraphics.setFont(font);
|
||||
lazyMetrics = lazyGraphics.getFontMetrics();
|
||||
lazySamples = new int[mbox3 * mbox3];
|
||||
|
||||
// These values are terrible/unusable. Verified again for Processing 1.1.
|
||||
// They vary widely per-platform and per-font, so instead we'll use the
|
||||
// calculate-by-hand method of measuring pixels in characters.
|
||||
//ascent = lazyMetrics.getAscent();
|
||||
//descent = lazyMetrics.getDescent();
|
||||
|
||||
if (charset != null) {
|
||||
// charset needs to be sorted to make index lookup run more quickly
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=494
|
||||
Arrays.sort(charset);
|
||||
|
||||
glyphs = new Glyph[charset.length];
|
||||
|
||||
glyphCount = 0;
|
||||
for (char c : charset) {
|
||||
if (font.canDisplay(c)) {
|
||||
glyphs[glyphCount++] = new Glyph(c);
|
||||
}
|
||||
}
|
||||
|
||||
// shorten the array if necessary
|
||||
if (glyphCount != charset.length) {
|
||||
glyphs = (Glyph[]) PApplet.subset(glyphs, 0, glyphCount);
|
||||
}
|
||||
|
||||
// foreign font, so just make ascent the max topExtent
|
||||
// for > 1.0.9, not doing this anymore.
|
||||
// instead using getAscent() and getDescent() values for these cases.
|
||||
// if ((ascent == 0) && (descent == 0)) {
|
||||
// //for (int i = 0; i < charCount; i++) {
|
||||
// for (Glyph glyph : glyphs) {
|
||||
// char cc = (char) glyph.value;
|
||||
// //char cc = (char) glyphs[i].value;
|
||||
// if (Character.isWhitespace(cc) ||
|
||||
// (cc == '\u00A0') || (cc == '\u2007') || (cc == '\u202F')) {
|
||||
// continue;
|
||||
// }
|
||||
// if (glyph.topExtent > ascent) {
|
||||
// ascent = glyph.topExtent;
|
||||
// }
|
||||
// int d = -glyph.topExtent + glyph.height;
|
||||
// if (d > descent) {
|
||||
// descent = d;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// If not already created, just create these two characters to calculate
|
||||
// the ascent and descent values for the font. This was tested to only
|
||||
// require 5-10 ms on a 2.4 GHz MacBook Pro.
|
||||
// In versions 1.0.9 and earlier, fonts that could not display d or p
|
||||
// used the max up/down values as calculated by looking through the font.
|
||||
// That's no longer valid with the auto-generating fonts, so we'll just
|
||||
// use getAscent() and getDescent() in such (minor) cases.
|
||||
if (ascent == 0) {
|
||||
if (font.canDisplay('d')) {
|
||||
new Glyph('d');
|
||||
} else {
|
||||
ascent = lazyMetrics.getAscent();
|
||||
}
|
||||
}
|
||||
if (descent == 0) {
|
||||
if (font.canDisplay('p')) {
|
||||
new Glyph('p');
|
||||
} else {
|
||||
descent = lazyMetrics.getDescent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an additional parameter that indicates the font came from a file,
|
||||
* not a built-in OS font.
|
||||
*/
|
||||
public PFont(Font font, boolean smooth, char charset[], boolean stream) {
|
||||
this(font, smooth, charset);
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
|
||||
public PFont(InputStream input) throws IOException {
|
||||
DataInputStream is = new DataInputStream(input);
|
||||
|
||||
// number of character images stored in this font
|
||||
glyphCount = is.readInt();
|
||||
|
||||
// used to be the bitCount, but now used for version number.
|
||||
// version 8 is any font before 69, so 9 is anything from 83+
|
||||
// 9 was buggy so gonna increment to 10.
|
||||
int version = is.readInt();
|
||||
|
||||
// this was formerly ignored, now it's the actual font size
|
||||
//mbox = is.readInt();
|
||||
size = is.readInt();
|
||||
|
||||
// this was formerly mboxY, the one that was used
|
||||
// this will make new fonts downward compatible
|
||||
is.readInt(); // ignore the other mbox attribute
|
||||
|
||||
ascent = is.readInt(); // formerly baseHt (zero/ignored)
|
||||
descent = is.readInt(); // formerly ignored struct padding
|
||||
|
||||
// allocate enough space for the character info
|
||||
glyphs = new Glyph[glyphCount];
|
||||
|
||||
ascii = new int[128];
|
||||
Arrays.fill(ascii, -1);
|
||||
|
||||
// read the information about the individual characters
|
||||
for (int i = 0; i < glyphCount; i++) {
|
||||
Glyph glyph = new Glyph(is);
|
||||
// cache locations of the ascii charset
|
||||
if (glyph.value < 128) {
|
||||
ascii[glyph.value] = i;
|
||||
}
|
||||
glyphs[i] = glyph;
|
||||
}
|
||||
|
||||
// not a roman font, so throw an error and ask to re-build.
|
||||
// that way can avoid a bunch of error checking hacks in here.
|
||||
if ((ascent == 0) && (descent == 0)) {
|
||||
throw new RuntimeException("Please use \"Create Font\" to " +
|
||||
"re-create this font.");
|
||||
}
|
||||
|
||||
for (Glyph glyph : glyphs) {
|
||||
glyph.readBitmap(is);
|
||||
}
|
||||
|
||||
if (version >= 10) { // includes the font name at the end of the file
|
||||
name = is.readUTF();
|
||||
psname = is.readUTF();
|
||||
}
|
||||
if (version == 11) {
|
||||
smooth = is.readBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write this PFont to an OutputStream.
|
||||
* <p>
|
||||
* This is used by the Create Font tool, or whatever anyone else dreams
|
||||
* up for messing with fonts themselves.
|
||||
* <p>
|
||||
* It is assumed that the calling class will handle closing
|
||||
* the stream when finished.
|
||||
*/
|
||||
public void save(OutputStream output) throws IOException {
|
||||
DataOutputStream os = new DataOutputStream(output);
|
||||
|
||||
os.writeInt(glyphCount);
|
||||
|
||||
if ((name == null) || (psname == null)) {
|
||||
name = "";
|
||||
psname = "";
|
||||
}
|
||||
|
||||
os.writeInt(11); // formerly numBits, now used for version number
|
||||
os.writeInt(size); // formerly mboxX (was 64, now 48)
|
||||
os.writeInt(0); // formerly mboxY, now ignored
|
||||
os.writeInt(ascent); // formerly baseHt (was ignored)
|
||||
os.writeInt(descent); // formerly struct padding for c version
|
||||
|
||||
for (int i = 0; i < glyphCount; i++) {
|
||||
glyphs[i].writeHeader(os);
|
||||
}
|
||||
|
||||
for (int i = 0; i < glyphCount; i++) {
|
||||
glyphs[i].writeBitmap(os);
|
||||
}
|
||||
|
||||
// version 11
|
||||
os.writeUTF(name);
|
||||
os.writeUTF(psname);
|
||||
os.writeBoolean(smooth);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new glyph, and add the character to the current font.
|
||||
* @param c character to create an image for.
|
||||
*/
|
||||
protected void addGlyph(char c) {
|
||||
Glyph glyph = new Glyph(c);
|
||||
|
||||
if (glyphCount == glyphs.length) {
|
||||
glyphs = (Glyph[]) PApplet.expand(glyphs);
|
||||
}
|
||||
if (glyphCount == 0) {
|
||||
glyphs[glyphCount] = glyph;
|
||||
if (glyph.value < 128) {
|
||||
ascii[glyph.value] = 0;
|
||||
}
|
||||
|
||||
} else if (glyphs[glyphCount-1].value < glyph.value) {
|
||||
glyphs[glyphCount] = glyph;
|
||||
if (glyph.value < 128) {
|
||||
ascii[glyph.value] = glyphCount;
|
||||
}
|
||||
|
||||
} else {
|
||||
for (int i = 0; i < glyphCount; i++) {
|
||||
if (glyphs[i].value > c) {
|
||||
for (int j = glyphCount; j > i; --j) {
|
||||
glyphs[j] = glyphs[j-1];
|
||||
if (glyphs[j].value < 128) {
|
||||
ascii[glyphs[j].value] = j;
|
||||
}
|
||||
}
|
||||
glyphs[i] = glyph;
|
||||
// cache locations of the ascii charset
|
||||
if (c < 128) ascii[c] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
glyphCount++;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public String getPostScriptName() {
|
||||
return psname;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the native complement of this font.
|
||||
*/
|
||||
public void setFont(Font font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the native java.awt.Font associated with this PFont (if any).
|
||||
*/
|
||||
public Font getFont() {
|
||||
// if (font == null && !fontSearched) {
|
||||
// font = findFont();
|
||||
// }
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
public boolean isStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to find the native version of this font.
|
||||
* (Public so that it can be used by OpenGL or other renderers.)
|
||||
*/
|
||||
public Font findFont() {
|
||||
if (font == null) {
|
||||
if (!fontSearched) {
|
||||
// this font may or may not be installed
|
||||
font = new Font(name, Font.PLAIN, size);
|
||||
// if the ps name matches, then we're in fine shape
|
||||
if (!font.getPSName().equals(psname)) {
|
||||
// on osx java 1.4 (not 1.3.. ugh), you can specify the ps name
|
||||
// of the font, so try that in case this .vlw font was created on pc
|
||||
// and the name is different, but the ps name is found on the
|
||||
// java 1.4 mac that's currently running this sketch.
|
||||
font = new Font(psname, Font.PLAIN, size);
|
||||
}
|
||||
// check again, and if still bad, screw em
|
||||
if (!font.getPSName().equals(psname)) {
|
||||
font = null;
|
||||
}
|
||||
fontSearched = true;
|
||||
}
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
public Glyph getGlyph(char c) {
|
||||
int index = index(c);
|
||||
return (index == -1) ? null : glyphs[index];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get index for the character.
|
||||
* @return index into arrays or -1 if not found
|
||||
*/
|
||||
protected int index(char c) {
|
||||
if (lazy) {
|
||||
int index = indexActual(c);
|
||||
if (index != -1) {
|
||||
return index;
|
||||
}
|
||||
if (font.canDisplay(c)) {
|
||||
// create the glyph
|
||||
addGlyph(c);
|
||||
// now where did i put that?
|
||||
return indexActual(c);
|
||||
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
return indexActual(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected int indexActual(char c) {
|
||||
// degenerate case, but the find function will have trouble
|
||||
// if there are somehow zero chars in the lookup
|
||||
//if (value.length == 0) return -1;
|
||||
if (glyphCount == 0) return -1;
|
||||
|
||||
// quicker lookup for the ascii fellers
|
||||
if (c < 128) return ascii[c];
|
||||
|
||||
// some other unicode char, hunt it out
|
||||
//return index_hunt(c, 0, value.length-1);
|
||||
return indexHunt(c, 0, glyphCount-1);
|
||||
}
|
||||
|
||||
|
||||
protected int indexHunt(int c, int start, int stop) {
|
||||
int pivot = (start + stop) / 2;
|
||||
|
||||
// if this is the char, then return it
|
||||
if (c == glyphs[pivot].value) return pivot;
|
||||
|
||||
// char doesn't exist, otherwise would have been the pivot
|
||||
//if (start == stop) return -1;
|
||||
if (start >= stop) return -1;
|
||||
|
||||
// if it's in the lower half, continue searching that
|
||||
if (c < glyphs[pivot].value) return indexHunt(c, start, pivot-1);
|
||||
|
||||
// if it's in the upper half, continue there
|
||||
return indexHunt(c, pivot+1, stop);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Currently un-implemented for .vlw fonts,
|
||||
* but honored for layout in case subclasses use it.
|
||||
*/
|
||||
public float kern(char a, char b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the ascent of this font from the baseline.
|
||||
* The value is based on a font of size 1.
|
||||
*/
|
||||
public float ascent() {
|
||||
return ((float) ascent / (float) size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns how far this font descends from the baseline.
|
||||
* The value is based on a font size of 1.
|
||||
*/
|
||||
public float descent() {
|
||||
return ((float) descent / (float) size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Width of this character for a font of size 1.
|
||||
*/
|
||||
public float width(char c) {
|
||||
if (c == 32) return width('i');
|
||||
|
||||
int cc = index(c);
|
||||
if (cc == -1) return 0;
|
||||
|
||||
return ((float) glyphs[cc].setWidth / (float) size);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
static final char[] EXTRA_CHARS = {
|
||||
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
|
||||
0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
||||
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
|
||||
0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00BA,
|
||||
0x00BB, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5,
|
||||
0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD,
|
||||
0x00CE, 0x00CF, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6,
|
||||
0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8,
|
||||
0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FF, 0x0102, 0x0103,
|
||||
0x0104, 0x0105, 0x0106, 0x0107, 0x010C, 0x010D, 0x010E, 0x010F,
|
||||
0x0110, 0x0111, 0x0118, 0x0119, 0x011A, 0x011B, 0x0131, 0x0139,
|
||||
0x013A, 0x013D, 0x013E, 0x0141, 0x0142, 0x0143, 0x0144, 0x0147,
|
||||
0x0148, 0x0150, 0x0151, 0x0152, 0x0153, 0x0154, 0x0155, 0x0158,
|
||||
0x0159, 0x015A, 0x015B, 0x015E, 0x015F, 0x0160, 0x0161, 0x0162,
|
||||
0x0163, 0x0164, 0x0165, 0x016E, 0x016F, 0x0170, 0x0171, 0x0178,
|
||||
0x0179, 0x017A, 0x017B, 0x017C, 0x017D, 0x017E, 0x0192, 0x02C6,
|
||||
0x02C7, 0x02D8, 0x02D9, 0x02DA, 0x02DB, 0x02DC, 0x02DD, 0x03A9,
|
||||
0x03C0, 0x2013, 0x2014, 0x2018, 0x2019, 0x201A, 0x201C, 0x201D,
|
||||
0x201E, 0x2020, 0x2021, 0x2022, 0x2026, 0x2030, 0x2039, 0x203A,
|
||||
0x2044, 0x20AC, 0x2122, 0x2202, 0x2206, 0x220F, 0x2211, 0x221A,
|
||||
0x221E, 0x222B, 0x2248, 0x2260, 0x2264, 0x2265, 0x25CA, 0xF8FF,
|
||||
0xFB01, 0xFB02
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The default Processing character set.
|
||||
* <P>
|
||||
* This is the union of the Mac Roman and Windows ANSI (CP1250)
|
||||
* character sets. ISO 8859-1 Latin 1 is Unicode characters 0x80 -> 0xFF,
|
||||
* and would seem a good standard, but in practice, most P5 users would
|
||||
* rather have characters that they expect from their platform's fonts.
|
||||
* <P>
|
||||
* This is more of an interim solution until a much better
|
||||
* font solution can be determined. (i.e. create fonts on
|
||||
* the fly from some sort of vector format).
|
||||
* <P>
|
||||
* Not that I expect that to happen.
|
||||
*/
|
||||
static public char[] CHARSET;
|
||||
static {
|
||||
CHARSET = new char[126-33+1 + EXTRA_CHARS.length];
|
||||
int index = 0;
|
||||
for (int i = 33; i <= 126; i++) {
|
||||
CHARSET[index++] = (char)i;
|
||||
}
|
||||
for (int i = 0; i < EXTRA_CHARS.length; i++) {
|
||||
CHARSET[index++] = EXTRA_CHARS[i];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of the fonts installed on the system that can be used
|
||||
* by Java. Not all fonts can be used in Java, in fact it's mostly
|
||||
* only TrueType fonts. OpenType fonts with CFF data such as Adobe's
|
||||
* OpenType fonts seem to have trouble (even though they're sort of
|
||||
* TrueType fonts as well, or may have a .ttf extension). Regular
|
||||
* PostScript fonts seem to work OK, however.
|
||||
* <P>
|
||||
* Not recommended for use in applets, but this is implemented
|
||||
* in PFont because the Java methods to access this information
|
||||
* have changed between 1.1 and 1.4, and the 1.4 method is
|
||||
* typical of the sort of undergraduate-level over-abstraction
|
||||
* that the seems to have made its way into the Java API after 1.1.
|
||||
*/
|
||||
static public String[] list() {
|
||||
loadFonts();
|
||||
String list[] = new String[fonts.length];
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
list[i] = fonts[i].getName();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
static public void loadFonts() {
|
||||
if (fonts == null) {
|
||||
GraphicsEnvironment ge =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
fonts = ge.getAllFonts();
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
fontDifferent = new HashMap<String,Font>();
|
||||
for (Font font : fonts) {
|
||||
// getName() returns the PostScript name on OS X 10.6 w/ Java 6.
|
||||
fontDifferent.put(font.getName(), font);
|
||||
//fontDifferent.put(font.getPSName(), font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starting with Java 1.5, Apple broke the ability to specify most fonts.
|
||||
* This bug was filed years ago as #4769141 at bugreporter.apple.com. More:
|
||||
* <a href="http://dev.processing.org/bugs/show_bug.cgi?id=407">Bug 407</a>.
|
||||
*/
|
||||
static public Font findFont(String name) {
|
||||
loadFonts();
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
Font maybe = fontDifferent.get(name);
|
||||
if (maybe != null) {
|
||||
return maybe;
|
||||
}
|
||||
// for (int i = 0; i < fonts.length; i++) {
|
||||
// if (name.equals(fonts[i].getName())) {
|
||||
// return fonts[i];
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return new Font(name, Font.PLAIN, 1);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* A single character, and its visage.
|
||||
*/
|
||||
public class Glyph {
|
||||
PImage image;
|
||||
int value;
|
||||
int height;
|
||||
int width;
|
||||
int setWidth;
|
||||
int topExtent;
|
||||
int leftExtent;
|
||||
|
||||
|
||||
protected Glyph() {
|
||||
// used when reading from a stream or for subclasses
|
||||
}
|
||||
|
||||
|
||||
protected Glyph(DataInputStream is) throws IOException {
|
||||
readHeader(is);
|
||||
}
|
||||
|
||||
|
||||
protected void readHeader(DataInputStream is) throws IOException {
|
||||
value = is.readInt();
|
||||
height = is.readInt();
|
||||
width = is.readInt();
|
||||
setWidth = is.readInt();
|
||||
topExtent = is.readInt();
|
||||
leftExtent = is.readInt();
|
||||
|
||||
// pointer from a struct in the c version, ignored
|
||||
is.readInt();
|
||||
|
||||
// the values for getAscent() and getDescent() from FontMetrics
|
||||
// seem to be way too large.. perhaps they're the max?
|
||||
// as such, use a more traditional marker for ascent/descent
|
||||
if (value == 'd') {
|
||||
if (ascent == 0) ascent = topExtent;
|
||||
}
|
||||
if (value == 'p') {
|
||||
if (descent == 0) descent = -topExtent + height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void writeHeader(DataOutputStream os) throws IOException {
|
||||
os.writeInt(value);
|
||||
os.writeInt(height);
|
||||
os.writeInt(width);
|
||||
os.writeInt(setWidth);
|
||||
os.writeInt(topExtent);
|
||||
os.writeInt(leftExtent);
|
||||
os.writeInt(0); // padding
|
||||
}
|
||||
|
||||
|
||||
protected void readBitmap(DataInputStream is) throws IOException {
|
||||
image = new PImage(width, height, ALPHA);
|
||||
int bitmapSize = width * height;
|
||||
|
||||
byte[] temp = new byte[bitmapSize];
|
||||
is.readFully(temp);
|
||||
|
||||
// convert the bitmap to an alpha channel
|
||||
int w = width;
|
||||
int h = height;
|
||||
int[] pixels = image.pixels;
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
pixels[y * width + x] = temp[y*w + x] & 0xff;
|
||||
// System.out.print((image.pixels[y*64+x] > 128) ? "*" : ".");
|
||||
}
|
||||
// System.out.println();
|
||||
}
|
||||
// System.out.println();
|
||||
}
|
||||
|
||||
|
||||
protected void writeBitmap(DataOutputStream os) throws IOException {
|
||||
int[] pixels = image.pixels;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
os.write(pixels[y * width + x] & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected Glyph(char c) {
|
||||
int mbox3 = size * 3;
|
||||
lazyGraphics.setColor(Color.white);
|
||||
lazyGraphics.fillRect(0, 0, mbox3, mbox3);
|
||||
lazyGraphics.setColor(Color.black);
|
||||
lazyGraphics.drawString(String.valueOf(c), size, size * 2);
|
||||
|
||||
WritableRaster raster = lazyImage.getRaster();
|
||||
raster.getDataElements(0, 0, mbox3, mbox3, lazySamples);
|
||||
|
||||
int minX = 1000, maxX = 0;
|
||||
int minY = 1000, maxY = 0;
|
||||
boolean pixelFound = false;
|
||||
|
||||
for (int y = 0; y < mbox3; y++) {
|
||||
for (int x = 0; x < mbox3; x++) {
|
||||
int sample = lazySamples[y * mbox3 + x] & 0xff;
|
||||
if (sample != 255) {
|
||||
if (x < minX) minX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
pixelFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pixelFound) {
|
||||
minX = minY = 0;
|
||||
maxX = maxY = 0;
|
||||
// this will create a 1 pixel white (clear) character..
|
||||
// maybe better to set one to -1 so nothing is added?
|
||||
}
|
||||
|
||||
value = c;
|
||||
height = (maxY - minY) + 1;
|
||||
width = (maxX - minX) + 1;
|
||||
setWidth = lazyMetrics.charWidth(c);
|
||||
|
||||
// offset from vertical location of baseline
|
||||
// of where the char was drawn (size*2)
|
||||
topExtent = size*2 - minY;
|
||||
|
||||
// offset from left of where coord was drawn
|
||||
leftExtent = minX - size;
|
||||
|
||||
image = new PImage(width, height, ALPHA);
|
||||
int[] pixels = image.pixels;
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
int val = 255 - (lazySamples[y * mbox3 + x] & 0xff);
|
||||
int pindex = (y - minY) * width + (x - minX);
|
||||
pixels[pindex] = val;
|
||||
}
|
||||
}
|
||||
|
||||
// replace the ascent/descent values with something.. err, decent.
|
||||
if (value == 'd') {
|
||||
if (ascent == 0) ascent = topExtent;
|
||||
}
|
||||
if (value == 'p') {
|
||||
if (descent == 0) descent = -topExtent + height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,150 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2005-08 Ben Fry and Casey Reas
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
|
||||
public interface PMatrix {
|
||||
|
||||
public void reset();
|
||||
|
||||
/**
|
||||
* Returns a copy of this PMatrix.
|
||||
*/
|
||||
public PMatrix get();
|
||||
|
||||
/**
|
||||
* Copies the matrix contents into a float array.
|
||||
* If target is null (or not the correct size), a new array will be created.
|
||||
*/
|
||||
public float[] get(float[] target);
|
||||
|
||||
|
||||
public void set(PMatrix src);
|
||||
|
||||
public void set(float[] source);
|
||||
|
||||
public void set(float m00, float m01, float m02,
|
||||
float m10, float m11, float m12);
|
||||
|
||||
public void set(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33);
|
||||
|
||||
|
||||
public void translate(float tx, float ty);
|
||||
|
||||
public void translate(float tx, float ty, float tz);
|
||||
|
||||
public void rotate(float angle);
|
||||
|
||||
public void rotateX(float angle);
|
||||
|
||||
public void rotateY(float angle);
|
||||
|
||||
public void rotateZ(float angle);
|
||||
|
||||
public void rotate(float angle, float v0, float v1, float v2);
|
||||
|
||||
public void scale(float s);
|
||||
|
||||
public void scale(float sx, float sy);
|
||||
|
||||
public void scale(float x, float y, float z);
|
||||
|
||||
public void skewX(float angle);
|
||||
|
||||
public void skewY(float angle);
|
||||
|
||||
/**
|
||||
* Multiply this matrix by another.
|
||||
*/
|
||||
public void apply(PMatrix source);
|
||||
|
||||
public void apply(PMatrix2D source);
|
||||
|
||||
public void apply(PMatrix3D source);
|
||||
|
||||
public void apply(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12);
|
||||
|
||||
public void apply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33);
|
||||
|
||||
/**
|
||||
* Apply another matrix to the left of this one.
|
||||
*/
|
||||
public void preApply(PMatrix2D left);
|
||||
|
||||
public void preApply(PMatrix3D left);
|
||||
|
||||
public void preApply(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12);
|
||||
|
||||
public void preApply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33);
|
||||
|
||||
|
||||
/**
|
||||
* Multiply a PVector by this matrix.
|
||||
*/
|
||||
public PVector mult(PVector source, PVector target);
|
||||
|
||||
|
||||
/**
|
||||
* Multiply a multi-element vector against this matrix.
|
||||
*/
|
||||
public float[] mult(float[] source, float[] target);
|
||||
|
||||
|
||||
// public float multX(float x, float y);
|
||||
// public float multY(float x, float y);
|
||||
|
||||
// public float multX(float x, float y, float z);
|
||||
// public float multY(float x, float y, float z);
|
||||
// public float multZ(float x, float y, float z);
|
||||
|
||||
|
||||
/**
|
||||
* Transpose this matrix.
|
||||
*/
|
||||
public void transpose();
|
||||
|
||||
|
||||
/**
|
||||
* Invert this matrix.
|
||||
* @return true if successful
|
||||
*/
|
||||
public boolean invert();
|
||||
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public float determinant();
|
||||
}
|
@ -1,450 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2005-08 Ben Fry and Casey Reas
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
|
||||
/**
|
||||
* 3x2 affine matrix implementation.
|
||||
*/
|
||||
public class PMatrix2D implements PMatrix {
|
||||
|
||||
public float m00, m01, m02;
|
||||
public float m10, m11, m12;
|
||||
|
||||
|
||||
public PMatrix2D() {
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
public PMatrix2D(float m00, float m01, float m02,
|
||||
float m10, float m11, float m12) {
|
||||
set(m00, m01, m02,
|
||||
m10, m11, m12);
|
||||
}
|
||||
|
||||
|
||||
public PMatrix2D(PMatrix matrix) {
|
||||
set(matrix);
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
set(1, 0, 0,
|
||||
0, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a copy of this PMatrix.
|
||||
*/
|
||||
public PMatrix2D get() {
|
||||
PMatrix2D outgoing = new PMatrix2D();
|
||||
outgoing.set(this);
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the matrix contents into a 6 entry float array.
|
||||
* If target is null (or not the correct size), a new array will be created.
|
||||
*/
|
||||
public float[] get(float[] target) {
|
||||
if ((target == null) || (target.length != 6)) {
|
||||
target = new float[6];
|
||||
}
|
||||
target[0] = m00;
|
||||
target[1] = m01;
|
||||
target[2] = m02;
|
||||
|
||||
target[3] = m10;
|
||||
target[4] = m11;
|
||||
target[5] = m12;
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
public void set(PMatrix matrix) {
|
||||
if (matrix instanceof PMatrix2D) {
|
||||
PMatrix2D src = (PMatrix2D) matrix;
|
||||
set(src.m00, src.m01, src.m02,
|
||||
src.m10, src.m11, src.m12);
|
||||
} else {
|
||||
throw new IllegalArgumentException("PMatrix2D.set() only accepts PMatrix2D objects.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void set(PMatrix3D src) {
|
||||
}
|
||||
|
||||
|
||||
public void set(float[] source) {
|
||||
m00 = source[0];
|
||||
m01 = source[1];
|
||||
m02 = source[2];
|
||||
|
||||
m10 = source[3];
|
||||
m11 = source[4];
|
||||
m12 = source[5];
|
||||
}
|
||||
|
||||
|
||||
public void set(float m00, float m01, float m02,
|
||||
float m10, float m11, float m12) {
|
||||
this.m00 = m00; this.m01 = m01; this.m02 = m02;
|
||||
this.m10 = m10; this.m11 = m11; this.m12 = m12;
|
||||
}
|
||||
|
||||
|
||||
public void set(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void translate(float tx, float ty) {
|
||||
m02 = tx*m00 + ty*m01 + m02;
|
||||
m12 = tx*m10 + ty*m11 + m12;
|
||||
}
|
||||
|
||||
|
||||
public void translate(float x, float y, float z) {
|
||||
throw new IllegalArgumentException("Cannot use translate(x, y, z) on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
// Implementation roughly based on AffineTransform.
|
||||
public void rotate(float angle) {
|
||||
float s = sin(angle);
|
||||
float c = cos(angle);
|
||||
|
||||
float temp1 = m00;
|
||||
float temp2 = m01;
|
||||
m00 = c * temp1 + s * temp2;
|
||||
m01 = -s * temp1 + c * temp2;
|
||||
temp1 = m10;
|
||||
temp2 = m11;
|
||||
m10 = c * temp1 + s * temp2;
|
||||
m11 = -s * temp1 + c * temp2;
|
||||
}
|
||||
|
||||
|
||||
public void rotateX(float angle) {
|
||||
throw new IllegalArgumentException("Cannot use rotateX() on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
public void rotateY(float angle) {
|
||||
throw new IllegalArgumentException("Cannot use rotateY() on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
public void rotateZ(float angle) {
|
||||
rotate(angle);
|
||||
}
|
||||
|
||||
|
||||
public void rotate(float angle, float v0, float v1, float v2) {
|
||||
throw new IllegalArgumentException("Cannot use this version of rotate() on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
public void scale(float s) {
|
||||
scale(s, s);
|
||||
}
|
||||
|
||||
|
||||
public void scale(float sx, float sy) {
|
||||
m00 *= sx; m01 *= sy;
|
||||
m10 *= sx; m11 *= sy;
|
||||
}
|
||||
|
||||
|
||||
public void scale(float x, float y, float z) {
|
||||
throw new IllegalArgumentException("Cannot use this version of scale() on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
public void skewX(float angle) {
|
||||
apply(1, 0, 1, angle, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
public void skewY(float angle) {
|
||||
apply(1, 0, 1, 0, angle, 0);
|
||||
}
|
||||
|
||||
|
||||
public void apply(PMatrix source) {
|
||||
if (source instanceof PMatrix2D) {
|
||||
apply((PMatrix2D) source);
|
||||
} else if (source instanceof PMatrix3D) {
|
||||
apply((PMatrix3D) source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void apply(PMatrix2D source) {
|
||||
apply(source.m00, source.m01, source.m02,
|
||||
source.m10, source.m11, source.m12);
|
||||
}
|
||||
|
||||
|
||||
public void apply(PMatrix3D source) {
|
||||
throw new IllegalArgumentException("Cannot use apply(PMatrix3D) on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
public void apply(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12) {
|
||||
float t0 = m00;
|
||||
float t1 = m01;
|
||||
m00 = n00 * t0 + n10 * t1;
|
||||
m01 = n01 * t0 + n11 * t1;
|
||||
m02 += n02 * t0 + n12 * t1;
|
||||
|
||||
t0 = m10;
|
||||
t1 = m11;
|
||||
m10 = n00 * t0 + n10 * t1;
|
||||
m11 = n01 * t0 + n11 * t1;
|
||||
m12 += n02 * t0 + n12 * t1;
|
||||
}
|
||||
|
||||
|
||||
public void apply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
throw new IllegalArgumentException("Cannot use this version of apply() on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply another matrix to the left of this one.
|
||||
*/
|
||||
public void preApply(PMatrix2D left) {
|
||||
preApply(left.m00, left.m01, left.m02,
|
||||
left.m10, left.m11, left.m12);
|
||||
}
|
||||
|
||||
|
||||
public void preApply(PMatrix3D left) {
|
||||
throw new IllegalArgumentException("Cannot use preApply(PMatrix3D) on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
public void preApply(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12) {
|
||||
float t0 = m02;
|
||||
float t1 = m12;
|
||||
n02 += t0 * n00 + t1 * n01;
|
||||
n12 += t0 * n10 + t1 * n11;
|
||||
|
||||
m02 = n02;
|
||||
m12 = n12;
|
||||
|
||||
t0 = m00;
|
||||
t1 = m10;
|
||||
m00 = t0 * n00 + t1 * n01;
|
||||
m10 = t0 * n10 + t1 * n11;
|
||||
|
||||
t0 = m01;
|
||||
t1 = m11;
|
||||
m01 = t0 * n00 + t1 * n01;
|
||||
m11 = t0 * n10 + t1 * n11;
|
||||
}
|
||||
|
||||
|
||||
public void preApply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
throw new IllegalArgumentException("Cannot use this version of preApply() on a PMatrix2D.");
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Multiply the x and y coordinates of a PVector against this matrix.
|
||||
*/
|
||||
public PVector mult(PVector source, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector();
|
||||
}
|
||||
target.x = m00*source.x + m01*source.y + m02;
|
||||
target.y = m10*source.x + m11*source.y + m12;
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply a two element vector against this matrix.
|
||||
* If out is null or not length four, a new float array will be returned.
|
||||
* The values for vec and out can be the same (though that's less efficient).
|
||||
*/
|
||||
public float[] mult(float vec[], float out[]) {
|
||||
if (out == null || out.length != 2) {
|
||||
out = new float[2];
|
||||
}
|
||||
|
||||
if (vec == out) {
|
||||
float tx = m00*vec[0] + m01*vec[1] + m02;
|
||||
float ty = m10*vec[0] + m11*vec[1] + m12;
|
||||
|
||||
out[0] = tx;
|
||||
out[1] = ty;
|
||||
|
||||
} else {
|
||||
out[0] = m00*vec[0] + m01*vec[1] + m02;
|
||||
out[1] = m10*vec[0] + m11*vec[1] + m12;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
public float multX(float x, float y) {
|
||||
return m00*x + m01*y + m02;
|
||||
}
|
||||
|
||||
|
||||
public float multY(float x, float y) {
|
||||
return m10*x + m11*y + m12;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transpose this matrix.
|
||||
*/
|
||||
public void transpose() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invert this matrix. Implementation stolen from OpenJDK.
|
||||
* @return true if successful
|
||||
*/
|
||||
public boolean invert() {
|
||||
float determinant = determinant();
|
||||
if (Math.abs(determinant) <= Float.MIN_VALUE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float t00 = m00;
|
||||
float t01 = m01;
|
||||
float t02 = m02;
|
||||
float t10 = m10;
|
||||
float t11 = m11;
|
||||
float t12 = m12;
|
||||
|
||||
m00 = t11 / determinant;
|
||||
m10 = -t10 / determinant;
|
||||
m01 = -t01 / determinant;
|
||||
m11 = t00 / determinant;
|
||||
m02 = (t01 * t12 - t11 * t02) / determinant;
|
||||
m12 = (t10 * t02 - t00 * t12) / determinant;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public float determinant() {
|
||||
return m00 * m11 - m01 * m10;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void print() {
|
||||
int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)),
|
||||
PApplet.max(abs(m10), abs(m11), abs(m12))));
|
||||
|
||||
int digits = 1;
|
||||
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
||||
digits = 5;
|
||||
} else {
|
||||
while ((big /= 10) != 0) digits++; // cheap log()
|
||||
}
|
||||
|
||||
System.out.println(PApplet.nfs(m00, digits, 4) + " " +
|
||||
PApplet.nfs(m01, digits, 4) + " " +
|
||||
PApplet.nfs(m02, digits, 4));
|
||||
|
||||
System.out.println(PApplet.nfs(m10, digits, 4) + " " +
|
||||
PApplet.nfs(m11, digits, 4) + " " +
|
||||
PApplet.nfs(m12, digits, 4));
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO these need to be added as regular API, but the naming and
|
||||
// implementation needs to be improved first. (e.g. actually keeping track
|
||||
// of whether the matrix is in fact identity internally.)
|
||||
|
||||
|
||||
protected boolean isIdentity() {
|
||||
return ((m00 == 1) && (m01 == 0) && (m02 == 0) &&
|
||||
(m10 == 0) && (m11 == 1) && (m12 == 0));
|
||||
}
|
||||
|
||||
|
||||
// TODO make this more efficient, or move into PMatrix2D
|
||||
protected boolean isWarped() {
|
||||
return ((m00 != 1) || (m01 != 0) &&
|
||||
(m10 != 0) || (m11 != 1));
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
private final float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
private final float abs(float a) {
|
||||
return (a < 0) ? -a : a;
|
||||
}
|
||||
|
||||
private final float sin(float angle) {
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
private final float cos(float angle) {
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
}
|
@ -1,782 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2005-08 Ben Fry and Casey Reas
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
|
||||
/**
|
||||
* 4x4 matrix implementation.
|
||||
*/
|
||||
public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
||||
|
||||
public float m00, m01, m02, m03;
|
||||
public float m10, m11, m12, m13;
|
||||
public float m20, m21, m22, m23;
|
||||
public float m30, m31, m32, m33;
|
||||
|
||||
|
||||
// locally allocated version to avoid creating new memory
|
||||
protected PMatrix3D inverseCopy;
|
||||
|
||||
|
||||
public PMatrix3D() {
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
public PMatrix3D(float m00, float m01, float m02,
|
||||
float m10, float m11, float m12) {
|
||||
set(m00, m01, m02, 0,
|
||||
m10, m11, m12, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public PMatrix3D(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33) {
|
||||
set(m00, m01, m02, m03,
|
||||
m10, m11, m12, m13,
|
||||
m20, m21, m22, m23,
|
||||
m30, m31, m32, m33);
|
||||
}
|
||||
|
||||
|
||||
public PMatrix3D(PMatrix matrix) {
|
||||
set(matrix);
|
||||
}
|
||||
|
||||
|
||||
public void reset() {
|
||||
set(1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a copy of this PMatrix.
|
||||
*/
|
||||
public PMatrix3D get() {
|
||||
PMatrix3D outgoing = new PMatrix3D();
|
||||
outgoing.set(this);
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies the matrix contents into a 16 entry float array.
|
||||
* If target is null (or not the correct size), a new array will be created.
|
||||
*/
|
||||
public float[] get(float[] target) {
|
||||
if ((target == null) || (target.length != 16)) {
|
||||
target = new float[16];
|
||||
}
|
||||
target[0] = m00;
|
||||
target[1] = m01;
|
||||
target[2] = m02;
|
||||
target[3] = m03;
|
||||
|
||||
target[4] = m10;
|
||||
target[5] = m11;
|
||||
target[6] = m12;
|
||||
target[7] = m13;
|
||||
|
||||
target[8] = m20;
|
||||
target[9] = m21;
|
||||
target[10] = m22;
|
||||
target[11] = m23;
|
||||
|
||||
target[12] = m30;
|
||||
target[13] = m31;
|
||||
target[14] = m32;
|
||||
target[15] = m33;
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
public void set(PMatrix matrix) {
|
||||
if (matrix instanceof PMatrix3D) {
|
||||
PMatrix3D src = (PMatrix3D) matrix;
|
||||
set(src.m00, src.m01, src.m02, src.m03,
|
||||
src.m10, src.m11, src.m12, src.m13,
|
||||
src.m20, src.m21, src.m22, src.m23,
|
||||
src.m30, src.m31, src.m32, src.m33);
|
||||
} else {
|
||||
PMatrix2D src = (PMatrix2D) matrix;
|
||||
set(src.m00, src.m01, 0, src.m02,
|
||||
src.m10, src.m11, 0, src.m12,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void set(float[] source) {
|
||||
if (source.length == 6) {
|
||||
set(source[0], source[1], source[2],
|
||||
source[3], source[4], source[5]);
|
||||
|
||||
} else if (source.length == 16) {
|
||||
m00 = source[0];
|
||||
m01 = source[1];
|
||||
m02 = source[2];
|
||||
m03 = source[3];
|
||||
|
||||
m10 = source[4];
|
||||
m11 = source[5];
|
||||
m12 = source[6];
|
||||
m13 = source[7];
|
||||
|
||||
m20 = source[8];
|
||||
m21 = source[9];
|
||||
m22 = source[10];
|
||||
m23 = source[11];
|
||||
|
||||
m30 = source[12];
|
||||
m31 = source[13];
|
||||
m32 = source[14];
|
||||
m33 = source[15];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void set(float m00, float m01, float m02,
|
||||
float m10, float m11, float m12) {
|
||||
set(m00, m01, 0, m02,
|
||||
m10, m11, 0, m12,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void set(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33) {
|
||||
this.m00 = m00; this.m01 = m01; this.m02 = m02; this.m03 = m03;
|
||||
this.m10 = m10; this.m11 = m11; this.m12 = m12; this.m13 = m13;
|
||||
this.m20 = m20; this.m21 = m21; this.m22 = m22; this.m23 = m23;
|
||||
this.m30 = m30; this.m31 = m31; this.m32 = m32; this.m33 = m33;
|
||||
}
|
||||
|
||||
|
||||
public void translate(float tx, float ty) {
|
||||
translate(tx, ty, 0);
|
||||
}
|
||||
|
||||
// public void invTranslate(float tx, float ty) {
|
||||
// invTranslate(tx, ty, 0);
|
||||
// }
|
||||
|
||||
|
||||
public void translate(float tx, float ty, float tz) {
|
||||
m03 += tx*m00 + ty*m01 + tz*m02;
|
||||
m13 += tx*m10 + ty*m11 + tz*m12;
|
||||
m23 += tx*m20 + ty*m21 + tz*m22;
|
||||
m33 += tx*m30 + ty*m31 + tz*m32;
|
||||
}
|
||||
|
||||
|
||||
public void rotate(float angle) {
|
||||
rotateZ(angle);
|
||||
}
|
||||
|
||||
|
||||
public void rotateX(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
apply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void rotateY(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
apply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void rotateZ(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
apply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void rotate(float angle, float v0, float v1, float v2) {
|
||||
// TODO should make sure this vector is normalized
|
||||
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
float t = 1.0f - c;
|
||||
|
||||
apply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
||||
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
|
||||
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void scale(float s) {
|
||||
//apply(s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1);
|
||||
scale(s, s, s);
|
||||
}
|
||||
|
||||
|
||||
public void scale(float sx, float sy) {
|
||||
//apply(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
scale(sx, sy, 1);
|
||||
}
|
||||
|
||||
|
||||
public void scale(float x, float y, float z) {
|
||||
//apply(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
||||
m00 *= x; m01 *= y; m02 *= z;
|
||||
m10 *= x; m11 *= y; m12 *= z;
|
||||
m20 *= x; m21 *= y; m22 *= z;
|
||||
m30 *= x; m31 *= y; m32 *= z;
|
||||
}
|
||||
|
||||
|
||||
public void skewX(float angle) {
|
||||
float t = (float) Math.tan(angle);
|
||||
apply(1, t, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void skewY(float angle) {
|
||||
float t = (float) Math.tan(angle);
|
||||
apply(1, 0, 0, 0,
|
||||
t, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void apply(PMatrix source) {
|
||||
if (source instanceof PMatrix2D) {
|
||||
apply((PMatrix2D) source);
|
||||
} else if (source instanceof PMatrix3D) {
|
||||
apply((PMatrix3D) source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void apply(PMatrix2D source) {
|
||||
apply(source.m00, source.m01, 0, source.m02,
|
||||
source.m10, source.m11, 0, source.m12,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void apply(PMatrix3D source) {
|
||||
apply(source.m00, source.m01, source.m02, source.m03,
|
||||
source.m10, source.m11, source.m12, source.m13,
|
||||
source.m20, source.m21, source.m22, source.m23,
|
||||
source.m30, source.m31, source.m32, source.m33);
|
||||
}
|
||||
|
||||
|
||||
public void apply(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12) {
|
||||
apply(n00, n01, 0, n02,
|
||||
n10, n11, 0, n12,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void apply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
|
||||
float r00 = m00*n00 + m01*n10 + m02*n20 + m03*n30;
|
||||
float r01 = m00*n01 + m01*n11 + m02*n21 + m03*n31;
|
||||
float r02 = m00*n02 + m01*n12 + m02*n22 + m03*n32;
|
||||
float r03 = m00*n03 + m01*n13 + m02*n23 + m03*n33;
|
||||
|
||||
float r10 = m10*n00 + m11*n10 + m12*n20 + m13*n30;
|
||||
float r11 = m10*n01 + m11*n11 + m12*n21 + m13*n31;
|
||||
float r12 = m10*n02 + m11*n12 + m12*n22 + m13*n32;
|
||||
float r13 = m10*n03 + m11*n13 + m12*n23 + m13*n33;
|
||||
|
||||
float r20 = m20*n00 + m21*n10 + m22*n20 + m23*n30;
|
||||
float r21 = m20*n01 + m21*n11 + m22*n21 + m23*n31;
|
||||
float r22 = m20*n02 + m21*n12 + m22*n22 + m23*n32;
|
||||
float r23 = m20*n03 + m21*n13 + m22*n23 + m23*n33;
|
||||
|
||||
float r30 = m30*n00 + m31*n10 + m32*n20 + m33*n30;
|
||||
float r31 = m30*n01 + m31*n11 + m32*n21 + m33*n31;
|
||||
float r32 = m30*n02 + m31*n12 + m32*n22 + m33*n32;
|
||||
float r33 = m30*n03 + m31*n13 + m32*n23 + m33*n33;
|
||||
|
||||
m00 = r00; m01 = r01; m02 = r02; m03 = r03;
|
||||
m10 = r10; m11 = r11; m12 = r12; m13 = r13;
|
||||
m20 = r20; m21 = r21; m22 = r22; m23 = r23;
|
||||
m30 = r30; m31 = r31; m32 = r32; m33 = r33;
|
||||
}
|
||||
|
||||
|
||||
public void preApply(PMatrix2D left) {
|
||||
preApply(left.m00, left.m01, 0, left.m02,
|
||||
left.m10, left.m11, 0, left.m12,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply another matrix to the left of this one.
|
||||
*/
|
||||
public void preApply(PMatrix3D left) {
|
||||
preApply(left.m00, left.m01, left.m02, left.m03,
|
||||
left.m10, left.m11, left.m12, left.m13,
|
||||
left.m20, left.m21, left.m22, left.m23,
|
||||
left.m30, left.m31, left.m32, left.m33);
|
||||
}
|
||||
|
||||
|
||||
public void preApply(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12) {
|
||||
preApply(n00, n01, 0, n02,
|
||||
n10, n11, 0, n12,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void preApply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
|
||||
float r00 = n00*m00 + n01*m10 + n02*m20 + n03*m30;
|
||||
float r01 = n00*m01 + n01*m11 + n02*m21 + n03*m31;
|
||||
float r02 = n00*m02 + n01*m12 + n02*m22 + n03*m32;
|
||||
float r03 = n00*m03 + n01*m13 + n02*m23 + n03*m33;
|
||||
|
||||
float r10 = n10*m00 + n11*m10 + n12*m20 + n13*m30;
|
||||
float r11 = n10*m01 + n11*m11 + n12*m21 + n13*m31;
|
||||
float r12 = n10*m02 + n11*m12 + n12*m22 + n13*m32;
|
||||
float r13 = n10*m03 + n11*m13 + n12*m23 + n13*m33;
|
||||
|
||||
float r20 = n20*m00 + n21*m10 + n22*m20 + n23*m30;
|
||||
float r21 = n20*m01 + n21*m11 + n22*m21 + n23*m31;
|
||||
float r22 = n20*m02 + n21*m12 + n22*m22 + n23*m32;
|
||||
float r23 = n20*m03 + n21*m13 + n22*m23 + n23*m33;
|
||||
|
||||
float r30 = n30*m00 + n31*m10 + n32*m20 + n33*m30;
|
||||
float r31 = n30*m01 + n31*m11 + n32*m21 + n33*m31;
|
||||
float r32 = n30*m02 + n31*m12 + n32*m22 + n33*m32;
|
||||
float r33 = n30*m03 + n31*m13 + n32*m23 + n33*m33;
|
||||
|
||||
m00 = r00; m01 = r01; m02 = r02; m03 = r03;
|
||||
m10 = r10; m11 = r11; m12 = r12; m13 = r13;
|
||||
m20 = r20; m21 = r21; m22 = r22; m23 = r23;
|
||||
m30 = r30; m31 = r31; m32 = r32; m33 = r33;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public PVector mult(PVector source, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector();
|
||||
}
|
||||
target.x = m00*source.x + m01*source.y + m02*source.z + m03;
|
||||
target.y = m10*source.x + m11*source.y + m12*source.z + m13;
|
||||
target.z = m20*source.x + m21*source.y + m22*source.z + m23;
|
||||
// float tw = m30*source.x + m31*source.y + m32*source.z + m33;
|
||||
// if (tw != 0 && tw != 1) {
|
||||
// target.div(tw);
|
||||
// }
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public PVector cmult(PVector source, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector();
|
||||
}
|
||||
target.x = m00*source.x + m10*source.y + m20*source.z + m30;
|
||||
target.y = m01*source.x + m11*source.y + m21*source.z + m31;
|
||||
target.z = m02*source.x + m12*source.y + m22*source.z + m32;
|
||||
float tw = m03*source.x + m13*source.y + m23*source.z + m33;
|
||||
if (tw != 0 && tw != 1) {
|
||||
target.div(tw);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Multiply a three or four element vector against this matrix. If out is
|
||||
* null or not length 3 or 4, a new float array (length 3) will be returned.
|
||||
*/
|
||||
public float[] mult(float[] source, float[] target) {
|
||||
if (target == null || target.length < 3) {
|
||||
target = new float[3];
|
||||
}
|
||||
if (source == target) {
|
||||
throw new RuntimeException("The source and target vectors used in " +
|
||||
"PMatrix3D.mult() cannot be identical.");
|
||||
}
|
||||
if (target.length == 3) {
|
||||
target[0] = m00*source[0] + m01*source[1] + m02*source[2] + m03;
|
||||
target[1] = m10*source[0] + m11*source[1] + m12*source[2] + m13;
|
||||
target[2] = m20*source[0] + m21*source[1] + m22*source[2] + m23;
|
||||
//float w = m30*source[0] + m31*source[1] + m32*source[2] + m33;
|
||||
//if (w != 0 && w != 1) {
|
||||
// target[0] /= w; target[1] /= w; target[2] /= w;
|
||||
//}
|
||||
} else if (target.length > 3) {
|
||||
target[0] = m00*source[0] + m01*source[1] + m02*source[2] + m03*source[3];
|
||||
target[1] = m10*source[0] + m11*source[1] + m12*source[2] + m13*source[3];
|
||||
target[2] = m20*source[0] + m21*source[1] + m22*source[2] + m23*source[3];
|
||||
target[3] = m30*source[0] + m31*source[1] + m32*source[2] + m33*source[3];
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
public float multX(float x, float y) {
|
||||
return m00*x + m01*y + m03;
|
||||
}
|
||||
|
||||
|
||||
public float multY(float x, float y) {
|
||||
return m10*x + m11*y + m13;
|
||||
}
|
||||
|
||||
|
||||
public float multX(float x, float y, float z) {
|
||||
return m00*x + m01*y + m02*z + m03;
|
||||
}
|
||||
|
||||
|
||||
public float multY(float x, float y, float z) {
|
||||
return m10*x + m11*y + m12*z + m13;
|
||||
}
|
||||
|
||||
|
||||
public float multZ(float x, float y, float z) {
|
||||
return m20*x + m21*y + m22*z + m23;
|
||||
}
|
||||
|
||||
|
||||
public float multW(float x, float y, float z) {
|
||||
return m30*x + m31*y + m32*z + m33;
|
||||
}
|
||||
|
||||
|
||||
public float multX(float x, float y, float z, float w) {
|
||||
return m00*x + m01*y + m02*z + m03*w;
|
||||
}
|
||||
|
||||
|
||||
public float multY(float x, float y, float z, float w) {
|
||||
return m10*x + m11*y + m12*z + m13*w;
|
||||
}
|
||||
|
||||
|
||||
public float multZ(float x, float y, float z, float w) {
|
||||
return m20*x + m21*y + m22*z + m23*w;
|
||||
}
|
||||
|
||||
|
||||
public float multW(float x, float y, float z, float w) {
|
||||
return m30*x + m31*y + m32*z + m33*w;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transpose this matrix.
|
||||
*/
|
||||
public void transpose() {
|
||||
float temp;
|
||||
temp = m01; m01 = m10; m10 = temp;
|
||||
temp = m02; m02 = m20; m20 = temp;
|
||||
temp = m03; m03 = m30; m30 = temp;
|
||||
temp = m12; m12 = m21; m21 = temp;
|
||||
temp = m13; m13 = m31; m31 = temp;
|
||||
temp = m23; m23 = m32; m32 = temp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invert this matrix.
|
||||
* @return true if successful
|
||||
*/
|
||||
public boolean invert() {
|
||||
float determinant = determinant();
|
||||
if (determinant == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// first row
|
||||
float t00 = determinant3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
|
||||
float t01 = -determinant3x3(m10, m12, m13, m20, m22, m23, m30, m32, m33);
|
||||
float t02 = determinant3x3(m10, m11, m13, m20, m21, m23, m30, m31, m33);
|
||||
float t03 = -determinant3x3(m10, m11, m12, m20, m21, m22, m30, m31, m32);
|
||||
|
||||
// second row
|
||||
float t10 = -determinant3x3(m01, m02, m03, m21, m22, m23, m31, m32, m33);
|
||||
float t11 = determinant3x3(m00, m02, m03, m20, m22, m23, m30, m32, m33);
|
||||
float t12 = -determinant3x3(m00, m01, m03, m20, m21, m23, m30, m31, m33);
|
||||
float t13 = determinant3x3(m00, m01, m02, m20, m21, m22, m30, m31, m32);
|
||||
|
||||
// third row
|
||||
float t20 = determinant3x3(m01, m02, m03, m11, m12, m13, m31, m32, m33);
|
||||
float t21 = -determinant3x3(m00, m02, m03, m10, m12, m13, m30, m32, m33);
|
||||
float t22 = determinant3x3(m00, m01, m03, m10, m11, m13, m30, m31, m33);
|
||||
float t23 = -determinant3x3(m00, m01, m02, m10, m11, m12, m30, m31, m32);
|
||||
|
||||
// fourth row
|
||||
float t30 = -determinant3x3(m01, m02, m03, m11, m12, m13, m21, m22, m23);
|
||||
float t31 = determinant3x3(m00, m02, m03, m10, m12, m13, m20, m22, m23);
|
||||
float t32 = -determinant3x3(m00, m01, m03, m10, m11, m13, m20, m21, m23);
|
||||
float t33 = determinant3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
|
||||
|
||||
// transpose and divide by the determinant
|
||||
m00 = t00 / determinant;
|
||||
m01 = t10 / determinant;
|
||||
m02 = t20 / determinant;
|
||||
m03 = t30 / determinant;
|
||||
|
||||
m10 = t01 / determinant;
|
||||
m11 = t11 / determinant;
|
||||
m12 = t21 / determinant;
|
||||
m13 = t31 / determinant;
|
||||
|
||||
m20 = t02 / determinant;
|
||||
m21 = t12 / determinant;
|
||||
m22 = t22 / determinant;
|
||||
m23 = t32 / determinant;
|
||||
|
||||
m30 = t03 / determinant;
|
||||
m31 = t13 / determinant;
|
||||
m32 = t23 / determinant;
|
||||
m33 = t33 / determinant;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the determinant of a 3x3 matrix.
|
||||
* @return result
|
||||
*/
|
||||
private float determinant3x3(float t00, float t01, float t02,
|
||||
float t10, float t11, float t12,
|
||||
float t20, float t21, float t22) {
|
||||
return (t00 * (t11 * t22 - t12 * t21) +
|
||||
t01 * (t12 * t20 - t10 * t22) +
|
||||
t02 * (t10 * t21 - t11 * t20));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public float determinant() {
|
||||
float f =
|
||||
m00
|
||||
* ((m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32)
|
||||
- m13 * m22 * m31
|
||||
- m11 * m23 * m32
|
||||
- m12 * m21 * m33);
|
||||
f -= m01
|
||||
* ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32)
|
||||
- m13 * m22 * m30
|
||||
- m10 * m23 * m32
|
||||
- m12 * m20 * m33);
|
||||
f += m02
|
||||
* ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31)
|
||||
- m13 * m21 * m30
|
||||
- m10 * m23 * m31
|
||||
- m11 * m20 * m33);
|
||||
f -= m03
|
||||
* ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31)
|
||||
- m12 * m21 * m30
|
||||
- m10 * m22 * m31
|
||||
- m11 * m20 * m32);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// REVERSE VERSIONS OF MATRIX OPERATIONS
|
||||
|
||||
// These functions should not be used, as they will be removed in the future.
|
||||
|
||||
|
||||
protected void invTranslate(float tx, float ty, float tz) {
|
||||
preApply(1, 0, 0, -tx,
|
||||
0, 1, 0, -ty,
|
||||
0, 0, 1, -tz,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
protected void invRotateX(float angle) {
|
||||
float c = cos(-angle);
|
||||
float s = sin(-angle);
|
||||
preApply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
protected void invRotateY(float angle) {
|
||||
float c = cos(-angle);
|
||||
float s = sin(-angle);
|
||||
preApply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
protected void invRotateZ(float angle) {
|
||||
float c = cos(-angle);
|
||||
float s = sin(-angle);
|
||||
preApply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
protected void invRotate(float angle, float v0, float v1, float v2) {
|
||||
//TODO should make sure this vector is normalized
|
||||
|
||||
float c = cos(-angle);
|
||||
float s = sin(-angle);
|
||||
float t = 1.0f - c;
|
||||
|
||||
preApply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
||||
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
|
||||
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
protected void invScale(float x, float y, float z) {
|
||||
preApply(1/x, 0, 0, 0, 0, 1/y, 0, 0, 0, 0, 1/z, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
protected boolean invApply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
if (inverseCopy == null) {
|
||||
inverseCopy = new PMatrix3D();
|
||||
}
|
||||
inverseCopy.set(n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23,
|
||||
n30, n31, n32, n33);
|
||||
if (!inverseCopy.invert()) {
|
||||
return false;
|
||||
}
|
||||
preApply(inverseCopy);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void print() {
|
||||
/*
|
||||
System.out.println(m00 + " " + m01 + " " + m02 + " " + m03 + "\n" +
|
||||
m10 + " " + m11 + " " + m12 + " " + m13 + "\n" +
|
||||
m20 + " " + m21 + " " + m22 + " " + m23 + "\n" +
|
||||
m30 + " " + m31 + " " + m32 + " " + m33 + "\n");
|
||||
*/
|
||||
int big = (int) Math.abs(max(max(max(max(abs(m00), abs(m01)),
|
||||
max(abs(m02), abs(m03))),
|
||||
max(max(abs(m10), abs(m11)),
|
||||
max(abs(m12), abs(m13)))),
|
||||
max(max(max(abs(m20), abs(m21)),
|
||||
max(abs(m22), abs(m23))),
|
||||
max(max(abs(m30), abs(m31)),
|
||||
max(abs(m32), abs(m33))))));
|
||||
|
||||
int digits = 1;
|
||||
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
||||
digits = 5;
|
||||
} else {
|
||||
while ((big /= 10) != 0) digits++; // cheap log()
|
||||
}
|
||||
|
||||
System.out.println(PApplet.nfs(m00, digits, 4) + " " +
|
||||
PApplet.nfs(m01, digits, 4) + " " +
|
||||
PApplet.nfs(m02, digits, 4) + " " +
|
||||
PApplet.nfs(m03, digits, 4));
|
||||
|
||||
System.out.println(PApplet.nfs(m10, digits, 4) + " " +
|
||||
PApplet.nfs(m11, digits, 4) + " " +
|
||||
PApplet.nfs(m12, digits, 4) + " " +
|
||||
PApplet.nfs(m13, digits, 4));
|
||||
|
||||
System.out.println(PApplet.nfs(m20, digits, 4) + " " +
|
||||
PApplet.nfs(m21, digits, 4) + " " +
|
||||
PApplet.nfs(m22, digits, 4) + " " +
|
||||
PApplet.nfs(m23, digits, 4));
|
||||
|
||||
System.out.println(PApplet.nfs(m30, digits, 4) + " " +
|
||||
PApplet.nfs(m31, digits, 4) + " " +
|
||||
PApplet.nfs(m32, digits, 4) + " " +
|
||||
PApplet.nfs(m33, digits, 4));
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
private final float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
private final float abs(float a) {
|
||||
return (a < 0) ? -a : a;
|
||||
}
|
||||
|
||||
private final float sin(float angle) {
|
||||
return (float) Math.sin(angle);
|
||||
}
|
||||
|
||||
private final float cos(float angle) {
|
||||
return (float) Math.cos(angle);
|
||||
}
|
||||
}
|
@ -1,701 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
|
||||
/**
|
||||
* Z-buffer polygon rendering object used by PGraphics2D.
|
||||
*/
|
||||
public class PPolygon implements PConstants {
|
||||
|
||||
static final int DEFAULT_SIZE = 64; // this is needed for spheres
|
||||
float vertices[][] = new float[DEFAULT_SIZE][VERTEX_FIELD_COUNT];
|
||||
int vertexCount;
|
||||
|
||||
float r[] = new float[DEFAULT_SIZE]; // storage used by incrementalize
|
||||
float dr[] = new float[DEFAULT_SIZE];
|
||||
float l[] = new float[DEFAULT_SIZE]; // more storage for incrementalize
|
||||
float dl[] = new float[DEFAULT_SIZE];
|
||||
float sp[] = new float[DEFAULT_SIZE]; // temporary storage for scanline
|
||||
float sdp[] = new float[DEFAULT_SIZE];
|
||||
|
||||
protected boolean interpX;
|
||||
protected boolean interpUV; // is this necessary? could just check timage != null
|
||||
protected boolean interpARGB;
|
||||
|
||||
private int rgba;
|
||||
private int r2, g2, b2, a2, a2orig;
|
||||
|
||||
PGraphics parent;
|
||||
int[] pixels;
|
||||
// the parent's width/height,
|
||||
// or if smooth is enabled, parent's w/h scaled
|
||||
// up by the smooth dimension
|
||||
int width, height;
|
||||
int width1, height1;
|
||||
|
||||
PImage timage;
|
||||
int[] tpixels;
|
||||
int theight, twidth;
|
||||
int theight1, twidth1;
|
||||
int tformat;
|
||||
|
||||
// for anti-aliasing
|
||||
static final int SUBXRES = 8;
|
||||
static final int SUBXRES1 = 7;
|
||||
static final int SUBYRES = 8;
|
||||
static final int SUBYRES1 = 7;
|
||||
static final int MAX_COVERAGE = SUBXRES * SUBYRES;
|
||||
|
||||
boolean smooth;
|
||||
int firstModY;
|
||||
int lastModY;
|
||||
int lastY;
|
||||
int aaleft[] = new int[SUBYRES];
|
||||
int aaright[] = new int[SUBYRES];
|
||||
int aaleftmin, aarightmin;
|
||||
int aaleftmax, aarightmax;
|
||||
int aaleftfull, aarightfull;
|
||||
|
||||
final private int MODYRES(int y) {
|
||||
return (y & SUBYRES1);
|
||||
}
|
||||
|
||||
|
||||
public PPolygon(PGraphics iparent) {
|
||||
parent = iparent;
|
||||
reset(0);
|
||||
}
|
||||
|
||||
|
||||
protected void reset(int count) {
|
||||
vertexCount = count;
|
||||
interpX = true;
|
||||
// interpZ = true;
|
||||
interpUV = false;
|
||||
interpARGB = true;
|
||||
timage = null;
|
||||
}
|
||||
|
||||
|
||||
protected float[] nextVertex() {
|
||||
if (vertexCount == vertices.length) {
|
||||
float temp[][] = new float[vertexCount<<1][VERTEX_FIELD_COUNT];
|
||||
System.arraycopy(vertices, 0, temp, 0, vertexCount);
|
||||
vertices = temp;
|
||||
|
||||
r = new float[vertices.length];
|
||||
dr = new float[vertices.length];
|
||||
l = new float[vertices.length];
|
||||
dl = new float[vertices.length];
|
||||
sp = new float[vertices.length];
|
||||
sdp = new float[vertices.length];
|
||||
}
|
||||
return vertices[vertexCount++]; // returns v[0], sets vc to 1
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if this vertex is redundant. If so, will also
|
||||
* decrement the vertex count.
|
||||
*/
|
||||
/*
|
||||
public boolean redundantVertex(float x, float y, float z) {
|
||||
// because vertexCount will be 2 when setting vertex[1]
|
||||
if (vertexCount < 2) return false;
|
||||
|
||||
// vertexCount-1 is the current vertex that would be used
|
||||
// vertexCount-2 would be the previous feller
|
||||
if ((Math.abs(vertices[vertexCount-2][MX] - x) < EPSILON) &&
|
||||
(Math.abs(vertices[vertexCount-2][MY] - y) < EPSILON) &&
|
||||
(Math.abs(vertices[vertexCount-2][MZ] - z) < EPSILON)) {
|
||||
vertexCount--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
protected void texture(PImage image) {
|
||||
this.timage = image;
|
||||
|
||||
if (image != null) {
|
||||
this.tpixels = image.pixels;
|
||||
this.twidth = image.width;
|
||||
this.theight = image.height;
|
||||
this.tformat = image.format;
|
||||
|
||||
twidth1 = twidth - 1;
|
||||
theight1 = theight - 1;
|
||||
interpUV = true;
|
||||
|
||||
} else {
|
||||
interpUV = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void renderPolygon(float[][] v, int count) {
|
||||
vertices = v;
|
||||
vertexCount = count;
|
||||
|
||||
if (r.length < vertexCount) {
|
||||
r = new float[vertexCount]; // storage used by incrementalize
|
||||
dr = new float[vertexCount];
|
||||
l = new float[vertexCount]; // more storage for incrementalize
|
||||
dl = new float[vertexCount];
|
||||
sp = new float[vertexCount]; // temporary storage for scanline
|
||||
sdp = new float[vertexCount];
|
||||
}
|
||||
|
||||
render();
|
||||
checkExpand();
|
||||
}
|
||||
|
||||
|
||||
protected void renderTriangle(float[] v1, float[] v2, float[] v3) {
|
||||
// Calling code will have already done reset(3).
|
||||
// Can't do it here otherwise would nuke any texture settings.
|
||||
|
||||
vertices[0] = v1;
|
||||
vertices[1] = v2;
|
||||
vertices[2] = v3;
|
||||
|
||||
render();
|
||||
checkExpand();
|
||||
}
|
||||
|
||||
|
||||
protected void checkExpand() {
|
||||
if (smooth) {
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
vertices[i][TX] /= SUBXRES;
|
||||
vertices[i][TY] /= SUBYRES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void render() {
|
||||
if (vertexCount < 3) return;
|
||||
|
||||
// these may have changed due to a resize()
|
||||
// so they should be refreshed here
|
||||
pixels = parent.pixels;
|
||||
//zbuffer = parent.zbuffer;
|
||||
|
||||
// noDepthTest = parent.hints[DISABLE_DEPTH_TEST];
|
||||
smooth = parent.smooth;
|
||||
|
||||
// by default, text turns on smooth for the textures
|
||||
// themselves. but this should be shut off if the hint
|
||||
// for DISABLE_TEXT_SMOOTH is set.
|
||||
// texture_smooth = true;
|
||||
|
||||
width = smooth ? parent.width*SUBXRES : parent.width;
|
||||
height = smooth ? parent.height*SUBYRES : parent.height;
|
||||
|
||||
width1 = width - 1;
|
||||
height1 = height - 1;
|
||||
|
||||
if (!interpARGB) {
|
||||
r2 = (int) (vertices[0][R] * 255);
|
||||
g2 = (int) (vertices[0][G] * 255);
|
||||
b2 = (int) (vertices[0][B] * 255);
|
||||
a2 = (int) (vertices[0][A] * 255);
|
||||
a2orig = a2; // save an extra copy
|
||||
rgba = 0xff000000 | (r2 << 16) | (g2 << 8) | b2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
r[i] = 0; dr[i] = 0; l[i] = 0; dl[i] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
// hack to not make polygons fly into the screen
|
||||
if (parent.hints[DISABLE_FLYING_POO]) {
|
||||
float nwidth2 = -width * 2;
|
||||
float nheight2 = -height * 2;
|
||||
float width2 = width * 2;
|
||||
float height2 = height * 2;
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
if ((vertices[i][TX] < nwidth2) ||
|
||||
(vertices[i][TX] > width2) ||
|
||||
(vertices[i][TY] < nheight2) ||
|
||||
(vertices[i][TY] > height2)) {
|
||||
return; // this is a bad poly
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
// System.out.println(vertices[i][R] + " " + vertices[i][G] + " " + vertices[i][B]);
|
||||
// }
|
||||
// System.out.println();
|
||||
|
||||
if (smooth) {
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
vertices[i][TX] *= SUBXRES;
|
||||
vertices[i][TY] *= SUBYRES;
|
||||
}
|
||||
firstModY = -1;
|
||||
}
|
||||
|
||||
// find top vertex (y is zero at top, higher downwards)
|
||||
int topi = 0;
|
||||
float ymin = vertices[0][TY];
|
||||
float ymax = vertices[0][TY]; // fry 031001
|
||||
for (int i = 1; i < vertexCount; i++) {
|
||||
if (vertices[i][TY] < ymin) {
|
||||
ymin = vertices[i][TY];
|
||||
topi = i;
|
||||
}
|
||||
if (vertices[i][TY] > ymax) {
|
||||
ymax = vertices[i][TY];
|
||||
}
|
||||
}
|
||||
|
||||
// the last row is an exceptional case, because there won't
|
||||
// necessarily be 8 rows of subpixel lines that will force
|
||||
// the final line to render. so instead, the algo keeps track
|
||||
// of the lastY (in subpixel resolution) that will be rendered
|
||||
// and that will force a scanline to happen the same as
|
||||
// every eighth in the other situations
|
||||
//lastY = -1; // fry 031001
|
||||
lastY = (int) (ymax - 0.5f); // global to class bc used by other fxns
|
||||
|
||||
int lefti = topi; // li, index of left vertex
|
||||
int righti = topi; // ri, index of right vertex
|
||||
int y = (int) (ymin + 0.5f); // current scan line
|
||||
int lefty = y - 1; // lower end of left edge
|
||||
int righty = y - 1; // lower end of right edge
|
||||
|
||||
interpX = true;
|
||||
|
||||
int remaining = vertexCount;
|
||||
|
||||
// scan in y, activating new edges on left & right
|
||||
// as scan line passes over new vertices
|
||||
while (remaining > 0) {
|
||||
// advance left edge?
|
||||
while ((lefty <= y) && (remaining > 0)) {
|
||||
remaining--;
|
||||
// step ccw down left side
|
||||
int i = (lefti != 0) ? (lefti-1) : (vertexCount-1);
|
||||
incrementalizeY(vertices[lefti], vertices[i], l, dl, y);
|
||||
lefty = (int) (vertices[i][TY] + 0.5f);
|
||||
lefti = i;
|
||||
}
|
||||
|
||||
// advance right edge?
|
||||
while ((righty <= y) && (remaining > 0)) {
|
||||
remaining--;
|
||||
// step cw down right edge
|
||||
int i = (righti != vertexCount-1) ? (righti + 1) : 0;
|
||||
incrementalizeY(vertices[righti], vertices[i], r, dr, y);
|
||||
righty = (int) (vertices[i][TY] + 0.5f);
|
||||
righti = i;
|
||||
}
|
||||
|
||||
// do scanlines till end of l or r edge
|
||||
while (y < lefty && y < righty) {
|
||||
// this doesn't work because it's not always set here
|
||||
//if (remaining == 0) {
|
||||
//lastY = (lefty < righty) ? lefty-1 : righty-1;
|
||||
//System.out.println("lastY is " + lastY);
|
||||
//}
|
||||
|
||||
if ((y >= 0) && (y < height)) {
|
||||
//try { // hopefully this bug is fixed
|
||||
if (l[TX] <= r[TX]) scanline(y, l, r);
|
||||
else scanline(y, r, l);
|
||||
//} catch (ArrayIndexOutOfBoundsException e) {
|
||||
//e.printStackTrace();
|
||||
//}
|
||||
}
|
||||
y++;
|
||||
// this increment probably needs to be different
|
||||
// UV and RGB shouldn't be incremented until line is emitted
|
||||
increment(l, dl);
|
||||
increment(r, dr);
|
||||
}
|
||||
}
|
||||
//if (smooth) {
|
||||
//System.out.println("y/lasty/lastmody = " + y + " " + lastY + " " + lastModY);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
private void scanline(int y, float l[], float r[]) {
|
||||
//System.out.println("scanline " + y);
|
||||
for (int i = 0; i < vertexCount; i++) { // should be moved later
|
||||
sp[i] = 0; sdp[i] = 0;
|
||||
}
|
||||
|
||||
// this rounding doesn't seem to be relevant with smooth
|
||||
int lx = (int) (l[TX] + 0.49999f); // ceil(l[TX]-.5);
|
||||
if (lx < 0) lx = 0;
|
||||
int rx = (int) (r[TX] - 0.5f);
|
||||
if (rx > width1) rx = width1;
|
||||
|
||||
if (lx > rx) return;
|
||||
|
||||
if (smooth) {
|
||||
int mody = MODYRES(y);
|
||||
|
||||
aaleft[mody] = lx;
|
||||
aaright[mody] = rx;
|
||||
|
||||
if (firstModY == -1) {
|
||||
firstModY = mody;
|
||||
aaleftmin = lx; aaleftmax = lx;
|
||||
aarightmin = rx; aarightmax = rx;
|
||||
|
||||
} else {
|
||||
if (aaleftmin > aaleft[mody]) aaleftmin = aaleft[mody];
|
||||
if (aaleftmax < aaleft[mody]) aaleftmax = aaleft[mody];
|
||||
if (aarightmin > aaright[mody]) aarightmin = aaright[mody];
|
||||
if (aarightmax < aaright[mody]) aarightmax = aaright[mody];
|
||||
}
|
||||
|
||||
lastModY = mody; // moved up here (before the return) 031001
|
||||
// not the eighth (or lastY) line, so not scanning this time
|
||||
if ((mody != SUBYRES1) && (y != lastY)) return;
|
||||
//lastModY = mody; // eeK! this was missing
|
||||
//return;
|
||||
|
||||
//if (y == lastY) {
|
||||
//System.out.println("y is lasty");
|
||||
//}
|
||||
//lastModY = mody;
|
||||
aaleftfull = aaleftmax/SUBXRES + 1;
|
||||
aarightfull = aarightmin/SUBXRES - 1;
|
||||
}
|
||||
|
||||
// this is the setup, based on lx
|
||||
incrementalizeX(l, r, sp, sdp, lx);
|
||||
|
||||
// scan in x, generating pixels
|
||||
// using parent.width to get actual pixel index
|
||||
// rather than scaled by smooth factor
|
||||
int offset = smooth ? parent.width * (y / SUBYRES) : parent.width*y;
|
||||
|
||||
int truelx = 0, truerx = 0;
|
||||
if (smooth) {
|
||||
truelx = lx / SUBXRES;
|
||||
truerx = (rx + SUBXRES1) / SUBXRES;
|
||||
|
||||
lx = aaleftmin / SUBXRES;
|
||||
rx = (aarightmax + SUBXRES1) / SUBXRES;
|
||||
if (lx < 0) lx = 0;
|
||||
if (rx > parent.width1) rx = parent.width1;
|
||||
}
|
||||
|
||||
interpX = false;
|
||||
int tr, tg, tb, ta;
|
||||
|
||||
// System.out.println("P2D interp uv " + interpUV + " " +
|
||||
// vertices[2][U] + " " + vertices[2][V]);
|
||||
for (int x = lx; x <= rx; x++) {
|
||||
// map texture based on U, V coords in sp[U] and sp[V]
|
||||
if (interpUV) {
|
||||
int tu = (int) (sp[U] * twidth);
|
||||
int tv = (int) (sp[V] * theight);
|
||||
|
||||
if (tu > twidth1) tu = twidth1;
|
||||
if (tv > theight1) tv = theight1;
|
||||
if (tu < 0) tu = 0;
|
||||
if (tv < 0) tv = 0;
|
||||
|
||||
int txy = tv*twidth + tu;
|
||||
|
||||
int tuf1 = (int) (255f * (sp[U]*twidth - (float)tu));
|
||||
int tvf1 = (int) (255f * (sp[V]*theight - (float)tv));
|
||||
|
||||
// the closer sp[U or V] is to the decimal being zero
|
||||
// the more coverage it should get of the original pixel
|
||||
int tuf = 255 - tuf1;
|
||||
int tvf = 255 - tvf1;
|
||||
|
||||
// this code sucks! filled with bugs and slow as hell!
|
||||
int pixel00 = tpixels[txy];
|
||||
int pixel01 = (tv < theight1) ?
|
||||
tpixels[txy + twidth] : tpixels[txy];
|
||||
int pixel10 = (tu < twidth1) ?
|
||||
tpixels[txy + 1] : tpixels[txy];
|
||||
int pixel11 = ((tv < theight1) && (tu < twidth1)) ?
|
||||
tpixels[txy + twidth + 1] : tpixels[txy];
|
||||
|
||||
int p00, p01, p10, p11;
|
||||
int px0, px1; //, pxy;
|
||||
|
||||
|
||||
// calculate alpha component (ta)
|
||||
|
||||
if (tformat == ALPHA) {
|
||||
px0 = (pixel00*tuf + pixel10*tuf1) >> 8;
|
||||
px1 = (pixel01*tuf + pixel11*tuf1) >> 8;
|
||||
ta = (((px0*tvf + px1*tvf1) >> 8) *
|
||||
(interpARGB ? ((int) (sp[A]*255)) : a2orig)) >> 8;
|
||||
|
||||
} else if (tformat == ARGB) {
|
||||
p00 = (pixel00 >> 24) & 0xff;
|
||||
p01 = (pixel01 >> 24) & 0xff;
|
||||
p10 = (pixel10 >> 24) & 0xff;
|
||||
p11 = (pixel11 >> 24) & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
ta = (((px0*tvf + px1*tvf1) >> 8) *
|
||||
(interpARGB ? ((int) (sp[A]*255)) : a2orig)) >> 8;
|
||||
|
||||
} else { // RGB image, no alpha
|
||||
ta = interpARGB ? ((int) (sp[A]*255)) : a2orig;
|
||||
}
|
||||
|
||||
// calculate r,g,b components (tr, tg, tb)
|
||||
|
||||
if ((tformat == RGB) || (tformat == ARGB)) {
|
||||
p00 = (pixel00 >> 16) & 0xff; // red
|
||||
p01 = (pixel01 >> 16) & 0xff;
|
||||
p10 = (pixel10 >> 16) & 0xff;
|
||||
p11 = (pixel11 >> 16) & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
tr = (((px0*tvf + px1*tvf1) >> 8) *
|
||||
(interpARGB ? ((int) (sp[R]*255)) : r2)) >> 8;
|
||||
|
||||
p00 = (pixel00 >> 8) & 0xff; // green
|
||||
p01 = (pixel01 >> 8) & 0xff;
|
||||
p10 = (pixel10 >> 8) & 0xff;
|
||||
p11 = (pixel11 >> 8) & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
tg = (((px0*tvf + px1*tvf1) >> 8) *
|
||||
(interpARGB ? ((int) (sp[G]*255)) : g2)) >> 8;
|
||||
|
||||
p00 = pixel00 & 0xff; // blue
|
||||
p01 = pixel01 & 0xff;
|
||||
p10 = pixel10 & 0xff;
|
||||
p11 = pixel11 & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
tb = (((px0*tvf + px1*tvf1) >> 8) *
|
||||
(interpARGB ? ((int) (sp[B]*255)) : b2)) >> 8;
|
||||
|
||||
} else { // alpha image, only use current fill color
|
||||
if (interpARGB) {
|
||||
tr = (int) (sp[R] * 255);
|
||||
tg = (int) (sp[G] * 255);
|
||||
tb = (int) (sp[B] * 255);
|
||||
|
||||
} else {
|
||||
tr = r2;
|
||||
tg = g2;
|
||||
tb = b2;
|
||||
}
|
||||
}
|
||||
|
||||
int weight = smooth ? coverage(x) : 255;
|
||||
if (weight != 255) ta = ta*weight >> 8;
|
||||
|
||||
if ((ta == 254) || (ta == 255)) { // if (ta & 0xf8) would be good
|
||||
// no need to blend
|
||||
pixels[offset+x] = 0xff000000 | (tr << 16) | (tg << 8) | tb;
|
||||
|
||||
} else {
|
||||
// blend with pixel on screen
|
||||
int a1 = 255-ta;
|
||||
int r1 = (pixels[offset+x] >> 16) & 0xff;
|
||||
int g1 = (pixels[offset+x] >> 8) & 0xff;
|
||||
int b1 = (pixels[offset+x]) & 0xff;
|
||||
|
||||
pixels[offset+x] = 0xff000000 |
|
||||
(((tr*ta + r1*a1) >> 8) << 16) |
|
||||
((tg*ta + g1*a1) & 0xff00) |
|
||||
((tb*ta + b1*a1) >> 8);
|
||||
}
|
||||
|
||||
} else { // no image applied
|
||||
int weight = smooth ? coverage(x) : 255;
|
||||
|
||||
if (interpARGB) {
|
||||
r2 = (int) (sp[R] * 255);
|
||||
g2 = (int) (sp[G] * 255);
|
||||
b2 = (int) (sp[B] * 255);
|
||||
if (sp[A] != 1) weight = (weight * ((int) (sp[A] * 255))) >> 8;
|
||||
if (weight == 255) {
|
||||
rgba = 0xff000000 | (r2 << 16) | (g2 << 8) | b2;
|
||||
}
|
||||
} else {
|
||||
if (a2orig != 255) weight = (weight * a2orig) >> 8;
|
||||
}
|
||||
|
||||
if (weight == 255) {
|
||||
// no blend, no aa, just the rgba
|
||||
pixels[offset+x] = rgba;
|
||||
//zbuffer[offset+x] = sp[Z];
|
||||
|
||||
} else {
|
||||
int r1 = (pixels[offset+x] >> 16) & 0xff;
|
||||
int g1 = (pixels[offset+x] >> 8) & 0xff;
|
||||
int b1 = (pixels[offset+x]) & 0xff;
|
||||
a2 = weight;
|
||||
|
||||
int a1 = 255 - a2;
|
||||
pixels[offset+x] = (0xff000000 |
|
||||
((r1*a1 + r2*a2) >> 8) << 16 |
|
||||
// use & instead of >> and << below
|
||||
((g1*a1 + g2*a2) >> 8) << 8 |
|
||||
((b1*a1 + b2*a2) >> 8));
|
||||
}
|
||||
}
|
||||
|
||||
// if smooth enabled, don't increment values
|
||||
// for the pixel in the stretch out version
|
||||
// of the scanline used to get smooth edges.
|
||||
if (!smooth || ((x >= truelx) && (x <= truerx))) {
|
||||
increment(sp, sdp);
|
||||
}
|
||||
}
|
||||
firstModY = -1;
|
||||
interpX = true;
|
||||
}
|
||||
|
||||
|
||||
// x is in screen, not huge 8x coordinates
|
||||
private int coverage(int x) {
|
||||
if ((x >= aaleftfull) && (x <= aarightfull) &&
|
||||
// important since not all SUBYRES lines may have been covered
|
||||
(firstModY == 0) && (lastModY == SUBYRES1)) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
int pixelLeft = x*SUBXRES; // huh?
|
||||
int pixelRight = pixelLeft + 8;
|
||||
|
||||
int amt = 0;
|
||||
for (int i = firstModY; i <= lastModY; i++) {
|
||||
if ((aaleft[i] > pixelRight) || (aaright[i] < pixelLeft)) {
|
||||
continue;
|
||||
}
|
||||
// does this need a +1 ?
|
||||
amt += ((aaright[i] < pixelRight ? aaright[i] : pixelRight) -
|
||||
(aaleft[i] > pixelLeft ? aaleft[i] : pixelLeft));
|
||||
}
|
||||
amt <<= 2;
|
||||
return (amt == 256) ? 255 : amt;
|
||||
}
|
||||
|
||||
|
||||
private void incrementalizeY(float p1[], float p2[],
|
||||
float p[], float dp[], int y) {
|
||||
float delta = p2[TY] - p1[TY];
|
||||
if (delta == 0) delta = 1;
|
||||
float fraction = y + 0.5f - p1[TY];
|
||||
|
||||
if (interpX) {
|
||||
dp[TX] = (p2[TX] - p1[TX]) / delta;
|
||||
p[TX] = p1[TX] + dp[TX] * fraction;
|
||||
}
|
||||
|
||||
if (interpARGB) {
|
||||
dp[R] = (p2[R] - p1[R]) / delta;
|
||||
dp[G] = (p2[G] - p1[G]) / delta;
|
||||
dp[B] = (p2[B] - p1[B]) / delta;
|
||||
dp[A] = (p2[A] - p1[A]) / delta;
|
||||
p[R] = p1[R] + dp[R] * fraction;
|
||||
p[G] = p1[G] + dp[G] * fraction;
|
||||
p[B] = p1[B] + dp[B] * fraction;
|
||||
p[A] = p1[A] + dp[A] * fraction;
|
||||
}
|
||||
|
||||
if (interpUV) {
|
||||
dp[U] = (p2[U] - p1[U]) / delta;
|
||||
dp[V] = (p2[V] - p1[V]) / delta;
|
||||
|
||||
p[U] = p1[U] + dp[U] * fraction;
|
||||
p[V] = p1[V] + dp[V] * fraction;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void incrementalizeX(float p1[], float p2[],
|
||||
float p[], float dp[], int x) {
|
||||
float delta = p2[TX] - p1[TX];
|
||||
if (delta == 0) delta = 1;
|
||||
float fraction = x + 0.5f - p1[TX];
|
||||
if (smooth) {
|
||||
delta /= SUBXRES;
|
||||
fraction /= SUBXRES;
|
||||
}
|
||||
|
||||
if (interpX) {
|
||||
dp[TX] = (p2[TX] - p1[TX]) / delta;
|
||||
p[TX] = p1[TX] + dp[TX] * fraction;
|
||||
}
|
||||
|
||||
if (interpARGB) {
|
||||
dp[R] = (p2[R] - p1[R]) / delta;
|
||||
dp[G] = (p2[G] - p1[G]) / delta;
|
||||
dp[B] = (p2[B] - p1[B]) / delta;
|
||||
dp[A] = (p2[A] - p1[A]) / delta;
|
||||
p[R] = p1[R] + dp[R] * fraction;
|
||||
p[G] = p1[G] + dp[G] * fraction;
|
||||
p[B] = p1[B] + dp[B] * fraction;
|
||||
p[A] = p1[A] + dp[A] * fraction;
|
||||
}
|
||||
|
||||
if (interpUV) {
|
||||
dp[U] = (p2[U] - p1[U]) / delta;
|
||||
dp[V] = (p2[V] - p1[V]) / delta;
|
||||
|
||||
p[U] = p1[U] + dp[U] * fraction;
|
||||
p[V] = p1[V] + dp[V] * fraction;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void increment(float p[], float dp[]) {
|
||||
if (interpX) p[TX] += dp[TX];
|
||||
|
||||
if (interpARGB) {
|
||||
p[R] += dp[R];
|
||||
p[G] += dp[G];
|
||||
p[B] += dp[B];
|
||||
p[A] += dp[A];
|
||||
}
|
||||
|
||||
if (interpUV) {
|
||||
p[U] += dp[U];
|
||||
p[V] += dp[V];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,955 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2006-08 Ben Fry and Casey Reas
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import processing.core.PApplet;
|
||||
|
||||
|
||||
/**
|
||||
* Datatype for storing shapes. Processing can currently load and display SVG (Scalable Vector Graphics) shapes.
|
||||
* Before a shape is used, it must be loaded with the <b>loadShape()</b> function. The <b>shape()</b> function is used to draw the shape to the display window.
|
||||
* The <b>PShape</b> object contain a group of methods, linked below, that can operate on the shape data.
|
||||
* <br><br>The <b>loadShape()</b> method supports SVG files created with Inkscape and Adobe Illustrator.
|
||||
* It is not a full SVG implementation, but offers some straightforward support for handling vector data.
|
||||
* =advanced
|
||||
*
|
||||
* In-progress class to handle shape data, currently to be considered of
|
||||
* alpha or beta quality. Major structural work may be performed on this class
|
||||
* after the release of Processing 1.0. Such changes may include:
|
||||
*
|
||||
* <ul>
|
||||
* <li> addition of proper accessors to read shape vertex and coloring data
|
||||
* (this is the second most important part of having a PShape class after all).
|
||||
* <li> a means of creating PShape objects ala beginShape() and endShape().
|
||||
* <li> load(), update(), and cache methods ala PImage, so that shapes can
|
||||
* have renderer-specific optimizations, such as vertex arrays in OpenGL.
|
||||
* <li> splitting this class into multiple classes to handle different
|
||||
* varieties of shape data (primitives vs collections of vertices vs paths)
|
||||
* <li> change of package declaration, for instance moving the code into
|
||||
* package processing.shape (if the code grows too much).
|
||||
* </ul>
|
||||
*
|
||||
* <p>For the time being, this class and its shape() and loadShape() friends in
|
||||
* PApplet exist as placeholders for more exciting things to come. If you'd
|
||||
* like to work with this class, make a subclass (see how PShapeSVG works)
|
||||
* and you can play with its internal methods all you like.</p>
|
||||
*
|
||||
* <p>Library developers are encouraged to create PShape objects when loading
|
||||
* shape data, so that they can eventually hook into the bounty that will be
|
||||
* the PShape interface, and the ease of loadShape() and shape().</p>
|
||||
*
|
||||
* @webref Shape
|
||||
* @usage Web & Application
|
||||
* @see PApplet#shape(PShape)
|
||||
* @see PApplet#loadShape(String)
|
||||
* @see PApplet#shapeMode(int)
|
||||
* @instanceName sh any variable of type PShape
|
||||
*/
|
||||
public class PShape implements PConstants {
|
||||
|
||||
protected String name;
|
||||
protected HashMap<String,PShape> nameTable;
|
||||
|
||||
/** Generic, only draws its child objects. */
|
||||
static public final int GROUP = 0;
|
||||
/** A line, ellipse, arc, image, etc. */
|
||||
static public final int PRIMITIVE = 1;
|
||||
/** A series of vertex, curveVertex, and bezierVertex calls. */
|
||||
static public final int PATH = 2;
|
||||
/** Collections of vertices created with beginShape(). */
|
||||
static public final int GEOMETRY = 3;
|
||||
/** The shape type, one of GROUP, PRIMITIVE, PATH, or GEOMETRY. */
|
||||
protected int family;
|
||||
|
||||
/** ELLIPSE, LINE, QUAD; TRIANGLE_FAN, QUAD_STRIP; etc. */
|
||||
protected int kind;
|
||||
|
||||
protected PMatrix matrix;
|
||||
|
||||
/** Texture or image data associated with this shape. */
|
||||
protected PImage image;
|
||||
|
||||
// boundary box of this shape
|
||||
//protected float x;
|
||||
//protected float y;
|
||||
//protected float width;
|
||||
//protected float height;
|
||||
/**
|
||||
* The width of the PShape document.
|
||||
* @webref
|
||||
* @brief Shape document width
|
||||
*/
|
||||
public float width;
|
||||
/**
|
||||
* The width of the PShape document.
|
||||
* @webref
|
||||
* @brief Shape document height
|
||||
*/
|
||||
public float height;
|
||||
|
||||
// set to false if the object is hidden in the layers palette
|
||||
protected boolean visible = true;
|
||||
|
||||
protected boolean stroke;
|
||||
protected int strokeColor;
|
||||
protected float strokeWeight; // default is 1
|
||||
protected int strokeCap;
|
||||
protected int strokeJoin;
|
||||
|
||||
protected boolean fill;
|
||||
protected int fillColor;
|
||||
|
||||
/** Temporary toggle for whether styles should be honored. */
|
||||
protected boolean style = true;
|
||||
|
||||
/** For primitive shapes in particular, parms like x/y/w/h or x1/y1/x2/y2. */
|
||||
protected float[] params;
|
||||
|
||||
protected int vertexCount;
|
||||
/**
|
||||
* When drawing POLYGON shapes, the second param is an array of length
|
||||
* VERTEX_FIELD_COUNT. When drawing PATH shapes, the second param has only
|
||||
* two variables.
|
||||
*/
|
||||
protected float[][] vertices;
|
||||
|
||||
static public final int VERTEX = 0;
|
||||
static public final int BEZIER_VERTEX = 1;
|
||||
static public final int CURVE_VERTEX = 2;
|
||||
static public final int BREAK = 3;
|
||||
/** Array of VERTEX, BEZIER_VERTEX, and CURVE_VERTEXT calls. */
|
||||
protected int vertexCodeCount;
|
||||
protected int[] vertexCodes;
|
||||
/** True if this is a closed path. */
|
||||
protected boolean close;
|
||||
|
||||
// should this be called vertices (consistent with PGraphics internals)
|
||||
// or does that hurt flexibility?
|
||||
|
||||
protected PShape parent;
|
||||
protected int childCount;
|
||||
protected PShape[] children;
|
||||
|
||||
// POINTS, LINES, xLINE_STRIP, xLINE_LOOP
|
||||
// TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN
|
||||
// QUADS, QUAD_STRIP
|
||||
// xPOLYGON
|
||||
// static final int PATH = 1; // POLYGON, LINE_LOOP, LINE_STRIP
|
||||
// static final int GROUP = 2;
|
||||
|
||||
// how to handle rectmode/ellipsemode?
|
||||
// are they bitshifted into the constant?
|
||||
// CORNER, CORNERS, CENTER, (CENTER_RADIUS?)
|
||||
// static final int RECT = 3; // could just be QUAD, but would be x1/y1/x2/y2
|
||||
// static final int ELLIPSE = 4;
|
||||
//
|
||||
// static final int VERTEX = 7;
|
||||
// static final int CURVE = 5;
|
||||
// static final int BEZIER = 6;
|
||||
|
||||
|
||||
// fill and stroke functions will need a pointer to the parent
|
||||
// PGraphics object.. may need some kind of createShape() fxn
|
||||
// or maybe the values are stored until draw() is called?
|
||||
|
||||
// attaching images is very tricky.. it's a different type of data
|
||||
|
||||
// material parameters will be thrown out,
|
||||
// except those currently supported (kinds of lights)
|
||||
|
||||
// pivot point for transformations
|
||||
// public float px;
|
||||
// public float py;
|
||||
|
||||
|
||||
public PShape() {
|
||||
this.family = GROUP;
|
||||
}
|
||||
|
||||
|
||||
public PShape(int family) {
|
||||
this.family = family;
|
||||
}
|
||||
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean value "true" if the image is set to be visible, "false" if not. This is modified with the <b>setVisible()</b> parameter.
|
||||
* <br><br>The visibility of a shape is usually controlled by whatever program created the SVG file.
|
||||
* For instance, this parameter is controlled by showing or hiding the shape in the layers palette in Adobe Illustrator.
|
||||
*
|
||||
* @webref
|
||||
* @brief Returns a boolean value "true" if the image is set to be visible, "false" if not
|
||||
*/
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shape to be visible or invisible. This is determined by the value of the <b>visible</b> parameter.
|
||||
* <br><br>The visibility of a shape is usually controlled by whatever program created the SVG file.
|
||||
* For instance, this parameter is controlled by showing or hiding the shape in the layers palette in Adobe Illustrator.
|
||||
* @param visible "false" makes the shape invisible and "true" makes it visible
|
||||
* @webref
|
||||
* @brief Sets the shape to be visible or invisible
|
||||
*/
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disables the shape's style data and uses Processing's current styles. Styles include attributes such as colors, stroke weight, and stroke joints.
|
||||
* =advanced
|
||||
* Overrides this shape's style information and uses PGraphics styles and
|
||||
* colors. Identical to ignoreStyles(true). Also disables styles for all
|
||||
* child shapes.
|
||||
* @webref
|
||||
* @brief Disables the shape's style data and uses Processing styles
|
||||
*/
|
||||
public void disableStyle() {
|
||||
style = false;
|
||||
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
children[i].disableStyle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enables the shape's style data and ignores Processing's current styles. Styles include attributes such as colors, stroke weight, and stroke joints.
|
||||
* @webref
|
||||
* @brief Enables the shape's style data and ignores the Processing styles
|
||||
*/
|
||||
public void enableStyle() {
|
||||
style = true;
|
||||
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
children[i].enableStyle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
// protected void checkBounds() {
|
||||
// if (width == 0 || height == 0) {
|
||||
// // calculate bounds here (also take kids into account)
|
||||
// width = 1;
|
||||
// height = 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Get the width of the drawing area (not necessarily the shape boundary).
|
||||
*/
|
||||
public float getWidth() {
|
||||
//checkBounds();
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the height of the drawing area (not necessarily the shape boundary).
|
||||
*/
|
||||
public float getHeight() {
|
||||
//checkBounds();
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/*
|
||||
boolean strokeSaved;
|
||||
int strokeColorSaved;
|
||||
float strokeWeightSaved;
|
||||
int strokeCapSaved;
|
||||
int strokeJoinSaved;
|
||||
|
||||
boolean fillSaved;
|
||||
int fillColorSaved;
|
||||
|
||||
int rectModeSaved;
|
||||
int ellipseModeSaved;
|
||||
int shapeModeSaved;
|
||||
*/
|
||||
|
||||
|
||||
protected void pre(PGraphics g) {
|
||||
if (matrix != null) {
|
||||
g.pushMatrix();
|
||||
g.applyMatrix(matrix);
|
||||
}
|
||||
|
||||
/*
|
||||
strokeSaved = g.stroke;
|
||||
strokeColorSaved = g.strokeColor;
|
||||
strokeWeightSaved = g.strokeWeight;
|
||||
strokeCapSaved = g.strokeCap;
|
||||
strokeJoinSaved = g.strokeJoin;
|
||||
|
||||
fillSaved = g.fill;
|
||||
fillColorSaved = g.fillColor;
|
||||
|
||||
rectModeSaved = g.rectMode;
|
||||
ellipseModeSaved = g.ellipseMode;
|
||||
shapeModeSaved = g.shapeMode;
|
||||
*/
|
||||
if (style) {
|
||||
g.pushStyle();
|
||||
styles(g);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void styles(PGraphics g) {
|
||||
// should not be necessary because using only the int version of color
|
||||
//parent.colorMode(PConstants.RGB, 255);
|
||||
|
||||
if (stroke) {
|
||||
g.stroke(strokeColor);
|
||||
g.strokeWeight(strokeWeight);
|
||||
g.strokeCap(strokeCap);
|
||||
g.strokeJoin(strokeJoin);
|
||||
} else {
|
||||
g.noStroke();
|
||||
}
|
||||
|
||||
if (fill) {
|
||||
//System.out.println("filling " + PApplet.hex(fillColor));
|
||||
g.fill(fillColor);
|
||||
} else {
|
||||
g.noFill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void post(PGraphics g) {
|
||||
// for (int i = 0; i < childCount; i++) {
|
||||
// children[i].draw(g);
|
||||
// }
|
||||
|
||||
/*
|
||||
// TODO this is not sufficient, since not saving fillR et al.
|
||||
g.stroke = strokeSaved;
|
||||
g.strokeColor = strokeColorSaved;
|
||||
g.strokeWeight = strokeWeightSaved;
|
||||
g.strokeCap = strokeCapSaved;
|
||||
g.strokeJoin = strokeJoinSaved;
|
||||
|
||||
g.fill = fillSaved;
|
||||
g.fillColor = fillColorSaved;
|
||||
|
||||
g.ellipseMode = ellipseModeSaved;
|
||||
*/
|
||||
|
||||
if (matrix != null) {
|
||||
g.popMatrix();
|
||||
}
|
||||
|
||||
if (style) {
|
||||
g.popStyle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called by the following (the shape() command adds the g)
|
||||
* PShape s = loadShapes("blah.svg");
|
||||
* shape(s);
|
||||
*/
|
||||
public void draw(PGraphics g) {
|
||||
if (visible) {
|
||||
pre(g);
|
||||
drawImpl(g);
|
||||
post(g);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws the SVG document.
|
||||
*/
|
||||
public void drawImpl(PGraphics g) {
|
||||
//System.out.println("drawing " + family);
|
||||
if (family == GROUP) {
|
||||
drawGroup(g);
|
||||
} else if (family == PRIMITIVE) {
|
||||
drawPrimitive(g);
|
||||
} else if (family == GEOMETRY) {
|
||||
drawGeometry(g);
|
||||
} else if (family == PATH) {
|
||||
drawPath(g);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void drawGroup(PGraphics g) {
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
children[i].draw(g);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void drawPrimitive(PGraphics g) {
|
||||
if (kind == POINT) {
|
||||
g.point(params[0], params[1]);
|
||||
|
||||
} else if (kind == LINE) {
|
||||
if (params.length == 4) { // 2D
|
||||
g.line(params[0], params[1],
|
||||
params[2], params[3]);
|
||||
} else { // 3D
|
||||
g.line(params[0], params[1], params[2],
|
||||
params[3], params[4], params[5]);
|
||||
}
|
||||
|
||||
} else if (kind == TRIANGLE) {
|
||||
g.triangle(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5]);
|
||||
|
||||
} else if (kind == QUAD) {
|
||||
g.quad(params[0], params[1],
|
||||
params[2], params[3],
|
||||
params[4], params[5],
|
||||
params[6], params[7]);
|
||||
|
||||
} else if (kind == RECT) {
|
||||
if (image != null) {
|
||||
g.imageMode(CORNER);
|
||||
g.image(image, params[0], params[1], params[2], params[3]);
|
||||
} else {
|
||||
g.rectMode(CORNER);
|
||||
g.rect(params[0], params[1], params[2], params[3]);
|
||||
}
|
||||
|
||||
} else if (kind == ELLIPSE) {
|
||||
g.ellipseMode(CORNER);
|
||||
g.ellipse(params[0], params[1], params[2], params[3]);
|
||||
|
||||
} else if (kind == ARC) {
|
||||
g.ellipseMode(CORNER);
|
||||
g.arc(params[0], params[1], params[2], params[3], params[4], params[5]);
|
||||
|
||||
} else if (kind == BOX) {
|
||||
if (params.length == 1) {
|
||||
g.box(params[0]);
|
||||
} else {
|
||||
g.box(params[0], params[1], params[2]);
|
||||
}
|
||||
|
||||
} else if (kind == SPHERE) {
|
||||
g.sphere(params[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void drawGeometry(PGraphics g) {
|
||||
g.beginShape(kind);
|
||||
if (style) {
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
g.vertex(vertices[i]);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
float[] vert = vertices[i];
|
||||
if (vert[PGraphics.Z] == 0) {
|
||||
g.vertex(vert[X], vert[Y]);
|
||||
} else {
|
||||
g.vertex(vert[X], vert[Y], vert[Z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
g.endShape();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
protected void drawPath(PGraphics g) {
|
||||
g.beginShape();
|
||||
for (int j = 0; j < childCount; j++) {
|
||||
if (j > 0) g.breakShape();
|
||||
int count = children[j].vertexCount;
|
||||
float[][] vert = children[j].vertices;
|
||||
int[] code = children[j].vertexCodes;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (style) {
|
||||
if (children[j].fill) {
|
||||
g.fill(vert[i][R], vert[i][G], vert[i][B]);
|
||||
} else {
|
||||
g.noFill();
|
||||
}
|
||||
if (children[j].stroke) {
|
||||
g.stroke(vert[i][R], vert[i][G], vert[i][B]);
|
||||
} else {
|
||||
g.noStroke();
|
||||
}
|
||||
}
|
||||
g.edge(vert[i][EDGE] == 1);
|
||||
|
||||
if (code[i] == VERTEX) {
|
||||
g.vertex(vert[i]);
|
||||
|
||||
} else if (code[i] == BEZIER_VERTEX) {
|
||||
float z0 = vert[i+0][Z];
|
||||
float z1 = vert[i+1][Z];
|
||||
float z2 = vert[i+2][Z];
|
||||
if (z0 == 0 && z1 == 0 && z2 == 0) {
|
||||
g.bezierVertex(vert[i+0][X], vert[i+0][Y], z0,
|
||||
vert[i+1][X], vert[i+1][Y], z1,
|
||||
vert[i+2][X], vert[i+2][Y], z2);
|
||||
} else {
|
||||
g.bezierVertex(vert[i+0][X], vert[i+0][Y],
|
||||
vert[i+1][X], vert[i+1][Y],
|
||||
vert[i+2][X], vert[i+2][Y]);
|
||||
}
|
||||
} else if (code[i] == CURVE_VERTEX) {
|
||||
float z = vert[i][Z];
|
||||
if (z == 0) {
|
||||
g.curveVertex(vert[i][X], vert[i][Y]);
|
||||
} else {
|
||||
g.curveVertex(vert[i][X], vert[i][Y], z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
g.endShape();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
protected void drawPath(PGraphics g) {
|
||||
// Paths might be empty (go figure)
|
||||
// http://dev.processing.org/bugs/show_bug.cgi?id=982
|
||||
if (vertices == null) return;
|
||||
|
||||
g.beginShape();
|
||||
|
||||
if (vertexCodeCount == 0) { // each point is a simple vertex
|
||||
if (vertices[0].length == 2) { // drawing 2D vertices
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
g.vertex(vertices[i][X], vertices[i][Y]);
|
||||
}
|
||||
} else { // drawing 3D vertices
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
g.vertex(vertices[i][X], vertices[i][Y], vertices[i][Z]);
|
||||
}
|
||||
}
|
||||
|
||||
} else { // coded set of vertices
|
||||
int index = 0;
|
||||
|
||||
if (vertices[0].length == 2) { // drawing a 2D path
|
||||
for (int j = 0; j < vertexCodeCount; j++) {
|
||||
switch (vertexCodes[j]) {
|
||||
|
||||
case VERTEX:
|
||||
g.vertex(vertices[index][X], vertices[index][Y]);
|
||||
index++;
|
||||
break;
|
||||
|
||||
case BEZIER_VERTEX:
|
||||
g.bezierVertex(vertices[index+0][X], vertices[index+0][Y],
|
||||
vertices[index+1][X], vertices[index+1][Y],
|
||||
vertices[index+2][X], vertices[index+2][Y]);
|
||||
index += 3;
|
||||
break;
|
||||
|
||||
case CURVE_VERTEX:
|
||||
g.curveVertex(vertices[index][X], vertices[index][Y]);
|
||||
index++;
|
||||
|
||||
case BREAK:
|
||||
g.breakShape();
|
||||
}
|
||||
}
|
||||
} else { // drawing a 3D path
|
||||
for (int j = 0; j < vertexCodeCount; j++) {
|
||||
switch (vertexCodes[j]) {
|
||||
|
||||
case VERTEX:
|
||||
g.vertex(vertices[index][X], vertices[index][Y], vertices[index][Z]);
|
||||
index++;
|
||||
break;
|
||||
|
||||
case BEZIER_VERTEX:
|
||||
g.bezierVertex(vertices[index+0][X], vertices[index+0][Y], vertices[index+0][Z],
|
||||
vertices[index+1][X], vertices[index+1][Y], vertices[index+1][Z],
|
||||
vertices[index+2][X], vertices[index+2][Y], vertices[index+2][Z]);
|
||||
index += 3;
|
||||
break;
|
||||
|
||||
case CURVE_VERTEX:
|
||||
g.curveVertex(vertices[index][X], vertices[index][Y], vertices[index][Z]);
|
||||
index++;
|
||||
|
||||
case BREAK:
|
||||
g.breakShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
g.endShape(close ? CLOSE : OPEN);
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
public int getChildCount() {
|
||||
return childCount;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param index the layer position of the shape to get
|
||||
*/
|
||||
public PShape getChild(int index) {
|
||||
return children[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a child shape from a parent shape. Specify the name of the shape with the <b>target</b> parameter.
|
||||
* The shape is returned as a <b>PShape</b> object, or <b>null</b> is returned if there is an error.
|
||||
* @param target the name of the shape to get
|
||||
* @webref
|
||||
* @brief Returns a child element of a shape as a PShape object
|
||||
*/
|
||||
public PShape getChild(String target) {
|
||||
if (name != null && name.equals(target)) {
|
||||
return this;
|
||||
}
|
||||
if (nameTable != null) {
|
||||
PShape found = nameTable.get(target);
|
||||
if (found != null) return found;
|
||||
}
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
PShape found = children[i].getChild(target);
|
||||
if (found != null) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as getChild(name), except that it first walks all the way up the
|
||||
* hierarchy to the farthest parent, so that children can be found anywhere.
|
||||
*/
|
||||
public PShape findChild(String target) {
|
||||
if (parent == null) {
|
||||
return getChild(target);
|
||||
|
||||
} else {
|
||||
return parent.findChild(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// can't be just 'add' because that suggests additive geometry
|
||||
public void addChild(PShape who) {
|
||||
if (children == null) {
|
||||
children = new PShape[1];
|
||||
}
|
||||
if (childCount == children.length) {
|
||||
children = (PShape[]) PApplet.expand(children);
|
||||
}
|
||||
children[childCount++] = who;
|
||||
who.parent = this;
|
||||
|
||||
if (who.getName() != null) {
|
||||
addName(who.getName(), who);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a shape to the name lookup table.
|
||||
*/
|
||||
protected void addName(String nom, PShape shape) {
|
||||
if (parent != null) {
|
||||
parent.addName(nom, shape);
|
||||
} else {
|
||||
if (nameTable == null) {
|
||||
nameTable = new HashMap<String,PShape>();
|
||||
}
|
||||
nameTable.put(nom, shape);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public PShape createGroup() {
|
||||
// PShape group = new PShape();
|
||||
// group.kind = GROUP;
|
||||
// addChild(group);
|
||||
// return group;
|
||||
// }
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
// translate, rotate, scale, apply (no push/pop)
|
||||
// these each call matrix.translate, etc
|
||||
// if matrix is null when one is called,
|
||||
// it is created and set to identity
|
||||
|
||||
public void translate(float tx, float ty) {
|
||||
checkMatrix(2);
|
||||
matrix.translate(tx, ty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies an amount to displace the shape. The <b>x</b> parameter specifies left/right translation, the <b>y</b> parameter specifies up/down translation, and the <b>z</b> parameter specifies translations toward/away from the screen. Subsequent calls to the method accumulates the effect. For example, calling <b>translate(50, 0)</b> and then <b>translate(20, 0)</b> is the same as <b>translate(70, 0)</b>. This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
|
||||
* <br><br>Using this method with the <b>z</b> parameter requires using the P3D or OPENGL parameter in combination with size.
|
||||
* @webref
|
||||
* @param tx left/right translation
|
||||
* @param ty up/down translation
|
||||
* @param tz forward/back translation
|
||||
* @brief Displaces the shape
|
||||
*/
|
||||
public void translate(float tx, float ty, float tz) {
|
||||
checkMatrix(3);
|
||||
matrix.translate(tx, ty, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a shape around the x-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
|
||||
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
|
||||
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateX(HALF_PI)</b> and then <b>rotateX(HALF_PI)</b> is the same as <b>rotateX(PI)</b>.
|
||||
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
|
||||
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
|
||||
* @param angle angle of rotation specified in radians
|
||||
* @webref
|
||||
* @brief Rotates the shape around the x-axis
|
||||
*/
|
||||
public void rotateX(float angle) {
|
||||
rotate(angle, 1, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a shape around the y-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
|
||||
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
|
||||
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateY(HALF_PI)</b> and then <b>rotateY(HALF_PI)</b> is the same as <b>rotateY(PI)</b>.
|
||||
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
|
||||
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
|
||||
* @param angle angle of rotation specified in radians
|
||||
* @webref
|
||||
* @brief Rotates the shape around the y-axis
|
||||
*/
|
||||
public void rotateY(float angle) {
|
||||
rotate(angle, 0, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rotates a shape around the z-axis the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
|
||||
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
|
||||
* Subsequent calls to the method accumulates the effect. For example, calling <b>rotateZ(HALF_PI)</b> and then <b>rotateZ(HALF_PI)</b> is the same as <b>rotateZ(PI)</b>.
|
||||
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
|
||||
* <br><br>This method requires a 3D renderer. You need to pass P3D or OPENGL as a third parameter into the <b>size()</b> method as shown in the example above.
|
||||
* @param angle angle of rotation specified in radians
|
||||
* @webref
|
||||
* @brief Rotates the shape around the z-axis
|
||||
*/
|
||||
public void rotateZ(float angle) {
|
||||
rotate(angle, 0, 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a shape the amount specified by the <b>angle</b> parameter. Angles should be specified in radians (values from 0 to TWO_PI) or converted to radians with the <b>radians()</b> method.
|
||||
* <br><br>Shapes are always rotated around the upper-left corner of their bounding box. Positive numbers rotate objects in a clockwise direction.
|
||||
* Transformations apply to everything that happens after and subsequent calls to the method accumulates the effect.
|
||||
* For example, calling <b>rotate(HALF_PI)</b> and then <b>rotate(HALF_PI)</b> is the same as <b>rotate(PI)</b>.
|
||||
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
|
||||
* @param angle angle of rotation specified in radians
|
||||
* @webref
|
||||
* @brief Rotates the shape
|
||||
*/
|
||||
public void rotate(float angle) {
|
||||
checkMatrix(2); // at least 2...
|
||||
matrix.rotate(angle);
|
||||
}
|
||||
|
||||
|
||||
public void rotate(float angle, float v0, float v1, float v2) {
|
||||
checkMatrix(3);
|
||||
matrix.rotate(angle, v0, v1, v2);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* @param s percentage to scale the object
|
||||
*/
|
||||
public void scale(float s) {
|
||||
checkMatrix(2); // at least 2...
|
||||
matrix.scale(s);
|
||||
}
|
||||
|
||||
|
||||
public void scale(float x, float y) {
|
||||
checkMatrix(2);
|
||||
matrix.scale(x, y);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Increases or decreases the size of a shape by expanding and contracting vertices. Shapes always scale from the relative origin of their bounding box.
|
||||
* Scale values are specified as decimal percentages. For example, the method call <b>scale(2.0)</b> increases the dimension of a shape by 200%.
|
||||
* Subsequent calls to the method multiply the effect. For example, calling <b>scale(2.0)</b> and then <b>scale(1.5)</b> is the same as <b>scale(3.0)</b>.
|
||||
* This transformation is applied directly to the shape, it's not refreshed each time <b>draw()</b> is run.
|
||||
* <br><br>Using this fuction with the <b>z</b> parameter requires passing P3D or OPENGL into the size() parameter.
|
||||
* @param x percentage to scale the object in the x-axis
|
||||
* @param y percentage to scale the object in the y-axis
|
||||
* @param z percentage to scale the object in the z-axis
|
||||
* @webref
|
||||
* @brief Increases and decreases the size of a shape
|
||||
*/
|
||||
public void scale(float x, float y, float z) {
|
||||
checkMatrix(3);
|
||||
matrix.scale(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
public void resetMatrix() {
|
||||
checkMatrix(2);
|
||||
matrix.reset();
|
||||
}
|
||||
|
||||
|
||||
public void applyMatrix(PMatrix source) {
|
||||
if (source instanceof PMatrix2D) {
|
||||
applyMatrix((PMatrix2D) source);
|
||||
} else if (source instanceof PMatrix3D) {
|
||||
applyMatrix((PMatrix3D) source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void applyMatrix(PMatrix2D source) {
|
||||
applyMatrix(source.m00, source.m01, 0, source.m02,
|
||||
source.m10, source.m11, 0, source.m12,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void applyMatrix(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12) {
|
||||
checkMatrix(2);
|
||||
matrix.apply(n00, n01, n02, 0,
|
||||
n10, n11, n12, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void apply(PMatrix3D source) {
|
||||
applyMatrix(source.m00, source.m01, source.m02, source.m03,
|
||||
source.m10, source.m11, source.m12, source.m13,
|
||||
source.m20, source.m21, source.m22, source.m23,
|
||||
source.m30, source.m31, source.m32, source.m33);
|
||||
}
|
||||
|
||||
|
||||
public void applyMatrix(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
checkMatrix(3);
|
||||
matrix.apply(n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23,
|
||||
n30, n31, n32, n33);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Make sure that the shape's matrix is 1) not null, and 2) has a matrix
|
||||
* that can handle <em>at least</em> the specified number of dimensions.
|
||||
*/
|
||||
protected void checkMatrix(int dimensions) {
|
||||
if (matrix == null) {
|
||||
if (dimensions == 2) {
|
||||
matrix = new PMatrix2D();
|
||||
} else {
|
||||
matrix = new PMatrix3D();
|
||||
}
|
||||
} else if (dimensions == 3 && (matrix instanceof PMatrix2D)) {
|
||||
// time for an upgrayedd for a double dose of my pimpin'
|
||||
matrix = new PMatrix3D(matrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/**
|
||||
* Center the shape based on its bounding box. Can't assume
|
||||
* that the bounding box is 0, 0, width, height. Common case will be
|
||||
* opening a letter size document in Illustrator, and drawing something
|
||||
* in the middle, then reading it in as an svg file.
|
||||
* This will also need to flip the y axis (scale(1, -1)) in cases
|
||||
* like Adobe Illustrator where the coordinates start at the bottom.
|
||||
*/
|
||||
// public void center() {
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Set the pivot point for all transformations.
|
||||
*/
|
||||
// public void pivot(float x, float y) {
|
||||
// px = x;
|
||||
// py = y;
|
||||
// }
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,968 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-08 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
|
||||
/**
|
||||
* Smoothed triangle renderer for P3D.
|
||||
*
|
||||
* Based off of the PPolygon class in old versions of Processing.
|
||||
* Name and location of this class will change in a future release.
|
||||
*/
|
||||
public class PSmoothTriangle implements PConstants {
|
||||
|
||||
// really this is "debug" but..
|
||||
private static final boolean EWJORDAN = false;
|
||||
private static final boolean FRY = false;
|
||||
|
||||
// identical to the constants from PGraphics
|
||||
|
||||
static final int X = 0; // transformed xyzw
|
||||
static final int Y = 1; // formerly SX SY SZ
|
||||
static final int Z = 2;
|
||||
|
||||
static final int R = 3; // actual rgb, after lighting
|
||||
static final int G = 4; // fill stored here, transform in place
|
||||
static final int B = 5;
|
||||
static final int A = 6;
|
||||
|
||||
static final int U = 7; // texture
|
||||
static final int V = 8;
|
||||
|
||||
static final int DEFAULT_SIZE = 64; // this is needed for spheres
|
||||
float vertices[][] = new float[DEFAULT_SIZE][PGraphics.VERTEX_FIELD_COUNT];
|
||||
int vertexCount;
|
||||
|
||||
|
||||
// after some fiddling, this seems to produce the best results
|
||||
static final int ZBUFFER_MIN_COVERAGE = 204;
|
||||
|
||||
float r[] = new float[DEFAULT_SIZE]; // storage used by incrementalize
|
||||
float dr[] = new float[DEFAULT_SIZE];
|
||||
float l[] = new float[DEFAULT_SIZE]; // more storage for incrementalize
|
||||
float dl[] = new float[DEFAULT_SIZE];
|
||||
float sp[] = new float[DEFAULT_SIZE]; // temporary storage for scanline
|
||||
float sdp[] = new float[DEFAULT_SIZE];
|
||||
|
||||
// color and xyz are always interpolated
|
||||
boolean interpX;
|
||||
boolean interpZ;
|
||||
boolean interpUV; // is this necessary? could just check timage != null
|
||||
boolean interpARGB;
|
||||
|
||||
int rgba;
|
||||
int r2, g2, b2, a2, a2orig;
|
||||
|
||||
boolean noDepthTest;
|
||||
|
||||
PGraphics3D parent;
|
||||
int pixels[];
|
||||
float[] zbuffer;
|
||||
|
||||
// the parent's width/height,
|
||||
// or if smooth is enabled, parent's w/h scaled
|
||||
// up by the smooth dimension
|
||||
int width, height;
|
||||
int width1, height1;
|
||||
|
||||
PImage timage;
|
||||
int tpixels[];
|
||||
int theight, twidth;
|
||||
int theight1, twidth1;
|
||||
int tformat;
|
||||
|
||||
// temp fix to behave like SMOOTH_IMAGES
|
||||
// TODO ewjordan: can probably remove this variable
|
||||
boolean texture_smooth;
|
||||
|
||||
// for anti-aliasing
|
||||
static final int SUBXRES = 8;
|
||||
static final int SUBXRES1 = 7;
|
||||
static final int SUBYRES = 8;
|
||||
static final int SUBYRES1 = 7;
|
||||
static final int MAX_COVERAGE = SUBXRES * SUBYRES;
|
||||
|
||||
boolean smooth;
|
||||
int firstModY;
|
||||
int lastModY;
|
||||
int lastY;
|
||||
int aaleft[] = new int[SUBYRES];
|
||||
int aaright[] = new int[SUBYRES];
|
||||
int aaleftmin, aarightmin;
|
||||
int aaleftmax, aarightmax;
|
||||
int aaleftfull, aarightfull;
|
||||
|
||||
/* Variables needed for accurate texturing. */
|
||||
//private PMatrix textureMatrix = new PMatrix3D();
|
||||
private float[] camX = new float[3];
|
||||
private float[] camY = new float[3];
|
||||
private float[] camZ = new float[3];
|
||||
private float ax,ay,az;
|
||||
private float bx,by,bz;
|
||||
private float cx,cy,cz;
|
||||
private float nearPlaneWidth, nearPlaneHeight, nearPlaneDepth;
|
||||
//private float newax, newbx, newcx;
|
||||
private float xmult, ymult;
|
||||
|
||||
|
||||
final private int MODYRES(int y) {
|
||||
return (y & SUBYRES1);
|
||||
}
|
||||
|
||||
|
||||
public PSmoothTriangle(PGraphics3D iparent) {
|
||||
parent = iparent;
|
||||
reset(0);
|
||||
}
|
||||
|
||||
|
||||
public void reset(int count) {
|
||||
vertexCount = count;
|
||||
interpX = true;
|
||||
interpZ = true;
|
||||
interpUV = false;
|
||||
interpARGB = true;
|
||||
timage = null;
|
||||
}
|
||||
|
||||
|
||||
public float[] nextVertex() {
|
||||
if (vertexCount == vertices.length) {
|
||||
//parent.message(CHATTER, "re-allocating for " +
|
||||
// (vertexCount*2) + " vertices");
|
||||
float temp[][] = new float[vertexCount<<1][PGraphics.VERTEX_FIELD_COUNT];
|
||||
System.arraycopy(vertices, 0, temp, 0, vertexCount);
|
||||
vertices = temp;
|
||||
|
||||
r = new float[vertices.length];
|
||||
dr = new float[vertices.length];
|
||||
l = new float[vertices.length];
|
||||
dl = new float[vertices.length];
|
||||
sp = new float[vertices.length];
|
||||
sdp = new float[vertices.length];
|
||||
}
|
||||
return vertices[vertexCount++]; // returns v[0], sets vc to 1
|
||||
}
|
||||
|
||||
|
||||
public void texture(PImage image) {
|
||||
this.timage = image;
|
||||
this.tpixels = image.pixels;
|
||||
this.twidth = image.width;
|
||||
this.theight = image.height;
|
||||
this.tformat = image.format;
|
||||
|
||||
twidth1 = twidth - 1;
|
||||
theight1 = theight - 1;
|
||||
interpUV = true;
|
||||
}
|
||||
|
||||
public void render() {
|
||||
if (vertexCount < 3) return;
|
||||
|
||||
smooth = true;//TODO
|
||||
// these may have changed due to a resize()
|
||||
// so they should be refreshed here
|
||||
pixels = parent.pixels;
|
||||
zbuffer = parent.zbuffer;
|
||||
|
||||
noDepthTest = false;//parent.hints[DISABLE_DEPTH_TEST];
|
||||
|
||||
// In 0148+, should always be true if this code is called at all
|
||||
//smooth = parent.smooth;
|
||||
|
||||
// by default, text turns on smooth for the textures
|
||||
// themselves. but this should be shut off if the hint
|
||||
// for DISABLE_TEXT_SMOOTH is set.
|
||||
texture_smooth = true;
|
||||
|
||||
width = smooth ? parent.width*SUBXRES : parent.width;
|
||||
height = smooth ? parent.height*SUBYRES : parent.height;
|
||||
|
||||
width1 = width - 1;
|
||||
height1 = height - 1;
|
||||
|
||||
if (!interpARGB) {
|
||||
r2 = (int) (vertices[0][R] * 255);
|
||||
g2 = (int) (vertices[0][G] * 255);
|
||||
b2 = (int) (vertices[0][B] * 255);
|
||||
a2 = (int) (vertices[0][A] * 255);
|
||||
a2orig = a2; // save an extra copy
|
||||
rgba = 0xff000000 | (r2 << 16) | (g2 << 8) | b2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
r[i] = 0; dr[i] = 0; l[i] = 0; dl[i] = 0;
|
||||
}
|
||||
|
||||
if (smooth) {
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
vertices[i][X] *= SUBXRES;
|
||||
vertices[i][Y] *= SUBYRES;
|
||||
}
|
||||
firstModY = -1;
|
||||
}
|
||||
|
||||
// find top vertex (y is zero at top, higher downwards)
|
||||
int topi = 0;
|
||||
float ymin = vertices[0][Y];
|
||||
float ymax = vertices[0][Y]; // fry 031001
|
||||
for (int i = 1; i < vertexCount; i++) {
|
||||
if (vertices[i][Y] < ymin) {
|
||||
ymin = vertices[i][Y];
|
||||
topi = i;
|
||||
}
|
||||
if (vertices[i][Y] > ymax) ymax = vertices[i][Y];
|
||||
}
|
||||
|
||||
// the last row is an exceptional case, because there won't
|
||||
// necessarily be 8 rows of subpixel lines that will force
|
||||
// the final line to render. so instead, the algo keeps track
|
||||
// of the lastY (in subpixel resolution) that will be rendered
|
||||
// and that will force a scanline to happen the same as
|
||||
// every eighth in the other situations
|
||||
//lastY = -1; // fry 031001
|
||||
lastY = (int) (ymax - 0.5f); // global to class bc used by other fxns
|
||||
|
||||
int lefti = topi; // li, index of left vertex
|
||||
int righti = topi; // ri, index of right vertex
|
||||
int y = (int) (ymin + 0.5f); // current scan line
|
||||
int lefty = y - 1; // lower end of left edge
|
||||
int righty = y - 1; // lower end of right edge
|
||||
|
||||
interpX = true;
|
||||
|
||||
int remaining = vertexCount;
|
||||
|
||||
// scan in y, activating new edges on left & right
|
||||
// as scan line passes over new vertices
|
||||
while (remaining > 0) {
|
||||
// advance left edge?
|
||||
while ((lefty <= y) && (remaining > 0)) {
|
||||
remaining--;
|
||||
// step ccw down left side
|
||||
int i = (lefti != 0) ? (lefti-1) : (vertexCount-1);
|
||||
incrementalize_y(vertices[lefti], vertices[i], l, dl, y);
|
||||
lefty = (int) (vertices[i][Y] + 0.5f);
|
||||
lefti = i;
|
||||
}
|
||||
|
||||
// advance right edge?
|
||||
while ((righty <= y) && (remaining > 0)) {
|
||||
remaining--;
|
||||
// step cw down right edge
|
||||
int i = (righti != vertexCount-1) ? (righti + 1) : 0;
|
||||
incrementalize_y(vertices[righti], vertices[i], r, dr, y);
|
||||
righty = (int) (vertices[i][Y] + 0.5f);
|
||||
righti = i;
|
||||
}
|
||||
|
||||
// do scanlines till end of l or r edge
|
||||
while (y < lefty && y < righty) {
|
||||
// this doesn't work because it's not always set here
|
||||
//if (remaining == 0) {
|
||||
//lastY = (lefty < righty) ? lefty-1 : righty-1;
|
||||
//System.out.println("lastY is " + lastY);
|
||||
//}
|
||||
|
||||
if ((y >= 0) && (y < height)) {
|
||||
//try { // hopefully this bug is fixed
|
||||
if (l[X] <= r[X]) scanline(y, l, r);
|
||||
else scanline(y, r, l);
|
||||
//} catch (ArrayIndexOutOfBoundsException e) {
|
||||
//e.printStackTrace();
|
||||
//}
|
||||
}
|
||||
y++;
|
||||
// this increment probably needs to be different
|
||||
// UV and RGB shouldn't be incremented until line is emitted
|
||||
increment(l, dl);
|
||||
increment(r, dr);
|
||||
}
|
||||
}
|
||||
//if (smooth) {
|
||||
//System.out.println("y/lasty/lastmody = " + y + " " + lastY + " " + lastModY);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
public void unexpand() {
|
||||
if (smooth) {
|
||||
for (int i = 0; i < vertexCount; i++) {
|
||||
vertices[i][X] /= SUBXRES;
|
||||
vertices[i][Y] /= SUBYRES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void scanline(int y, float l[], float r[]) {
|
||||
//System.out.println("scanline " + y);
|
||||
for (int i = 0; i < vertexCount; i++) { // should be moved later
|
||||
sp[i] = 0; sdp[i] = 0;
|
||||
}
|
||||
|
||||
// this rounding doesn't seem to be relevant with smooth
|
||||
int lx = (int) (l[X] + 0.49999f); // ceil(l[X]-.5);
|
||||
if (lx < 0) lx = 0;
|
||||
int rx = (int) (r[X] - 0.5f);
|
||||
if (rx > width1) rx = width1;
|
||||
|
||||
if (lx > rx) return;
|
||||
|
||||
if (smooth) {
|
||||
int mody = MODYRES(y);
|
||||
|
||||
aaleft[mody] = lx;
|
||||
aaright[mody] = rx;
|
||||
|
||||
if (firstModY == -1) {
|
||||
firstModY = mody;
|
||||
aaleftmin = lx; aaleftmax = lx;
|
||||
aarightmin = rx; aarightmax = rx;
|
||||
|
||||
} else {
|
||||
if (aaleftmin > aaleft[mody]) aaleftmin = aaleft[mody];
|
||||
if (aaleftmax < aaleft[mody]) aaleftmax = aaleft[mody];
|
||||
if (aarightmin > aaright[mody]) aarightmin = aaright[mody];
|
||||
if (aarightmax < aaright[mody]) aarightmax = aaright[mody];
|
||||
}
|
||||
|
||||
lastModY = mody; // moved up here (before the return) 031001
|
||||
// not the eighth (or lastY) line, so not scanning this time
|
||||
if ((mody != SUBYRES1) && (y != lastY)) return;
|
||||
//lastModY = mody; // eeK! this was missing
|
||||
//return;
|
||||
|
||||
//if (y == lastY) {
|
||||
//System.out.println("y is lasty");
|
||||
//}
|
||||
//lastModY = mody;
|
||||
aaleftfull = aaleftmax/SUBXRES + 1;
|
||||
aarightfull = aarightmin/SUBXRES - 1;
|
||||
}
|
||||
|
||||
// this is the setup, based on lx
|
||||
incrementalize_x(l, r, sp, sdp, lx);
|
||||
//System.out.println(l[V] + " " + r[V] + " " +sp[V] + " " +sdp[V]);
|
||||
|
||||
// scan in x, generating pixels
|
||||
// using parent.width to get actual pixel index
|
||||
// rather than scaled by smooth factor
|
||||
int offset = smooth ? parent.width * (y / SUBYRES) : parent.width*y;
|
||||
|
||||
int truelx = 0, truerx = 0;
|
||||
if (smooth) {
|
||||
truelx = lx / SUBXRES;
|
||||
truerx = (rx + SUBXRES1) / SUBXRES;
|
||||
|
||||
lx = aaleftmin / SUBXRES;
|
||||
rx = (aarightmax + SUBXRES1) / SUBXRES;
|
||||
if (lx < 0) lx = 0;
|
||||
if (rx > parent.width1) rx = parent.width1;
|
||||
}
|
||||
|
||||
// System.out.println("P3D interp uv " + interpUV + " " +
|
||||
// vertices[2][U] + " " + vertices[2][V]);
|
||||
|
||||
interpX = false;
|
||||
int tr, tg, tb, ta;
|
||||
//System.out.println("lx: "+lx + "\nrx: "+rx);
|
||||
for (int x = lx; x <= rx; x++) {
|
||||
|
||||
// added == because things on same plane weren't replacing each other
|
||||
// makes for strangeness in 3D [ewj: yup!], but totally necessary for 2D
|
||||
//if (noDepthTest || (sp[Z] < zbuffer[offset+x])) {
|
||||
if (noDepthTest || (sp[Z] <= zbuffer[offset+x])) {
|
||||
//if (true) {
|
||||
|
||||
// map texture based on U, V coords in sp[U] and sp[V]
|
||||
if (interpUV) {
|
||||
int tu = (int)sp[U];
|
||||
int tv = (int)sp[V];
|
||||
|
||||
if (tu > twidth1) tu = twidth1;
|
||||
if (tv > theight1) tv = theight1;
|
||||
if (tu < 0) tu = 0;
|
||||
if (tv < 0) tv = 0;
|
||||
|
||||
int txy = tv*twidth + tu;
|
||||
//System.out.println("tu: "+tu+" ; tv: "+tv+" ; txy: "+txy);
|
||||
float[] uv = new float[2];
|
||||
txy = getTextureIndex(x, y*1.0f/SUBYRES, uv);
|
||||
// txy = getTextureIndex(x* 1.0f/SUBXRES, y*1.0f/SUBYRES, uv);
|
||||
|
||||
tu = (int)uv[0]; tv = (int)uv[1];
|
||||
// if (tu > twidth1) tu = twidth1;
|
||||
// if (tv > theight1) tv = theight1;
|
||||
// if (tu < 0) tu = 0;
|
||||
// if (tv < 0) tv = 0;
|
||||
txy = twidth*tv + tu;
|
||||
// if (EWJORDAN) System.out.println("x/y/txy:"+x + " " + y + " " +txy);
|
||||
//PApplet.println(sp);
|
||||
|
||||
//smooth = true;
|
||||
if (smooth || texture_smooth) {
|
||||
//if (FRY) System.out.println("sp u v = " + sp[U] + " " + sp[V]);
|
||||
//System.out.println("sp u v = " + sp[U] + " " + sp[V]);
|
||||
// tuf1/tvf1 is the amount of coverage for the adjacent
|
||||
// pixel, which is the decimal percentage.
|
||||
// int tuf1 = (int) (255f * (sp[U] - (float)tu));
|
||||
// int tvf1 = (int) (255f * (sp[V] - (float)tv));
|
||||
|
||||
int tuf1 = (int) (255f * (uv[0] - tu));
|
||||
int tvf1 = (int) (255f * (uv[1] - tv));
|
||||
|
||||
// the closer sp[U or V] is to the decimal being zero
|
||||
// the more coverage it should get of the original pixel
|
||||
int tuf = 255 - tuf1;
|
||||
int tvf = 255 - tvf1;
|
||||
|
||||
// this code sucks! filled with bugs and slow as hell!
|
||||
int pixel00 = tpixels[txy];
|
||||
int pixel01 = (tv < theight1) ? tpixels[txy + twidth] : tpixels[txy];
|
||||
int pixel10 = (tu < twidth1) ? tpixels[txy + 1] : tpixels[txy];
|
||||
int pixel11 = ((tv < theight1) && (tu < twidth1)) ? tpixels[txy + twidth + 1] : tpixels[txy];
|
||||
//System.out.println("1: "+pixel00);
|
||||
//check
|
||||
int p00, p01, p10, p11;
|
||||
int px0, px1; //, pxy;
|
||||
|
||||
if (tformat == ALPHA) {
|
||||
px0 = (pixel00*tuf + pixel10*tuf1) >> 8;
|
||||
px1 = (pixel01*tuf + pixel11*tuf1) >> 8;
|
||||
ta = (((px0*tvf + px1*tvf1) >> 8) *
|
||||
(interpARGB ? ((int) (sp[A]*255)) : a2orig)) >> 8;
|
||||
} else if (tformat == ARGB) {
|
||||
p00 = (pixel00 >> 24) & 0xff;
|
||||
p01 = (pixel01 >> 24) & 0xff;
|
||||
p10 = (pixel10 >> 24) & 0xff;
|
||||
p11 = (pixel11 >> 24) & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
ta = (((px0*tvf + px1*tvf1) >> 8) *
|
||||
(interpARGB ? ((int) (sp[A]*255)) : a2orig)) >> 8;
|
||||
} else { // RGB image, no alpha
|
||||
//ACCTEX: Getting here when smooth is on
|
||||
ta = interpARGB ? ((int) (sp[A]*255)) : a2orig;
|
||||
//System.out.println("4: "+ta + " " +interpARGB + " " + sp[A] + " " + a2orig);
|
||||
//check
|
||||
}
|
||||
|
||||
if ((tformat == RGB) || (tformat == ARGB)) {
|
||||
p00 = (pixel00 >> 16) & 0xff; // red
|
||||
p01 = (pixel01 >> 16) & 0xff;
|
||||
p10 = (pixel10 >> 16) & 0xff;
|
||||
p11 = (pixel11 >> 16) & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
tr = (((px0*tvf + px1*tvf1) >> 8) * (interpARGB ? ((int) (sp[R]*255)) : r2)) >> 8;
|
||||
|
||||
p00 = (pixel00 >> 8) & 0xff; // green
|
||||
p01 = (pixel01 >> 8) & 0xff;
|
||||
p10 = (pixel10 >> 8) & 0xff;
|
||||
p11 = (pixel11 >> 8) & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
tg = (((px0*tvf + px1*tvf1) >> 8) * (interpARGB ? ((int) (sp[G]*255)) : g2)) >> 8;
|
||||
|
||||
|
||||
p00 = pixel00 & 0xff; // blue
|
||||
p01 = pixel01 & 0xff;
|
||||
p10 = pixel10 & 0xff;
|
||||
p11 = pixel11 & 0xff;
|
||||
|
||||
px0 = (p00*tuf + p10*tuf1) >> 8;
|
||||
px1 = (p01*tuf + p11*tuf1) >> 8;
|
||||
tb = (((px0*tvf + px1*tvf1) >> 8) * (interpARGB ? ((int) (sp[B]*255)) : b2)) >> 8;
|
||||
//System.out.println("5: "+tr + " " + tg + " " +tb);
|
||||
//check
|
||||
} else { // alpha image, only use current fill color
|
||||
if (interpARGB) {
|
||||
tr = (int) (sp[R] * 255);
|
||||
tg = (int) (sp[G] * 255);
|
||||
tb = (int) (sp[B] * 255);
|
||||
} else {
|
||||
tr = r2;
|
||||
tg = g2;
|
||||
tb = b2;
|
||||
}
|
||||
}
|
||||
|
||||
// get coverage for pixel if smooth
|
||||
// checks smooth again here because of
|
||||
// hints[SMOOTH_IMAGES] used up above
|
||||
int weight = smooth ? coverage(x) : 255;
|
||||
if (weight != 255) ta = (ta*weight) >> 8;
|
||||
//System.out.println(ta);
|
||||
//System.out.println("8");
|
||||
//check
|
||||
} else { // no smooth, just get the pixels
|
||||
int tpixel = tpixels[txy];
|
||||
// TODO i doubt splitting these guys really gets us
|
||||
// all that much speed.. is it worth it?
|
||||
if (tformat == ALPHA) {
|
||||
ta = tpixel;
|
||||
if (interpARGB) {
|
||||
tr = (int) (sp[R]*255);
|
||||
tg = (int) (sp[G]*255);
|
||||
tb = (int) (sp[B]*255);
|
||||
if (sp[A] != 1) {
|
||||
ta = (((int) (sp[A]*255)) * ta) >> 8;
|
||||
}
|
||||
} else {
|
||||
tr = r2;
|
||||
tg = g2;
|
||||
tb = b2;
|
||||
ta = (a2orig * ta) >> 8;
|
||||
}
|
||||
|
||||
} else { // RGB or ARGB
|
||||
ta = (tformat == RGB) ? 255 : (tpixel >> 24) & 0xff;
|
||||
if (interpARGB) {
|
||||
tr = (((int) (sp[R]*255)) * ((tpixel >> 16) & 0xff)) >> 8;
|
||||
tg = (((int) (sp[G]*255)) * ((tpixel >> 8) & 0xff)) >> 8;
|
||||
tb = (((int) (sp[B]*255)) * ((tpixel) & 0xff)) >> 8;
|
||||
ta = (((int) (sp[A]*255)) * ta) >> 8;
|
||||
} else {
|
||||
tr = (r2 * ((tpixel >> 16) & 0xff)) >> 8;
|
||||
tg = (g2 * ((tpixel >> 8) & 0xff)) >> 8;
|
||||
tb = (b2 * ((tpixel) & 0xff)) >> 8;
|
||||
ta = (a2orig * ta) >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((ta == 254) || (ta == 255)) { // if (ta & 0xf8) would be good
|
||||
// no need to blend
|
||||
pixels[offset+x] = 0xff000000 | (tr << 16) | (tg << 8) | tb;
|
||||
zbuffer[offset+x] = sp[Z];
|
||||
} else {
|
||||
// blend with pixel on screen
|
||||
int a1 = 255-ta;
|
||||
int r1 = (pixels[offset+x] >> 16) & 0xff;
|
||||
int g1 = (pixels[offset+x] >> 8) & 0xff;
|
||||
int b1 = (pixels[offset+x]) & 0xff;
|
||||
|
||||
|
||||
pixels[offset+x] =
|
||||
0xff000000 |
|
||||
(((tr*ta + r1*a1) >> 8) << 16) |
|
||||
((tg*ta + g1*a1) & 0xff00) |
|
||||
((tb*ta + b1*a1) >> 8);
|
||||
|
||||
//System.out.println("17");
|
||||
//check
|
||||
if (ta > ZBUFFER_MIN_COVERAGE) zbuffer[offset+x] = sp[Z];
|
||||
}
|
||||
|
||||
//System.out.println("18");
|
||||
//check
|
||||
} else { // no image applied
|
||||
int weight = smooth ? coverage(x) : 255;
|
||||
|
||||
if (interpARGB) {
|
||||
r2 = (int) (sp[R] * 255);
|
||||
g2 = (int) (sp[G] * 255);
|
||||
b2 = (int) (sp[B] * 255);
|
||||
if (sp[A] != 1) weight = (weight * ((int) (sp[A] * 255))) >> 8;
|
||||
if (weight == 255) {
|
||||
rgba = 0xff000000 | (r2 << 16) | (g2 << 8) | b2;
|
||||
}
|
||||
} else {
|
||||
if (a2orig != 255) weight = (weight * a2orig) >> 8;
|
||||
}
|
||||
|
||||
if (weight == 255) {
|
||||
// no blend, no aa, just the rgba
|
||||
pixels[offset+x] = rgba;
|
||||
zbuffer[offset+x] = sp[Z];
|
||||
|
||||
} else {
|
||||
int r1 = (pixels[offset+x] >> 16) & 0xff;
|
||||
int g1 = (pixels[offset+x] >> 8) & 0xff;
|
||||
int b1 = (pixels[offset+x]) & 0xff;
|
||||
a2 = weight;
|
||||
|
||||
int a1 = 255 - a2;
|
||||
pixels[offset+x] = (0xff000000 |
|
||||
((r1*a1 + r2*a2) >> 8) << 16 |
|
||||
// use & instead of >> and << below
|
||||
((g1*a1 + g2*a2) >> 8) << 8 |
|
||||
((b1*a1 + b2*a2) >> 8));
|
||||
|
||||
if (a2 > ZBUFFER_MIN_COVERAGE) zbuffer[offset+x] = sp[Z];
|
||||
}
|
||||
}
|
||||
}
|
||||
// if smooth enabled, don't increment values
|
||||
// for the pixel in the stretch out version
|
||||
// of the scanline used to get smooth edges.
|
||||
if (!smooth || ((x >= truelx) && (x <= truerx))) {
|
||||
//if (!smooth)
|
||||
increment(sp, sdp);
|
||||
}
|
||||
}
|
||||
firstModY = -1;
|
||||
interpX = true;
|
||||
}
|
||||
|
||||
|
||||
// x is in screen, not huge 8x coordinates
|
||||
private int coverage(int x) {
|
||||
if ((x >= aaleftfull) && (x <= aarightfull) &&
|
||||
// important since not all SUBYRES lines may have been covered
|
||||
(firstModY == 0) && (lastModY == SUBYRES1)) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
int pixelLeft = x*SUBXRES; // huh?
|
||||
int pixelRight = pixelLeft + 8;
|
||||
|
||||
int amt = 0;
|
||||
for (int i = firstModY; i <= lastModY; i++) {
|
||||
if ((aaleft[i] > pixelRight) || (aaright[i] < pixelLeft)) {
|
||||
continue;
|
||||
}
|
||||
// does this need a +1 ?
|
||||
amt += ((aaright[i] < pixelRight ? aaright[i] : pixelRight) -
|
||||
(aaleft[i] > pixelLeft ? aaleft[i] : pixelLeft));
|
||||
}
|
||||
amt <<= 2;
|
||||
return (amt == 256) ? 255 : amt;
|
||||
}
|
||||
|
||||
|
||||
private void incrementalize_y(float p1[], float p2[],
|
||||
float p[], float dp[], int y) {
|
||||
float delta = p2[Y] - p1[Y];
|
||||
if (delta == 0) delta = 1;
|
||||
float fraction = y + 0.5f - p1[Y];
|
||||
|
||||
if (interpX) {
|
||||
dp[X] = (p2[X] - p1[X]) / delta;
|
||||
p[X] = p1[X] + dp[X] * fraction;
|
||||
}
|
||||
if (interpZ) {
|
||||
dp[Z] = (p2[Z] - p1[Z]) / delta;
|
||||
p[Z] = p1[Z] + dp[Z] * fraction;
|
||||
}
|
||||
|
||||
if (interpARGB) {
|
||||
dp[R] = (p2[R] - p1[R]) / delta;
|
||||
dp[G] = (p2[G] - p1[G]) / delta;
|
||||
dp[B] = (p2[B] - p1[B]) / delta;
|
||||
dp[A] = (p2[A] - p1[A]) / delta;
|
||||
p[R] = p1[R] + dp[R] * fraction;
|
||||
p[G] = p1[G] + dp[G] * fraction;
|
||||
p[B] = p1[B] + dp[B] * fraction;
|
||||
p[A] = p1[A] + dp[A] * fraction;
|
||||
}
|
||||
|
||||
if (interpUV) {
|
||||
dp[U] = (p2[U] - p1[U]) / delta;
|
||||
dp[V] = (p2[V] - p1[V]) / delta;
|
||||
|
||||
//if (smooth) {
|
||||
//p[U] = p1[U]; //+ dp[U] * fraction;
|
||||
//p[V] = p1[V]; //+ dp[V] * fraction;
|
||||
|
||||
//} else {
|
||||
p[U] = p1[U] + dp[U] * fraction;
|
||||
p[V] = p1[V] + dp[V] * fraction;
|
||||
//}
|
||||
if (FRY) System.out.println("inc y p[U] p[V] = " + p[U] + " " + p[V]);
|
||||
}
|
||||
}
|
||||
|
||||
//incrementalize_x(l, r, sp, sdp, lx);
|
||||
private void incrementalize_x(float p1[], float p2[],
|
||||
float p[], float dp[], int x) {
|
||||
float delta = p2[X] - p1[X];
|
||||
if (delta == 0) delta = 1;
|
||||
float fraction = x + 0.5f - p1[X];
|
||||
if (smooth) {
|
||||
delta /= SUBXRES;
|
||||
fraction /= SUBXRES;
|
||||
}
|
||||
|
||||
if (interpX) {
|
||||
dp[X] = (p2[X] - p1[X]) / delta;
|
||||
p[X] = p1[X] + dp[X] * fraction;
|
||||
}
|
||||
if (interpZ) {
|
||||
dp[Z] = (p2[Z] - p1[Z]) / delta;
|
||||
p[Z] = p1[Z] + dp[Z] * fraction;
|
||||
//System.out.println(p2[Z]+" " +p1[Z]+" " +dp[Z]);
|
||||
}
|
||||
|
||||
if (interpARGB) {
|
||||
dp[R] = (p2[R] - p1[R]) / delta;
|
||||
dp[G] = (p2[G] - p1[G]) / delta;
|
||||
dp[B] = (p2[B] - p1[B]) / delta;
|
||||
dp[A] = (p2[A] - p1[A]) / delta;
|
||||
p[R] = p1[R] + dp[R] * fraction;
|
||||
p[G] = p1[G] + dp[G] * fraction;
|
||||
p[B] = p1[B] + dp[B] * fraction;
|
||||
p[A] = p1[A] + dp[A] * fraction;
|
||||
}
|
||||
|
||||
if (interpUV) {
|
||||
if (FRY) System.out.println("delta, frac = " + delta + ", " + fraction);
|
||||
dp[U] = (p2[U] - p1[U]) / delta;
|
||||
dp[V] = (p2[V] - p1[V]) / delta;
|
||||
|
||||
//if (smooth) {
|
||||
//p[U] = p1[U];
|
||||
// offset for the damage that will be done by the
|
||||
// 8 consecutive calls to scanline
|
||||
// agh.. this won't work b/c not always 8 calls before render
|
||||
// maybe lastModY - firstModY + 1 instead?
|
||||
if (FRY) System.out.println("before inc x p[V] = " + p[V] + " " + p1[V] + " " + p2[V]);
|
||||
//p[V] = p1[V] - SUBXRES1 * fraction;
|
||||
|
||||
//} else {
|
||||
p[U] = p1[U] + dp[U] * fraction;
|
||||
p[V] = p1[V] + dp[V] * fraction;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
private void increment(float p[], float dp[]) {
|
||||
if (interpX) p[X] += dp[X];
|
||||
if (interpZ) p[Z] += dp[Z];
|
||||
|
||||
if (interpARGB) {
|
||||
p[R] += dp[R];
|
||||
p[G] += dp[G];
|
||||
p[B] += dp[B];
|
||||
p[A] += dp[A];
|
||||
}
|
||||
|
||||
if (interpUV) {
|
||||
if (FRY) System.out.println("increment() " + p[V] + " " + dp[V]);
|
||||
p[U] += dp[U];
|
||||
p[V] += dp[V];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pass camera-space coordinates for the triangle.
|
||||
* Needed to render if hint(ENABLE_ACCURATE_TEXTURES) enabled.
|
||||
* Generally this will not need to be called manually,
|
||||
* currently called from PGraphics3D.render_triangles()
|
||||
*/
|
||||
public void setCamVertices(float x0, float y0, float z0,
|
||||
float x1, float y1, float z1,
|
||||
float x2, float y2, float z2) {
|
||||
camX[0] = x0;
|
||||
camX[1] = x1;
|
||||
camX[2] = x2;
|
||||
|
||||
camY[0] = y0;
|
||||
camY[1] = y1;
|
||||
camY[2] = y2;
|
||||
|
||||
camZ[0] = z0;
|
||||
camZ[1] = z1;
|
||||
camZ[2] = z2;
|
||||
}
|
||||
|
||||
public void setVertices(float x0, float y0, float z0,
|
||||
float x1, float y1, float z1,
|
||||
float x2, float y2, float z2) {
|
||||
vertices[0][X] = x0;
|
||||
vertices[1][X] = x1;
|
||||
vertices[2][X] = x2;
|
||||
|
||||
vertices[0][Y] = y0;
|
||||
vertices[1][Y] = y1;
|
||||
vertices[2][Y] = y2;
|
||||
|
||||
vertices[0][Z] = z0;
|
||||
vertices[1][Z] = z1;
|
||||
vertices[2][Z] = z2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Precompute a bunch of variables needed to perform
|
||||
* texture mapping.
|
||||
* @return True unless texture mapping is degenerate
|
||||
*/
|
||||
boolean precomputeAccurateTexturing() {
|
||||
int o0 = 0;
|
||||
int o1 = 1;
|
||||
int o2 = 2;
|
||||
|
||||
PMatrix3D myMatrix = new PMatrix3D(vertices[o0][U], vertices[o0][V], 1, 0,
|
||||
vertices[o1][U], vertices[o1][V], 1, 0,
|
||||
vertices[o2][U], vertices[o2][V], 1, 0,
|
||||
0, 0, 0, 1);
|
||||
|
||||
// A 3x3 inversion would be more efficient here,
|
||||
// given that the fourth r/c are unity
|
||||
boolean invertSuccess = myMatrix.invert();// = myMatrix.invert();
|
||||
|
||||
// If the matrix inversion had trouble, let the caller know.
|
||||
// Note that this does not catch everything that could go wrong
|
||||
// here, like if the renderer is in ortho() mode (which really
|
||||
// must be caught in PGraphics3D instead of here).
|
||||
if (!invertSuccess) return false;
|
||||
|
||||
float m00, m01, m02, m10, m11, m12, m20, m21, m22;
|
||||
m00 = myMatrix.m00*camX[o0]+myMatrix.m01*camX[o1]+myMatrix.m02*camX[o2];
|
||||
m01 = myMatrix.m10*camX[o0]+myMatrix.m11*camX[o1]+myMatrix.m12*camX[o2];
|
||||
m02 = myMatrix.m20*camX[o0]+myMatrix.m21*camX[o1]+myMatrix.m22*camX[o2];
|
||||
m10 = myMatrix.m00*camY[o0]+myMatrix.m01*camY[o1]+myMatrix.m02*camY[o2];
|
||||
m11 = myMatrix.m10*camY[o0]+myMatrix.m11*camY[o1]+myMatrix.m12*camY[o2];
|
||||
m12 = myMatrix.m20*camY[o0]+myMatrix.m21*camY[o1]+myMatrix.m22*camY[o2];
|
||||
m20 = -(myMatrix.m00*camZ[o0]+myMatrix.m01*camZ[o1]+myMatrix.m02*camZ[o2]);
|
||||
m21 = -(myMatrix.m10*camZ[o0]+myMatrix.m11*camZ[o1]+myMatrix.m12*camZ[o2]);
|
||||
m22 = -(myMatrix.m20*camZ[o0]+myMatrix.m21*camZ[o1]+myMatrix.m22*camZ[o2]);
|
||||
|
||||
float px = m02;
|
||||
float py = m12;
|
||||
float pz = m22;
|
||||
|
||||
float TEX_WIDTH = this.twidth;
|
||||
float TEX_HEIGHT = this.theight;
|
||||
|
||||
float resultT0x = m00*TEX_WIDTH+m02;
|
||||
float resultT0y = m10*TEX_WIDTH+m12;
|
||||
float resultT0z = m20*TEX_WIDTH+m22;
|
||||
float result0Tx = m01*TEX_HEIGHT+m02;
|
||||
float result0Ty = m11*TEX_HEIGHT+m12;
|
||||
float result0Tz = m21*TEX_HEIGHT+m22;
|
||||
float mx = resultT0x-m02;
|
||||
float my = resultT0y-m12;
|
||||
float mz = resultT0z-m22;
|
||||
float nx = result0Tx-m02;
|
||||
float ny = result0Ty-m12;
|
||||
float nz = result0Tz-m22;
|
||||
|
||||
//avec = p x n
|
||||
ax = (py*nz-pz*ny)*TEX_WIDTH; //F_TEX_WIDTH/HEIGHT?
|
||||
ay = (pz*nx-px*nz)*TEX_WIDTH;
|
||||
az = (px*ny-py*nx)*TEX_WIDTH;
|
||||
//bvec = m x p
|
||||
bx = (my*pz-mz*py)*TEX_HEIGHT;
|
||||
by = (mz*px-mx*pz)*TEX_HEIGHT;
|
||||
bz = (mx*py-my*px)*TEX_HEIGHT;
|
||||
//cvec = n x m
|
||||
cx = ny*mz-nz*my;
|
||||
cy = nz*mx-nx*mz;
|
||||
cz = nx*my-ny*mx;
|
||||
|
||||
//System.out.println("a/b/c: "+ax+" " + ay + " " + az + " " + bx + " " + by + " " + bz + " " + cx + " " + cy + " " + cz);
|
||||
|
||||
nearPlaneWidth = (parent.rightScreen-parent.leftScreen);
|
||||
nearPlaneHeight = (parent.topScreen-parent.bottomScreen);
|
||||
nearPlaneDepth = parent.nearPlane;
|
||||
|
||||
// one pixel width in nearPlane coordinates
|
||||
xmult = nearPlaneWidth / parent.width;
|
||||
ymult = nearPlaneHeight / parent.height;
|
||||
// Extra scalings to map screen plane units to pixel units
|
||||
// newax = ax*xmult;
|
||||
// newbx = bx*xmult;
|
||||
// newcx = cx*xmult;
|
||||
|
||||
|
||||
// System.out.println("nearplane: "+ nearPlaneWidth + " " + nearPlaneHeight + " " + nearPlaneDepth);
|
||||
// System.out.println("mults: "+ xmult + " " + ymult);
|
||||
// System.out.println("news: "+ newax + " " + newbx + " " + newcx);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the texture map location based on the current screen
|
||||
* coordinates. Assumes precomputeAccurateTexturing() has
|
||||
* been called already for this texture mapping.
|
||||
* @param sx
|
||||
* @param sy
|
||||
* @return
|
||||
*/
|
||||
private int getTextureIndex(float sx, float sy, float[] uv) {
|
||||
if (EWJORDAN) System.out.println("Getting texel at "+sx + ", "+sy);
|
||||
//System.out.println("Screen: "+ sx + " " + sy);
|
||||
sx = xmult*(sx-(parent.width/2.0f) +.5f);//+.5f)
|
||||
sy = ymult*(sy-(parent.height/2.0f)+.5f);//+.5f)
|
||||
//sx /= SUBXRES;
|
||||
//sy /= SUBYRES;
|
||||
float sz = nearPlaneDepth;
|
||||
float a = sx * ax + sy * ay + sz * az;
|
||||
float b = sx * bx + sy * by + sz * bz;
|
||||
float c = sx * cx + sy * cy + sz * cz;
|
||||
int u = (int)(a / c);
|
||||
int v = (int)(b / c);
|
||||
uv[0] = a / c;
|
||||
uv[1] = b / c;
|
||||
if (uv[0] < 0) {
|
||||
uv[0] = u = 0;
|
||||
}
|
||||
if (uv[1] < 0) {
|
||||
uv[1] = v = 0;
|
||||
}
|
||||
if (uv[0] >= twidth) {
|
||||
uv[0] = twidth-1;
|
||||
u = twidth-1;
|
||||
}
|
||||
if (uv[1] >= theight) {
|
||||
uv[1] = theight-1;
|
||||
v = theight-1;
|
||||
}
|
||||
int result = v*twidth + u;
|
||||
//System.out.println("a/b/c: "+a + " " + b + " " + c);
|
||||
//System.out.println("cx/y/z: "+cx + " " + cy + " " + cz);
|
||||
//if (result < 0) result = 0;
|
||||
//if (result >= timage.pixels.length-2) result = timage.pixels.length - 2;
|
||||
if (EWJORDAN) System.out.println("Got texel "+result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void setIntensities(float ar, float ag, float ab, float aa,
|
||||
float br, float bg, float bb, float ba,
|
||||
float cr, float cg, float cb, float ca) {
|
||||
vertices[0][R] = ar;
|
||||
vertices[0][G] = ag;
|
||||
vertices[0][B] = ab;
|
||||
vertices[0][A] = aa;
|
||||
vertices[1][R] = br;
|
||||
vertices[1][G] = bg;
|
||||
vertices[1][B] = bb;
|
||||
vertices[1][A] = ba;
|
||||
vertices[2][R] = cr;
|
||||
vertices[2][G] = cg;
|
||||
vertices[2][B] = cb;
|
||||
vertices[2][A] = ca;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2008 Ben Fry and Casey Reas
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
|
||||
public class PStyle implements PConstants {
|
||||
public int imageMode;
|
||||
public int rectMode;
|
||||
public int ellipseMode;
|
||||
public int shapeMode;
|
||||
|
||||
public int colorMode;
|
||||
public float colorModeX;
|
||||
public float colorModeY;
|
||||
public float colorModeZ;
|
||||
public float colorModeA;
|
||||
|
||||
public boolean tint;
|
||||
public int tintColor;
|
||||
public boolean fill;
|
||||
public int fillColor;
|
||||
public boolean stroke;
|
||||
public int strokeColor;
|
||||
public float strokeWeight;
|
||||
public int strokeCap;
|
||||
public int strokeJoin;
|
||||
|
||||
// TODO these fellas are inconsistent, and may need to go elsewhere
|
||||
public float ambientR, ambientG, ambientB;
|
||||
public float specularR, specularG, specularB;
|
||||
public float emissiveR, emissiveG, emissiveB;
|
||||
public float shininess;
|
||||
|
||||
public PFont textFont;
|
||||
public int textAlign;
|
||||
public int textAlignY;
|
||||
public int textMode;
|
||||
public float textSize;
|
||||
public float textLeading;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,565 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 200X Dan Shiffman
|
||||
Copyright (c) 2008 Ben Fry and Casey Reas
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
/**
|
||||
* A class to describe a two or three dimensional vector.
|
||||
* <p>
|
||||
* The result of all functions are applied to the vector itself, with the
|
||||
* exception of cross(), which returns a new PVector (or writes to a specified
|
||||
* 'target' PVector). That is, add() will add the contents of one vector to
|
||||
* this one. Using add() with additional parameters allows you to put the
|
||||
* result into a new PVector. Functions that act on multiple vectors also
|
||||
* include static versions. Because creating new objects can be computationally
|
||||
* expensive, most functions include an optional 'target' PVector, so that a
|
||||
* new PVector object is not created with each operation.
|
||||
* <p>
|
||||
* Initially based on the Vector3D class by <a href="http://www.shiffman.net">Dan Shiffman</a>.
|
||||
*/
|
||||
public class PVector {
|
||||
|
||||
/** The x component of the vector. */
|
||||
public float x;
|
||||
|
||||
/** The y component of the vector. */
|
||||
public float y;
|
||||
|
||||
/** The z component of the vector. */
|
||||
public float z;
|
||||
|
||||
/** Array so that this can be temporarily used in an array context */
|
||||
protected float[] array;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for an empty vector: x, y, and z are set to 0.
|
||||
*/
|
||||
public PVector() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for a 3D vector.
|
||||
*
|
||||
* @param x the x coordinate.
|
||||
* @param y the y coordinate.
|
||||
* @param z the y coordinate.
|
||||
*/
|
||||
public PVector(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for a 2D vector: z coordinate is set to 0.
|
||||
*
|
||||
* @param x the x coordinate.
|
||||
* @param y the y coordinate.
|
||||
*/
|
||||
public PVector(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set x, y, and z coordinates.
|
||||
*
|
||||
* @param x the x coordinate.
|
||||
* @param y the y coordinate.
|
||||
* @param z the z coordinate.
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set x, y, and z coordinates from a Vector3D object.
|
||||
*
|
||||
* @param v the PVector object to be copied
|
||||
*/
|
||||
public void set(PVector v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the x, y (and maybe z) coordinates using a float[] array as the source.
|
||||
* @param source array to copy from
|
||||
*/
|
||||
public void set(float[] source) {
|
||||
if (source.length >= 2) {
|
||||
x = source[0];
|
||||
y = source[1];
|
||||
}
|
||||
if (source.length >= 3) {
|
||||
z = source[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a copy of this vector.
|
||||
*/
|
||||
public PVector get() {
|
||||
return new PVector(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
public float[] get(float[] target) {
|
||||
if (target == null) {
|
||||
return new float[] { x, y, z };
|
||||
}
|
||||
if (target.length >= 2) {
|
||||
target[0] = x;
|
||||
target[1] = y;
|
||||
}
|
||||
if (target.length >= 3) {
|
||||
target[2] = z;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the magnitude (length) of the vector
|
||||
* @return the magnitude of the vector
|
||||
*/
|
||||
public float mag() {
|
||||
return (float) Math.sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a vector to this vector
|
||||
* @param v the vector to be added
|
||||
*/
|
||||
public void add(PVector v) {
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
z += v.z;
|
||||
}
|
||||
|
||||
|
||||
public void add(float x, float y, float z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add two vectors
|
||||
* @param v1 a vector
|
||||
* @param v2 another vector
|
||||
* @return a new vector that is the sum of v1 and v2
|
||||
*/
|
||||
static public PVector add(PVector v1, PVector v2) {
|
||||
return add(v1, v2, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add two vectors into a target vector
|
||||
* @param v1 a vector
|
||||
* @param v2 another vector
|
||||
* @param target the target vector (if null, a new vector will be created)
|
||||
* @return a new vector that is the sum of v1 and v2
|
||||
*/
|
||||
static public PVector add(PVector v1, PVector v2, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector(v1.x + v2.x,v1.y + v2.y, v1.z + v2.z);
|
||||
} else {
|
||||
target.set(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subtract a vector from this vector
|
||||
* @param v the vector to be subtracted
|
||||
*/
|
||||
public void sub(PVector v) {
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
z -= v.z;
|
||||
}
|
||||
|
||||
|
||||
public void sub(float x, float y, float z) {
|
||||
this.x -= x;
|
||||
this.y -= y;
|
||||
this.z -= z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subtract one vector from another
|
||||
* @param v1 a vector
|
||||
* @param v2 another vector
|
||||
* @return a new vector that is v1 - v2
|
||||
*/
|
||||
static public PVector sub(PVector v1, PVector v2) {
|
||||
return sub(v1, v2, null);
|
||||
}
|
||||
|
||||
|
||||
static public PVector sub(PVector v1, PVector v2, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
} else {
|
||||
target.set(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply this vector by a scalar
|
||||
* @param n the value to multiply by
|
||||
*/
|
||||
public void mult(float n) {
|
||||
x *= n;
|
||||
y *= n;
|
||||
z *= n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply a vector by a scalar
|
||||
* @param v a vector
|
||||
* @param n scalar
|
||||
* @return a new vector that is v1 * n
|
||||
*/
|
||||
static public PVector mult(PVector v, float n) {
|
||||
return mult(v, n, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply a vector by a scalar, and write the result into a target PVector.
|
||||
* @param v a vector
|
||||
* @param n scalar
|
||||
* @param target PVector to store the result
|
||||
* @return the target vector, now set to v1 * n
|
||||
*/
|
||||
static public PVector mult(PVector v, float n, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector(v.x*n, v.y*n, v.z*n);
|
||||
} else {
|
||||
target.set(v.x*n, v.y*n, v.z*n);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply each element of one vector by the elements of another vector.
|
||||
* @param v the vector to multiply by
|
||||
*/
|
||||
public void mult(PVector v) {
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
z *= v.z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply each element of one vector by the individual elements of another
|
||||
* vector, and return the result as a new PVector.
|
||||
*/
|
||||
static public PVector mult(PVector v1, PVector v2) {
|
||||
return mult(v1, v2, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply each element of one vector by the individual elements of another
|
||||
* vector, and write the result into a target vector.
|
||||
* @param v1 the first vector
|
||||
* @param v2 the second vector
|
||||
* @param target PVector to store the result
|
||||
*/
|
||||
static public PVector mult(PVector v1, PVector v2, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z);
|
||||
} else {
|
||||
target.set(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Divide this vector by a scalar
|
||||
* @param n the value to divide by
|
||||
*/
|
||||
public void div(float n) {
|
||||
x /= n;
|
||||
y /= n;
|
||||
z /= n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Divide a vector by a scalar and return the result in a new vector.
|
||||
* @param v a vector
|
||||
* @param n scalar
|
||||
* @return a new vector that is v1 / n
|
||||
*/
|
||||
static public PVector div(PVector v, float n) {
|
||||
return div(v, n, null);
|
||||
}
|
||||
|
||||
|
||||
static public PVector div(PVector v, float n, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector(v.x/n, v.y/n, v.z/n);
|
||||
} else {
|
||||
target.set(v.x/n, v.y/n, v.z/n);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Divide each element of one vector by the elements of another vector.
|
||||
*/
|
||||
public void div(PVector v) {
|
||||
x /= v.x;
|
||||
y /= v.y;
|
||||
z /= v.z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Multiply each element of one vector by the individual elements of another
|
||||
* vector, and return the result as a new PVector.
|
||||
*/
|
||||
static public PVector div(PVector v1, PVector v2) {
|
||||
return div(v1, v2, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Divide each element of one vector by the individual elements of another
|
||||
* vector, and write the result into a target vector.
|
||||
* @param v1 the first vector
|
||||
* @param v2 the second vector
|
||||
* @param target PVector to store the result
|
||||
*/
|
||||
static public PVector div(PVector v1, PVector v2, PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector(v1.x/v2.x, v1.y/v2.y, v1.z/v2.z);
|
||||
} else {
|
||||
target.set(v1.x/v2.x, v1.y/v2.y, v1.z/v2.z);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the Euclidean distance between two points (considering a point as a vector object)
|
||||
* @param v another vector
|
||||
* @return the Euclidean distance between
|
||||
*/
|
||||
public float dist(PVector v) {
|
||||
float dx = x - v.x;
|
||||
float dy = y - v.y;
|
||||
float dz = z - v.z;
|
||||
return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the Euclidean distance between two points (considering a point as a vector object)
|
||||
* @param v1 a vector
|
||||
* @param v2 another vector
|
||||
* @return the Euclidean distance between v1 and v2
|
||||
*/
|
||||
static public float dist(PVector v1, PVector v2) {
|
||||
float dx = v1.x - v2.x;
|
||||
float dy = v1.y - v2.y;
|
||||
float dz = v1.z - v2.z;
|
||||
return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the dot product with another vector
|
||||
* @return the dot product
|
||||
*/
|
||||
public float dot(PVector v) {
|
||||
return x*v.x + y*v.y + z*v.z;
|
||||
}
|
||||
|
||||
|
||||
public float dot(float x, float y, float z) {
|
||||
return this.x*x + this.y*y + this.z*z;
|
||||
}
|
||||
|
||||
|
||||
static public float dot(PVector v1, PVector v2) {
|
||||
return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a vector composed of the cross product between this and another.
|
||||
*/
|
||||
public PVector cross(PVector v) {
|
||||
return cross(v, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform cross product between this and another vector, and store the
|
||||
* result in 'target'. If target is null, a new vector is created.
|
||||
*/
|
||||
public PVector cross(PVector v, PVector target) {
|
||||
float crossX = y * v.z - v.y * z;
|
||||
float crossY = z * v.x - v.z * x;
|
||||
float crossZ = x * v.y - v.x * y;
|
||||
|
||||
if (target == null) {
|
||||
target = new PVector(crossX, crossY, crossZ);
|
||||
} else {
|
||||
target.set(crossX, crossY, crossZ);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
static public PVector cross(PVector v1, PVector v2, PVector target) {
|
||||
float crossX = v1.y * v2.z - v2.y * v1.z;
|
||||
float crossY = v1.z * v2.x - v2.z * v1.x;
|
||||
float crossZ = v1.x * v2.y - v2.x * v1.y;
|
||||
|
||||
if (target == null) {
|
||||
target = new PVector(crossX, crossY, crossZ);
|
||||
} else {
|
||||
target.set(crossX, crossY, crossZ);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normalize the vector to length 1 (make it a unit vector)
|
||||
*/
|
||||
public void normalize() {
|
||||
float m = mag();
|
||||
if (m != 0 && m != 1) {
|
||||
div(m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normalize this vector, storing the result in another vector.
|
||||
* @param target Set to null to create a new vector
|
||||
* @return a new vector (if target was null), or target
|
||||
*/
|
||||
public PVector normalize(PVector target) {
|
||||
if (target == null) {
|
||||
target = new PVector();
|
||||
}
|
||||
float m = mag();
|
||||
if (m > 0) {
|
||||
target.set(x/m, y/m, z/m);
|
||||
} else {
|
||||
target.set(x, y, z);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Limit the magnitude of this vector
|
||||
* @param max the maximum length to limit this vector
|
||||
*/
|
||||
public void limit(float max) {
|
||||
if (mag() > max) {
|
||||
normalize();
|
||||
mult(max);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the angle of rotation for this vector (only 2D vectors)
|
||||
* @return the angle of rotation
|
||||
*/
|
||||
public float heading2D() {
|
||||
float angle = (float) Math.atan2(-y, x);
|
||||
return -1*angle;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, using the dot product
|
||||
* @param v1 a vector
|
||||
* @param v2 another vector
|
||||
* @return the angle between the vectors
|
||||
*/
|
||||
static public float angleBetween(PVector v1, PVector v2) {
|
||||
double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
|
||||
double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
|
||||
return (float) Math.acos(dot / (v1mag * v2mag));
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "[ " + x + ", " + y + ", " + z + " ]";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a representation of this vector as a float array. This is only for
|
||||
* temporary use. If used in any other fashion, the contents should be copied
|
||||
* by using the get() command to copy into your own array.
|
||||
*/
|
||||
public float[] array() {
|
||||
if (array == null) {
|
||||
array = new float[3];
|
||||
}
|
||||
array[0] = x;
|
||||
array[1] = y;
|
||||
array[2] = z;
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,193 +0,0 @@
|
||||
/* CDATAReader.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2002/01/04 21:03:28 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* This reader reads data from another reader until the end of a CDATA section
|
||||
* (]]>) has been encountered.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $
|
||||
*/
|
||||
class CDATAReader
|
||||
extends Reader
|
||||
{
|
||||
|
||||
/**
|
||||
* The encapsulated reader.
|
||||
*/
|
||||
private StdXMLReader reader;
|
||||
|
||||
|
||||
/**
|
||||
* Saved char.
|
||||
*/
|
||||
private char savedChar;
|
||||
|
||||
|
||||
/**
|
||||
* True if the end of the stream has been reached.
|
||||
*/
|
||||
private boolean atEndOfData;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the reader.
|
||||
*
|
||||
* @param reader the encapsulated reader
|
||||
*/
|
||||
CDATAReader(StdXMLReader reader)
|
||||
{
|
||||
this.reader = reader;
|
||||
this.savedChar = 0;
|
||||
this.atEndOfData = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.reader = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a block of data.
|
||||
*
|
||||
* @param buffer where to put the read data
|
||||
* @param offset first position in buffer to put the data
|
||||
* @param size maximum number of chars to read
|
||||
*
|
||||
* @return the number of chars read, or -1 if at EOF
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
public int read(char[] buffer,
|
||||
int offset,
|
||||
int size)
|
||||
throws IOException
|
||||
{
|
||||
int charsRead = 0;
|
||||
|
||||
if (this.atEndOfData) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((offset + size) > buffer.length) {
|
||||
size = buffer.length - offset;
|
||||
}
|
||||
|
||||
while (charsRead < size) {
|
||||
char ch = this.savedChar;
|
||||
|
||||
if (ch == 0) {
|
||||
ch = this.reader.read();
|
||||
} else {
|
||||
this.savedChar = 0;
|
||||
}
|
||||
|
||||
if (ch == ']') {
|
||||
char ch2 = this.reader.read();
|
||||
|
||||
if (ch2 == ']') {
|
||||
char ch3 = this.reader.read();
|
||||
|
||||
if (ch3 == '>') {
|
||||
this.atEndOfData = true;
|
||||
break;
|
||||
}
|
||||
|
||||
this.savedChar = ch2;
|
||||
this.reader.unread(ch3);
|
||||
} else {
|
||||
this.reader.unread(ch2);
|
||||
}
|
||||
}
|
||||
buffer[charsRead] = ch;
|
||||
charsRead++;
|
||||
}
|
||||
|
||||
if (charsRead == 0) {
|
||||
charsRead = -1;
|
||||
}
|
||||
|
||||
return charsRead;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skips remaining data and closes the stream.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
public void close()
|
||||
throws IOException
|
||||
{
|
||||
while (! this.atEndOfData) {
|
||||
char ch = this.savedChar;
|
||||
|
||||
if (ch == 0) {
|
||||
ch = this.reader.read();
|
||||
} else {
|
||||
this.savedChar = 0;
|
||||
}
|
||||
|
||||
if (ch == ']') {
|
||||
char ch2 = this.reader.read();
|
||||
|
||||
if (ch2 == ']') {
|
||||
char ch3 = this.reader.read();
|
||||
|
||||
if (ch3 == '>') {
|
||||
break;
|
||||
}
|
||||
|
||||
this.savedChar = ch2;
|
||||
this.reader.unread(ch3);
|
||||
} else {
|
||||
this.reader.unread(ch2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.atEndOfData = true;
|
||||
}
|
||||
|
||||
}
|
@ -1,212 +0,0 @@
|
||||
/* ContentReader.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/01/04 21:03:28 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* This reader reads data from another reader until a new element has
|
||||
* been encountered.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
|
||||
*/
|
||||
class ContentReader
|
||||
extends Reader
|
||||
{
|
||||
|
||||
/**
|
||||
* The encapsulated reader.
|
||||
*/
|
||||
private StdXMLReader reader;
|
||||
|
||||
|
||||
/**
|
||||
* Buffer.
|
||||
*/
|
||||
private String buffer;
|
||||
|
||||
|
||||
/**
|
||||
* Pointer into the buffer.
|
||||
*/
|
||||
private int bufferIndex;
|
||||
|
||||
|
||||
/**
|
||||
* The entity resolver.
|
||||
*/
|
||||
private XMLEntityResolver resolver;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the reader.
|
||||
*
|
||||
* @param reader the encapsulated reader
|
||||
* @param resolver the entity resolver
|
||||
* @param buffer data that has already been read from <code>reader</code>
|
||||
*/
|
||||
ContentReader(StdXMLReader reader,
|
||||
XMLEntityResolver resolver,
|
||||
String buffer)
|
||||
{
|
||||
this.reader = reader;
|
||||
this.resolver = resolver;
|
||||
this.buffer = buffer;
|
||||
this.bufferIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.reader = null;
|
||||
this.resolver = null;
|
||||
this.buffer = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a block of data.
|
||||
*
|
||||
* @param outputBuffer where to put the read data
|
||||
* @param offset first position in buffer to put the data
|
||||
* @param size maximum number of chars to read
|
||||
*
|
||||
* @return the number of chars read, or -1 if at EOF
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
public int read(char[] outputBuffer,
|
||||
int offset,
|
||||
int size)
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
int charsRead = 0;
|
||||
int bufferLength = this.buffer.length();
|
||||
|
||||
if ((offset + size) > outputBuffer.length) {
|
||||
size = outputBuffer.length - offset;
|
||||
}
|
||||
|
||||
while (charsRead < size) {
|
||||
String str = "";
|
||||
char ch;
|
||||
|
||||
if (this.bufferIndex >= bufferLength) {
|
||||
str = XMLUtil.read(this.reader, '&');
|
||||
ch = str.charAt(0);
|
||||
} else {
|
||||
ch = this.buffer.charAt(this.bufferIndex);
|
||||
this.bufferIndex++;
|
||||
outputBuffer[charsRead] = ch;
|
||||
charsRead++;
|
||||
continue; // don't interprete chars in the buffer
|
||||
}
|
||||
|
||||
if (ch == '<') {
|
||||
this.reader.unread(ch);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ch == '&') && (str.length() > 1)) {
|
||||
if (str.charAt(1) == '#') {
|
||||
ch = XMLUtil.processCharLiteral(str);
|
||||
} else {
|
||||
XMLUtil.processEntity(str, this.reader, this.resolver);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
outputBuffer[charsRead] = ch;
|
||||
charsRead++;
|
||||
}
|
||||
|
||||
if (charsRead == 0) {
|
||||
charsRead = -1;
|
||||
}
|
||||
|
||||
return charsRead;
|
||||
} catch (XMLParseException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skips remaining data and closes the stream.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
public void close()
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
int bufferLength = this.buffer.length();
|
||||
|
||||
for (;;) {
|
||||
String str = "";
|
||||
char ch;
|
||||
|
||||
if (this.bufferIndex >= bufferLength) {
|
||||
str = XMLUtil.read(this.reader, '&');
|
||||
ch = str.charAt(0);
|
||||
} else {
|
||||
ch = this.buffer.charAt(this.bufferIndex);
|
||||
this.bufferIndex++;
|
||||
continue; // don't interprete chars in the buffer
|
||||
}
|
||||
|
||||
if (ch == '<') {
|
||||
this.reader.unread(ch);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ch == '&') && (str.length() > 1)) {
|
||||
if (str.charAt(1) != '#') {
|
||||
XMLUtil.processEntity(str, this.reader, this.resolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (XMLParseException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,157 +0,0 @@
|
||||
/* PIReader.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2002/01/04 21:03:28 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* This reader reads data from another reader until the end of a processing
|
||||
* instruction (?>) has been encountered.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $
|
||||
*/
|
||||
class PIReader
|
||||
extends Reader
|
||||
{
|
||||
|
||||
/**
|
||||
* The encapsulated reader.
|
||||
*/
|
||||
private StdXMLReader reader;
|
||||
|
||||
|
||||
/**
|
||||
* True if the end of the stream has been reached.
|
||||
*/
|
||||
private boolean atEndOfData;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the reader.
|
||||
*
|
||||
* @param reader the encapsulated reader
|
||||
*/
|
||||
PIReader(StdXMLReader reader)
|
||||
{
|
||||
this.reader = reader;
|
||||
this.atEndOfData = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.reader = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a block of data.
|
||||
*
|
||||
* @param buffer where to put the read data
|
||||
* @param offset first position in buffer to put the data
|
||||
* @param size maximum number of chars to read
|
||||
*
|
||||
* @return the number of chars read, or -1 if at EOF
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
public int read(char[] buffer,
|
||||
int offset,
|
||||
int size)
|
||||
throws IOException
|
||||
{
|
||||
if (this.atEndOfData) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int charsRead = 0;
|
||||
|
||||
if ((offset + size) > buffer.length) {
|
||||
size = buffer.length - offset;
|
||||
}
|
||||
|
||||
while (charsRead < size) {
|
||||
char ch = this.reader.read();
|
||||
|
||||
if (ch == '?') {
|
||||
char ch2 = this.reader.read();
|
||||
|
||||
if (ch2 == '>') {
|
||||
this.atEndOfData = true;
|
||||
break;
|
||||
}
|
||||
|
||||
this.reader.unread(ch2);
|
||||
}
|
||||
|
||||
buffer[charsRead] = ch;
|
||||
charsRead++;
|
||||
}
|
||||
|
||||
if (charsRead == 0) {
|
||||
charsRead = -1;
|
||||
}
|
||||
|
||||
return charsRead;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skips remaining data and closes the stream.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
public void close()
|
||||
throws IOException
|
||||
{
|
||||
while (! this.atEndOfData) {
|
||||
char ch = this.reader.read();
|
||||
|
||||
if (ch == '?') {
|
||||
char ch2 = this.reader.read();
|
||||
|
||||
if (ch2 == '>') {
|
||||
this.atEndOfData = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,356 +0,0 @@
|
||||
/* StdXMLBuilder.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2002/01/04 21:03:28 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
/**
|
||||
* StdXMLBuilder is a concrete implementation of IXMLBuilder which creates a
|
||||
* tree of IXMLElement from an XML data source.
|
||||
*
|
||||
* @see processing.xml.XMLElement
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $
|
||||
*/
|
||||
public class StdXMLBuilder
|
||||
{
|
||||
|
||||
/**
|
||||
* This stack contains the current element and its parents.
|
||||
*/
|
||||
private Stack<XMLElement> stack;
|
||||
|
||||
|
||||
/**
|
||||
* The root element of the parsed XML tree.
|
||||
*/
|
||||
private XMLElement root;
|
||||
|
||||
private XMLElement parent;
|
||||
|
||||
/**
|
||||
* Prototype element for creating the tree.
|
||||
*/
|
||||
//private XMLElement prototype;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the builder.
|
||||
*/
|
||||
public StdXMLBuilder()
|
||||
{
|
||||
this.stack = null;
|
||||
this.root = null;
|
||||
//this(new XMLElement());
|
||||
}
|
||||
|
||||
|
||||
public StdXMLBuilder(XMLElement parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the builder.
|
||||
*
|
||||
* @param prototype the prototype to use when building the tree.
|
||||
*/
|
||||
// public StdXMLBuilder(XMLElement prototype)
|
||||
// {
|
||||
// this.stack = null;
|
||||
// this.root = null;
|
||||
// this.prototype = prototype;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
//this.prototype = null;
|
||||
this.root = null;
|
||||
this.stack.clear();
|
||||
this.stack = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called before the parser starts processing its input.
|
||||
*
|
||||
* @param systemID the system ID of the XML data source.
|
||||
* @param lineNr the line on which the parsing starts.
|
||||
*/
|
||||
public void startBuilding(String systemID,
|
||||
int lineNr)
|
||||
{
|
||||
this.stack = new Stack<XMLElement>();
|
||||
this.root = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when a processing instruction is encountered.
|
||||
* PIs with target "xml" are handled by the parser.
|
||||
*
|
||||
* @param target the PI target.
|
||||
* @param reader to read the data from the PI.
|
||||
*/
|
||||
public void newProcessingInstruction(String target,
|
||||
Reader reader)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when a new XML element is encountered.
|
||||
*
|
||||
* @see #endElement
|
||||
*
|
||||
* @param name the name of the element.
|
||||
* @param nsPrefix the prefix used to identify the namespace. If no
|
||||
* namespace has been specified, this parameter is null.
|
||||
* @param nsURI the URI associated with the namespace. If no
|
||||
* namespace has been specified, or no URI is
|
||||
* associated with nsPrefix, this parameter is null.
|
||||
* @param systemID the system ID of the XML data source.
|
||||
* @param lineNr the line in the source where the element starts.
|
||||
*/
|
||||
public void startElement(String name,
|
||||
String nsPrefix,
|
||||
String nsURI,
|
||||
String systemID,
|
||||
int lineNr)
|
||||
{
|
||||
String fullName = name;
|
||||
|
||||
if (nsPrefix != null) {
|
||||
fullName = nsPrefix + ':' + name;
|
||||
}
|
||||
|
||||
//XMLElement elt = this.prototype.createElement(fullName, nsURI,
|
||||
// systemID, lineNr);
|
||||
|
||||
// XMLElement elt = new XMLElement(fullName, nsURI, systemID, lineNr);
|
||||
//
|
||||
// if (this.stack.empty()) {
|
||||
// this.root = elt;
|
||||
// } else {
|
||||
// XMLElement top = (XMLElement) this.stack.peek();
|
||||
// top.addChild(elt);
|
||||
// }
|
||||
// stack.push(elt);
|
||||
|
||||
if (this.stack.empty()) {
|
||||
//System.out.println("setting root");
|
||||
parent.set(fullName, nsURI, systemID, lineNr);
|
||||
stack.push(parent);
|
||||
root = parent;
|
||||
} else {
|
||||
XMLElement top = (XMLElement) this.stack.peek();
|
||||
//System.out.println("stack has " + top.getName());
|
||||
XMLElement elt = new XMLElement(fullName, nsURI, systemID, lineNr);
|
||||
top.addChild(elt);
|
||||
stack.push(elt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when the attributes of an XML element have been
|
||||
* processed.
|
||||
*
|
||||
* @see #startElement
|
||||
* @see #addAttribute
|
||||
*
|
||||
* @param name the name of the element.
|
||||
* @param nsPrefix the prefix used to identify the namespace. If no
|
||||
* namespace has been specified, this parameter is null.
|
||||
* @param nsURI the URI associated with the namespace. If no
|
||||
* namespace has been specified, or no URI is
|
||||
* associated with nsPrefix, this parameter is null.
|
||||
*/
|
||||
public void elementAttributesProcessed(String name,
|
||||
String nsPrefix,
|
||||
String nsURI)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when the end of an XML elemnt is encountered.
|
||||
*
|
||||
* @see #startElement
|
||||
*
|
||||
* @param name the name of the element.
|
||||
* @param nsPrefix the prefix used to identify the namespace. If no
|
||||
* namespace has been specified, this parameter is null.
|
||||
* @param nsURI the URI associated with the namespace. If no
|
||||
* namespace has been specified, or no URI is
|
||||
* associated with nsPrefix, this parameter is null.
|
||||
*/
|
||||
public void endElement(String name,
|
||||
String nsPrefix,
|
||||
String nsURI)
|
||||
{
|
||||
XMLElement elt = (XMLElement) this.stack.pop();
|
||||
|
||||
if (elt.getChildCount() == 1) {
|
||||
XMLElement child = elt.getChildAtIndex(0);
|
||||
|
||||
if (child.getLocalName() == null) {
|
||||
elt.setContent(child.getContent());
|
||||
elt.removeChildAtIndex(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when a new attribute of an XML element is
|
||||
* encountered.
|
||||
*
|
||||
* @param key the key (name) of the attribute.
|
||||
* @param nsPrefix the prefix used to identify the namespace. If no
|
||||
* namespace has been specified, this parameter is null.
|
||||
* @param nsURI the URI associated with the namespace. If no
|
||||
* namespace has been specified, or no URI is
|
||||
* associated with nsPrefix, this parameter is null.
|
||||
* @param value the value of the attribute.
|
||||
* @param type the type of the attribute. If no type is known,
|
||||
* "CDATA" is returned.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* If an exception occurred while processing the event.
|
||||
*/
|
||||
public void addAttribute(String key,
|
||||
String nsPrefix,
|
||||
String nsURI,
|
||||
String value,
|
||||
String type)
|
||||
throws Exception
|
||||
{
|
||||
String fullName = key;
|
||||
|
||||
if (nsPrefix != null) {
|
||||
fullName = nsPrefix + ':' + key;
|
||||
}
|
||||
|
||||
XMLElement top = (XMLElement) this.stack.peek();
|
||||
|
||||
if (top.hasAttribute(fullName)) {
|
||||
throw new XMLParseException(top.getSystemID(),
|
||||
top.getLineNr(),
|
||||
"Duplicate attribute: " + key);
|
||||
}
|
||||
|
||||
if (nsPrefix != null) {
|
||||
top.setAttribute(fullName, nsURI, value);
|
||||
} else {
|
||||
top.setAttribute(fullName, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when a PCDATA element is encountered. A Java
|
||||
* reader is supplied from which you can read the data. The reader will
|
||||
* only read the data of the element. You don't need to check for
|
||||
* boundaries. If you don't read the full element, the rest of the data
|
||||
* is skipped. You also don't have to care about entities; they are
|
||||
* resolved by the parser.
|
||||
*
|
||||
* @param reader the Java reader from which you can retrieve the data.
|
||||
* @param systemID the system ID of the XML data source.
|
||||
* @param lineNr the line in the source where the element starts.
|
||||
*/
|
||||
public void addPCData(Reader reader,
|
||||
String systemID,
|
||||
int lineNr)
|
||||
{
|
||||
int bufSize = 2048;
|
||||
int sizeRead = 0;
|
||||
StringBuffer str = new StringBuffer(bufSize);
|
||||
char[] buf = new char[bufSize];
|
||||
|
||||
for (;;) {
|
||||
if (sizeRead >= bufSize) {
|
||||
bufSize *= 2;
|
||||
str.ensureCapacity(bufSize);
|
||||
}
|
||||
|
||||
int size;
|
||||
|
||||
try {
|
||||
size = reader.read(buf);
|
||||
} catch (IOException e) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (size < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
str.append(buf, 0, size);
|
||||
sizeRead += size;
|
||||
}
|
||||
|
||||
//XMLElement elt = this.prototype.createElement(null, systemID, lineNr);
|
||||
XMLElement elt = new XMLElement(null, null, systemID, lineNr);
|
||||
elt.setContent(str.toString());
|
||||
|
||||
if (! this.stack.empty()) {
|
||||
XMLElement top = (XMLElement) this.stack.peek();
|
||||
top.addChild(elt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the result of the building process. This method is called just
|
||||
* before the <I>parse</I> method of StdXMLParser returns.
|
||||
*
|
||||
* @return the result of the building process.
|
||||
*/
|
||||
public Object getResult()
|
||||
{
|
||||
return this.root;
|
||||
}
|
||||
|
||||
}
|
@ -1,684 +0,0 @@
|
||||
/* StdXMLParser.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2002/03/24 11:37:00 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* StdXMLParser is the core parser of NanoXML.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.5 $
|
||||
*/
|
||||
public class StdXMLParser {
|
||||
|
||||
/**
|
||||
* The builder which creates the logical structure of the XML data.
|
||||
*/
|
||||
private StdXMLBuilder builder;
|
||||
|
||||
|
||||
/**
|
||||
* The reader from which the parser retrieves its data.
|
||||
*/
|
||||
private StdXMLReader reader;
|
||||
|
||||
|
||||
/**
|
||||
* The entity resolver.
|
||||
*/
|
||||
private XMLEntityResolver entityResolver;
|
||||
|
||||
|
||||
/**
|
||||
* The validator that will process entity references and validate the XML
|
||||
* data.
|
||||
*/
|
||||
private XMLValidator validator;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new parser.
|
||||
*/
|
||||
public StdXMLParser()
|
||||
{
|
||||
this.builder = null;
|
||||
this.validator = null;
|
||||
this.reader = null;
|
||||
this.entityResolver = new XMLEntityResolver();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.builder = null;
|
||||
this.reader = null;
|
||||
this.entityResolver = null;
|
||||
this.validator = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the builder which creates the logical structure of the XML data.
|
||||
*
|
||||
* @param builder the non-null builder
|
||||
*/
|
||||
public void setBuilder(StdXMLBuilder builder)
|
||||
{
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the builder which creates the logical structure of the XML data.
|
||||
*
|
||||
* @return the builder
|
||||
*/
|
||||
public StdXMLBuilder getBuilder()
|
||||
{
|
||||
return this.builder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the validator that validates the XML data.
|
||||
*
|
||||
* @param validator the non-null validator
|
||||
*/
|
||||
public void setValidator(XMLValidator validator)
|
||||
{
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the validator that validates the XML data.
|
||||
*
|
||||
* @return the validator
|
||||
*/
|
||||
public XMLValidator getValidator()
|
||||
{
|
||||
return this.validator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the entity resolver.
|
||||
*
|
||||
* @param resolver the non-null resolver
|
||||
*/
|
||||
public void setResolver(XMLEntityResolver resolver)
|
||||
{
|
||||
this.entityResolver = resolver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the entity resolver.
|
||||
*
|
||||
* @return the non-null resolver
|
||||
*/
|
||||
public XMLEntityResolver getResolver()
|
||||
{
|
||||
return this.entityResolver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the reader from which the parser retrieves its data.
|
||||
*
|
||||
* @param reader the reader
|
||||
*/
|
||||
public void setReader(StdXMLReader reader)
|
||||
{
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the reader from which the parser retrieves its data.
|
||||
*
|
||||
* @return the reader
|
||||
*/
|
||||
public StdXMLReader getReader()
|
||||
{
|
||||
return this.reader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the data and lets the builder create the logical data structure.
|
||||
*
|
||||
* @return the logical structure built by the builder
|
||||
*
|
||||
* @throws net.n3.nanoxml.XMLException
|
||||
* if an error occurred reading or parsing the data
|
||||
*/
|
||||
public Object parse()
|
||||
throws XMLException
|
||||
{
|
||||
try {
|
||||
this.builder.startBuilding(this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
this.scanData();
|
||||
return this.builder.getResult();
|
||||
} catch (XMLException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new XMLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans the XML data for elements.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if something went wrong
|
||||
*/
|
||||
protected void scanData() throws Exception {
|
||||
while ((! this.reader.atEOF()) && (this.builder.getResult() == null)) {
|
||||
String str = XMLUtil.read(this.reader, '&');
|
||||
char ch = str.charAt(0);
|
||||
if (ch == '&') {
|
||||
XMLUtil.processEntity(str, this.reader, this.entityResolver);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case '<':
|
||||
this.scanSomeTag(false, // don't allow CDATA
|
||||
null, // no default namespace
|
||||
new Properties());
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\r':
|
||||
case '\n':
|
||||
// skip whitespace
|
||||
break;
|
||||
|
||||
default:
|
||||
XMLUtil.errorInvalidInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"`" + ch + "' (0x"
|
||||
+ Integer.toHexString((int) ch)
|
||||
+ ')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans an XML tag.
|
||||
*
|
||||
* @param allowCDATA true if CDATA sections are allowed at this point
|
||||
* @param defaultNamespace the default namespace URI (or null)
|
||||
* @param namespaces list of defined namespaces
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if something went wrong
|
||||
*/
|
||||
protected void scanSomeTag(boolean allowCDATA,
|
||||
String defaultNamespace,
|
||||
Properties namespaces)
|
||||
throws Exception
|
||||
{
|
||||
String str = XMLUtil.read(this.reader, '&');
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch == '&') {
|
||||
XMLUtil.errorUnexpectedEntity(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
str);
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case '?':
|
||||
this.processPI();
|
||||
break;
|
||||
|
||||
case '!':
|
||||
this.processSpecialTag(allowCDATA);
|
||||
break;
|
||||
|
||||
default:
|
||||
this.reader.unread(ch);
|
||||
this.processElement(defaultNamespace, namespaces);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a "processing instruction".
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if something went wrong
|
||||
*/
|
||||
protected void processPI()
|
||||
throws Exception
|
||||
{
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
String target = XMLUtil.scanIdentifier(this.reader);
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
Reader r = new PIReader(this.reader);
|
||||
|
||||
if (!target.equalsIgnoreCase("xml")) {
|
||||
this.builder.newProcessingInstruction(target, r);
|
||||
}
|
||||
|
||||
r.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a tag that starts with a bang (<!...>).
|
||||
*
|
||||
* @param allowCDATA true if CDATA sections are allowed at this point
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if something went wrong
|
||||
*/
|
||||
protected void processSpecialTag(boolean allowCDATA)
|
||||
throws Exception
|
||||
{
|
||||
String str = XMLUtil.read(this.reader, '&');
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch == '&') {
|
||||
XMLUtil.errorUnexpectedEntity(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
str);
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case '[':
|
||||
if (allowCDATA) {
|
||||
this.processCDATA();
|
||||
} else {
|
||||
XMLUtil.errorUnexpectedCDATA(reader.getSystemID(),
|
||||
reader.getLineNr());
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
case 'D':
|
||||
this.processDocType();
|
||||
return;
|
||||
|
||||
case '-':
|
||||
XMLUtil.skipComment(this.reader);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a CDATA section.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if something went wrong
|
||||
*/
|
||||
protected void processCDATA() throws Exception {
|
||||
if (! XMLUtil.checkLiteral(this.reader, "CDATA[")) {
|
||||
XMLUtil.errorExpectedInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"<![[CDATA[");
|
||||
}
|
||||
|
||||
this.validator.PCDataAdded(this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
Reader r = new CDATAReader(this.reader);
|
||||
this.builder.addPCData(r, this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
r.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a document type declaration.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if an error occurred reading or parsing the data
|
||||
*/
|
||||
protected void processDocType() throws Exception {
|
||||
if (! XMLUtil.checkLiteral(this.reader, "OCTYPE")) {
|
||||
XMLUtil.errorExpectedInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"<!DOCTYPE");
|
||||
return;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
String systemID = null;
|
||||
StringBuffer publicID = new StringBuffer();
|
||||
/*String rootElement =*/ XMLUtil.scanIdentifier(this.reader);
|
||||
//System.out.println("rootElement is " + rootElement);
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
char ch = this.reader.read();
|
||||
|
||||
if (ch == 'P') {
|
||||
systemID = XMLUtil.scanPublicID(publicID, reader);
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
ch = this.reader.read();
|
||||
} else if (ch == 'S') {
|
||||
systemID = XMLUtil.scanSystemID(reader);
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
ch = this.reader.read();
|
||||
}
|
||||
|
||||
if (ch == '[') {
|
||||
this.validator.parseDTD(publicID.toString(),
|
||||
this.reader,
|
||||
this.entityResolver,
|
||||
false);
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
ch = this.reader.read();
|
||||
}
|
||||
|
||||
if (ch != '>') {
|
||||
XMLUtil.errorExpectedInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"`>'");
|
||||
}
|
||||
|
||||
// TODO DTD checking is currently disabled, because it breaks
|
||||
// applications that don't have access to a net connection
|
||||
// (since it insists on going and checking out the DTD).
|
||||
if (false) {
|
||||
if (systemID != null) {
|
||||
Reader r = this.reader.openStream(publicID.toString(), systemID);
|
||||
this.reader.startNewStream(r);
|
||||
this.reader.setSystemID(systemID);
|
||||
this.reader.setPublicID(publicID.toString());
|
||||
this.validator.parseDTD(publicID.toString(),
|
||||
this.reader,
|
||||
this.entityResolver,
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a regular element.
|
||||
*
|
||||
* @param defaultNamespace the default namespace URI (or null)
|
||||
* @param namespaces list of defined namespaces
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if something went wrong
|
||||
*/
|
||||
protected void processElement(String defaultNamespace,
|
||||
Properties namespaces)
|
||||
throws Exception
|
||||
{
|
||||
String fullName = XMLUtil.scanIdentifier(this.reader);
|
||||
String name = fullName;
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
String prefix = null;
|
||||
int colonIndex = name.indexOf(':');
|
||||
|
||||
if (colonIndex > 0) {
|
||||
prefix = name.substring(0, colonIndex);
|
||||
name = name.substring(colonIndex + 1);
|
||||
}
|
||||
|
||||
Vector<String> attrNames = new Vector<String>();
|
||||
Vector<String> attrValues = new Vector<String>();
|
||||
Vector<String> attrTypes = new Vector<String>();
|
||||
|
||||
this.validator.elementStarted(fullName,
|
||||
this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
char ch;
|
||||
|
||||
for (;;) {
|
||||
ch = this.reader.read();
|
||||
|
||||
if ((ch == '/') || (ch == '>')) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.reader.unread(ch);
|
||||
this.processAttribute(attrNames, attrValues, attrTypes);
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
}
|
||||
|
||||
Properties extraAttributes = new Properties();
|
||||
this.validator.elementAttributesProcessed(fullName,
|
||||
extraAttributes,
|
||||
this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
Enumeration<?> en = extraAttributes.keys();
|
||||
|
||||
while (en.hasMoreElements()) {
|
||||
String key = (String) en.nextElement();
|
||||
String value = extraAttributes.getProperty(key);
|
||||
attrNames.addElement(key);
|
||||
attrValues.addElement(value);
|
||||
attrTypes.addElement("CDATA");
|
||||
}
|
||||
|
||||
for (int i = 0; i < attrNames.size(); i++) {
|
||||
String key = (String) attrNames.elementAt(i);
|
||||
String value = (String) attrValues.elementAt(i);
|
||||
//String type = (String) attrTypes.elementAt(i);
|
||||
|
||||
if (key.equals("xmlns")) {
|
||||
defaultNamespace = value;
|
||||
} else if (key.startsWith("xmlns:")) {
|
||||
namespaces.put(key.substring(6), value);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix == null) {
|
||||
this.builder.startElement(name, prefix, defaultNamespace,
|
||||
this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
} else {
|
||||
this.builder.startElement(name, prefix,
|
||||
namespaces.getProperty(prefix),
|
||||
this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
}
|
||||
|
||||
for (int i = 0; i < attrNames.size(); i++) {
|
||||
String key = (String) attrNames.elementAt(i);
|
||||
|
||||
if (key.startsWith("xmlns")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String value = (String) attrValues.elementAt(i);
|
||||
String type = (String) attrTypes.elementAt(i);
|
||||
colonIndex = key.indexOf(':');
|
||||
|
||||
if (colonIndex > 0) {
|
||||
String attPrefix = key.substring(0, colonIndex);
|
||||
key = key.substring(colonIndex + 1);
|
||||
this.builder.addAttribute(key, attPrefix,
|
||||
namespaces.getProperty(attPrefix),
|
||||
value, type);
|
||||
} else {
|
||||
this.builder.addAttribute(key, null, null, value, type);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix == null) {
|
||||
this.builder.elementAttributesProcessed(name, prefix,
|
||||
defaultNamespace);
|
||||
} else {
|
||||
this.builder.elementAttributesProcessed(name, prefix,
|
||||
namespaces
|
||||
.getProperty(prefix));
|
||||
}
|
||||
|
||||
if (ch == '/') {
|
||||
if (this.reader.read() != '>') {
|
||||
XMLUtil.errorExpectedInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"`>'");
|
||||
}
|
||||
|
||||
this.validator.elementEnded(name,
|
||||
this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
|
||||
if (prefix == null) {
|
||||
this.builder.endElement(name, prefix, defaultNamespace);
|
||||
} else {
|
||||
this.builder.endElement(name, prefix,
|
||||
namespaces.getProperty(prefix));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer(16);
|
||||
|
||||
for (;;) {
|
||||
buffer.setLength(0);
|
||||
String str;
|
||||
|
||||
for (;;) {
|
||||
XMLUtil.skipWhitespace(this.reader, buffer);
|
||||
str = XMLUtil.read(this.reader, '&');
|
||||
|
||||
if ((str.charAt(0) == '&') && (str.charAt(1) != '#')) {
|
||||
XMLUtil.processEntity(str, this.reader,
|
||||
this.entityResolver);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (str.charAt(0) == '<') {
|
||||
str = XMLUtil.read(this.reader, '\0');
|
||||
|
||||
if (str.charAt(0) == '/') {
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
str = XMLUtil.scanIdentifier(this.reader);
|
||||
|
||||
if (! str.equals(fullName)) {
|
||||
XMLUtil.errorWrongClosingTag(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
name, str);
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
|
||||
if (this.reader.read() != '>') {
|
||||
XMLUtil.errorClosingTagNotEmpty(reader.getSystemID(),
|
||||
reader.getLineNr());
|
||||
}
|
||||
|
||||
this.validator.elementEnded(fullName,
|
||||
this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
if (prefix == null) {
|
||||
this.builder.endElement(name, prefix, defaultNamespace);
|
||||
} else {
|
||||
this.builder.endElement(name, prefix,
|
||||
namespaces.getProperty(prefix));
|
||||
}
|
||||
break;
|
||||
} else { // <[^/]
|
||||
this.reader.unread(str.charAt(0));
|
||||
this.scanSomeTag(true, //CDATA allowed
|
||||
defaultNamespace,
|
||||
(Properties) namespaces.clone());
|
||||
}
|
||||
} else { // [^<]
|
||||
if (str.charAt(0) == '&') {
|
||||
ch = XMLUtil.processCharLiteral(str);
|
||||
buffer.append(ch);
|
||||
} else {
|
||||
reader.unread(str.charAt(0));
|
||||
}
|
||||
this.validator.PCDataAdded(this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
Reader r = new ContentReader(this.reader,
|
||||
this.entityResolver,
|
||||
buffer.toString());
|
||||
this.builder.addPCData(r, this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
r.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes an attribute of an element.
|
||||
*
|
||||
* @param attrNames contains the names of the attributes.
|
||||
* @param attrValues contains the values of the attributes.
|
||||
* @param attrTypes contains the types of the attributes.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* if something went wrong
|
||||
*/
|
||||
protected void processAttribute(Vector<String> attrNames,
|
||||
Vector<String> attrValues,
|
||||
Vector<String> attrTypes)
|
||||
throws Exception
|
||||
{
|
||||
String key = XMLUtil.scanIdentifier(this.reader);
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
|
||||
if (! XMLUtil.read(this.reader, '&').equals("=")) {
|
||||
XMLUtil.errorExpectedInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"`='");
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(this.reader, null);
|
||||
String value = XMLUtil.scanString(this.reader, '&',
|
||||
this.entityResolver);
|
||||
attrNames.addElement(key);
|
||||
attrValues.addElement(value);
|
||||
attrTypes.addElement("CDATA");
|
||||
this.validator.attributeAdded(key, value,
|
||||
this.reader.getSystemID(),
|
||||
this.reader.getLineNr());
|
||||
}
|
||||
|
||||
}
|
@ -1,626 +0,0 @@
|
||||
/* StdXMLReader.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/01/04 21:03:28 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
//import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.PushbackReader;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
/**
|
||||
* StdXMLReader reads the data to be parsed.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
|
||||
*/
|
||||
public class StdXMLReader
|
||||
{
|
||||
|
||||
/**
|
||||
* A stacked reader.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
|
||||
*/
|
||||
private class StackedReader
|
||||
{
|
||||
|
||||
PushbackReader pbReader;
|
||||
|
||||
LineNumberReader lineReader;
|
||||
|
||||
URL systemId;
|
||||
|
||||
String publicId;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The stack of readers.
|
||||
*/
|
||||
private Stack<StackedReader> readers;
|
||||
|
||||
|
||||
/**
|
||||
* The current push-back reader.
|
||||
*/
|
||||
private StackedReader currentReader;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new reader using a string as input.
|
||||
*
|
||||
* @param str the string containing the XML data
|
||||
*/
|
||||
public static StdXMLReader stringReader(String str)
|
||||
{
|
||||
return new StdXMLReader(new StringReader(str));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new reader using a file as input.
|
||||
*
|
||||
* @param filename the name of the file containing the XML data
|
||||
*
|
||||
* @throws java.io.FileNotFoundException
|
||||
* if the file could not be found
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurred
|
||||
*/
|
||||
public static StdXMLReader fileReader(String filename)
|
||||
throws FileNotFoundException,
|
||||
IOException
|
||||
{
|
||||
StdXMLReader r = new StdXMLReader(new FileInputStream(filename));
|
||||
r.setSystemID(filename);
|
||||
|
||||
for (int i = 0; i < r.readers.size(); i++) {
|
||||
StackedReader sr = (StackedReader) r.readers.elementAt(i);
|
||||
sr.systemId = r.currentReader.systemId;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the reader from a system and public ID.
|
||||
*
|
||||
* @param publicID the public ID which may be null.
|
||||
* @param systemID the non-null system ID.
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* if the system ID does not contain a valid URL
|
||||
* @throws FileNotFoundException
|
||||
* if the system ID refers to a local file which does not exist
|
||||
* @throws IOException
|
||||
* if an error occurred opening the stream
|
||||
*/
|
||||
public StdXMLReader(String publicID,
|
||||
String systemID)
|
||||
throws MalformedURLException,
|
||||
FileNotFoundException,
|
||||
IOException
|
||||
{
|
||||
URL systemIDasURL = null;
|
||||
|
||||
try {
|
||||
systemIDasURL = new URL(systemID);
|
||||
} catch (MalformedURLException e) {
|
||||
systemID = "file:" + systemID;
|
||||
|
||||
try {
|
||||
systemIDasURL = new URL(systemID);
|
||||
} catch (MalformedURLException e2) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
this.currentReader = new StackedReader();
|
||||
this.readers = new Stack<StackedReader>();
|
||||
Reader reader = this.openStream(publicID, systemIDasURL.toString());
|
||||
this.currentReader.lineReader = new LineNumberReader(reader);
|
||||
this.currentReader.pbReader
|
||||
= new PushbackReader(this.currentReader.lineReader, 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the XML reader.
|
||||
*
|
||||
* @param reader the input for the XML data.
|
||||
*/
|
||||
public StdXMLReader(Reader reader)
|
||||
{
|
||||
this.currentReader = new StackedReader();
|
||||
this.readers = new Stack<StackedReader>();
|
||||
this.currentReader.lineReader = new LineNumberReader(reader);
|
||||
this.currentReader.pbReader
|
||||
= new PushbackReader(this.currentReader.lineReader, 2);
|
||||
this.currentReader.publicId = "";
|
||||
|
||||
try {
|
||||
this.currentReader.systemId = new URL("file:.");
|
||||
} catch (MalformedURLException e) {
|
||||
// never happens
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.currentReader.lineReader = null;
|
||||
this.currentReader.pbReader = null;
|
||||
this.currentReader.systemId = null;
|
||||
this.currentReader.publicId = null;
|
||||
this.currentReader = null;
|
||||
this.readers.clear();
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans the encoding from an <?xml...?> tag.
|
||||
*
|
||||
* @param str the first tag in the XML data.
|
||||
*
|
||||
* @return the encoding, or null if no encoding has been specified.
|
||||
*/
|
||||
protected String getEncoding(String str)
|
||||
{
|
||||
if (! str.startsWith("<?xml")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int index = 5;
|
||||
|
||||
while (index < str.length()) {
|
||||
StringBuffer key = new StringBuffer();
|
||||
|
||||
while ((index < str.length()) && (str.charAt(index) <= ' ')) {
|
||||
index++;
|
||||
}
|
||||
|
||||
while ((index < str.length())
|
||||
&& (str.charAt(index) >= 'a')
|
||||
&& (str.charAt(index) <= 'z')) {
|
||||
key.append(str.charAt(index));
|
||||
index++;
|
||||
}
|
||||
|
||||
while ((index < str.length()) && (str.charAt(index) <= ' ')) {
|
||||
index++;
|
||||
}
|
||||
|
||||
if ((index >= str.length()) || (str.charAt(index) != '=')) {
|
||||
break;
|
||||
}
|
||||
|
||||
while ((index < str.length()) && (str.charAt(index) != '\'')
|
||||
&& (str.charAt(index) != '"')) {
|
||||
index++;
|
||||
}
|
||||
|
||||
if (index >= str.length()) {
|
||||
break;
|
||||
}
|
||||
|
||||
char delimiter = str.charAt(index);
|
||||
index++;
|
||||
int index2 = str.indexOf(delimiter, index);
|
||||
|
||||
if (index2 < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (key.toString().equals("encoding")) {
|
||||
return str.substring(index, index2);
|
||||
}
|
||||
|
||||
index = index2 + 1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts a stream to a reader while detecting the encoding.
|
||||
*
|
||||
* @param stream the input for the XML data.
|
||||
* @param charsRead buffer where to put characters that have been read
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurred
|
||||
*/
|
||||
protected Reader stream2reader(InputStream stream,
|
||||
StringBuffer charsRead)
|
||||
throws IOException
|
||||
{
|
||||
PushbackInputStream pbstream = new PushbackInputStream(stream);
|
||||
int b = pbstream.read();
|
||||
|
||||
switch (b) {
|
||||
case 0x00:
|
||||
case 0xFE:
|
||||
case 0xFF:
|
||||
pbstream.unread(b);
|
||||
return new InputStreamReader(pbstream, "UTF-16");
|
||||
|
||||
case 0xEF:
|
||||
for (int i = 0; i < 2; i++) {
|
||||
pbstream.read();
|
||||
}
|
||||
|
||||
return new InputStreamReader(pbstream, "UTF-8");
|
||||
|
||||
case 0x3C:
|
||||
b = pbstream.read();
|
||||
charsRead.append('<');
|
||||
|
||||
while ((b > 0) && (b != 0x3E)) {
|
||||
charsRead.append((char) b);
|
||||
b = pbstream.read();
|
||||
}
|
||||
|
||||
if (b > 0) {
|
||||
charsRead.append((char) b);
|
||||
}
|
||||
|
||||
String encoding = this.getEncoding(charsRead.toString());
|
||||
|
||||
if (encoding == null) {
|
||||
return new InputStreamReader(pbstream, "UTF-8");
|
||||
}
|
||||
|
||||
charsRead.setLength(0);
|
||||
|
||||
try {
|
||||
return new InputStreamReader(pbstream, encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return new InputStreamReader(pbstream, "UTF-8");
|
||||
}
|
||||
|
||||
default:
|
||||
charsRead.append((char) b);
|
||||
return new InputStreamReader(pbstream, "UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the XML reader.
|
||||
*
|
||||
* @param stream the input for the XML data.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurred
|
||||
*/
|
||||
public StdXMLReader(InputStream stream)
|
||||
throws IOException
|
||||
{
|
||||
// unused?
|
||||
//PushbackInputStream pbstream = new PushbackInputStream(stream);
|
||||
StringBuffer charsRead = new StringBuffer();
|
||||
Reader reader = this.stream2reader(stream, charsRead);
|
||||
this.currentReader = new StackedReader();
|
||||
this.readers = new Stack<StackedReader>();
|
||||
this.currentReader.lineReader = new LineNumberReader(reader);
|
||||
this.currentReader.pbReader
|
||||
= new PushbackReader(this.currentReader.lineReader, 2);
|
||||
this.currentReader.publicId = "";
|
||||
|
||||
try {
|
||||
this.currentReader.systemId = new URL("file:.");
|
||||
} catch (MalformedURLException e) {
|
||||
// never happens
|
||||
}
|
||||
|
||||
this.startNewStream(new StringReader(charsRead.toString()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a character.
|
||||
*
|
||||
* @return the character
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if no character could be read
|
||||
*/
|
||||
public char read()
|
||||
throws IOException
|
||||
{
|
||||
int ch = this.currentReader.pbReader.read();
|
||||
|
||||
while (ch < 0) {
|
||||
if (this.readers.empty()) {
|
||||
throw new IOException("Unexpected EOF");
|
||||
}
|
||||
|
||||
this.currentReader.pbReader.close();
|
||||
this.currentReader = (StackedReader) this.readers.pop();
|
||||
ch = this.currentReader.pbReader.read();
|
||||
}
|
||||
|
||||
return (char) ch;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the current stream has no more characters left to be
|
||||
* read.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurred
|
||||
*/
|
||||
public boolean atEOFOfCurrentStream()
|
||||
throws IOException
|
||||
{
|
||||
int ch = this.currentReader.pbReader.read();
|
||||
|
||||
if (ch < 0) {
|
||||
return true;
|
||||
} else {
|
||||
this.currentReader.pbReader.unread(ch);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if there are no more characters left to be read.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurred
|
||||
*/
|
||||
public boolean atEOF()
|
||||
throws IOException
|
||||
{
|
||||
int ch = this.currentReader.pbReader.read();
|
||||
|
||||
while (ch < 0) {
|
||||
if (this.readers.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.currentReader.pbReader.close();
|
||||
this.currentReader = (StackedReader) this.readers.pop();
|
||||
ch = this.currentReader.pbReader.read();
|
||||
}
|
||||
|
||||
this.currentReader.pbReader.unread(ch);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pushes the last character read back to the stream.
|
||||
*
|
||||
* @param ch the character to push back.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an I/O error occurred
|
||||
*/
|
||||
public void unread(char ch)
|
||||
throws IOException
|
||||
{
|
||||
this.currentReader.pbReader.unread(ch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Opens a stream from a public and system ID.
|
||||
*
|
||||
* @param publicID the public ID, which may be null
|
||||
* @param systemID the system ID, which is never null
|
||||
*
|
||||
* @throws java.net.MalformedURLException
|
||||
* if the system ID does not contain a valid URL
|
||||
* @throws java.io.FileNotFoundException
|
||||
* if the system ID refers to a local file which does not exist
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred opening the stream
|
||||
*/
|
||||
public Reader openStream(String publicID,
|
||||
String systemID)
|
||||
throws MalformedURLException,
|
||||
FileNotFoundException,
|
||||
IOException
|
||||
{
|
||||
URL url = new URL(this.currentReader.systemId, systemID);
|
||||
|
||||
if (url.getRef() != null) {
|
||||
String ref = url.getRef();
|
||||
|
||||
if (url.getFile().length() > 0) {
|
||||
url = new URL(url.getProtocol(), url.getHost(), url.getPort(),
|
||||
url.getFile());
|
||||
url = new URL("jar:" + url + '!' + ref);
|
||||
} else {
|
||||
url = StdXMLReader.class.getResource(ref);
|
||||
}
|
||||
}
|
||||
|
||||
this.currentReader.publicId = publicID;
|
||||
this.currentReader.systemId = url;
|
||||
StringBuffer charsRead = new StringBuffer();
|
||||
Reader reader = this.stream2reader(url.openStream(), charsRead);
|
||||
|
||||
if (charsRead.length() == 0) {
|
||||
return reader;
|
||||
}
|
||||
|
||||
String charsReadStr = charsRead.toString();
|
||||
PushbackReader pbreader = new PushbackReader(reader,
|
||||
charsReadStr.length());
|
||||
|
||||
for (int i = charsReadStr.length() - 1; i >= 0; i--) {
|
||||
pbreader.unread(charsReadStr.charAt(i));
|
||||
}
|
||||
|
||||
return pbreader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts a new stream from a Java reader. The new stream is used
|
||||
* temporary to read data from. If that stream is exhausted, control
|
||||
* returns to the parent stream.
|
||||
*
|
||||
* @param reader the non-null reader to read the new data from
|
||||
*/
|
||||
public void startNewStream(Reader reader)
|
||||
{
|
||||
this.startNewStream(reader, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts a new stream from a Java reader. The new stream is used
|
||||
* temporary to read data from. If that stream is exhausted, control
|
||||
* returns to the parent stream.
|
||||
*
|
||||
* @param reader the non-null reader to read the new data from
|
||||
* @param isInternalEntity true if the reader is produced by resolving
|
||||
* an internal entity
|
||||
*/
|
||||
public void startNewStream(Reader reader,
|
||||
boolean isInternalEntity)
|
||||
{
|
||||
StackedReader oldReader = this.currentReader;
|
||||
this.readers.push(this.currentReader);
|
||||
this.currentReader = new StackedReader();
|
||||
|
||||
if (isInternalEntity) {
|
||||
this.currentReader.lineReader = null;
|
||||
this.currentReader.pbReader = new PushbackReader(reader, 2);
|
||||
} else {
|
||||
this.currentReader.lineReader = new LineNumberReader(reader);
|
||||
this.currentReader.pbReader
|
||||
= new PushbackReader(this.currentReader.lineReader, 2);
|
||||
}
|
||||
|
||||
this.currentReader.systemId = oldReader.systemId;
|
||||
this.currentReader.publicId = oldReader.publicId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current "level" of the stream on the stack of streams.
|
||||
*/
|
||||
public int getStreamLevel()
|
||||
{
|
||||
return this.readers.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line number of the data in the current stream.
|
||||
*/
|
||||
public int getLineNr()
|
||||
{
|
||||
if (this.currentReader.lineReader == null) {
|
||||
StackedReader sr = (StackedReader) this.readers.peek();
|
||||
|
||||
if (sr.lineReader == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return sr.lineReader.getLineNumber() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return this.currentReader.lineReader.getLineNumber() + 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the system ID of the current stream.
|
||||
*
|
||||
* @param systemID the system ID
|
||||
*
|
||||
* @throws java.net.MalformedURLException
|
||||
* if the system ID does not contain a valid URL
|
||||
*/
|
||||
public void setSystemID(String systemID)
|
||||
throws MalformedURLException
|
||||
{
|
||||
this.currentReader.systemId = new URL(this.currentReader.systemId,
|
||||
systemID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the public ID of the current stream.
|
||||
*
|
||||
* @param publicID the public ID
|
||||
*/
|
||||
public void setPublicID(String publicID)
|
||||
{
|
||||
this.currentReader.publicId = publicID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current system ID.
|
||||
*/
|
||||
public String getSystemID()
|
||||
{
|
||||
return this.currentReader.systemId.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current public ID.
|
||||
*/
|
||||
public String getPublicID()
|
||||
{
|
||||
return this.currentReader.publicId;
|
||||
}
|
||||
|
||||
}
|
@ -1,153 +0,0 @@
|
||||
/* XMLAttribute.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/01/04 21:03:29 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
/**
|
||||
* An attribute in an XML element. This is an internal class.
|
||||
*
|
||||
* @see net.n3.nanoxml.XMLElement
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
|
||||
*/
|
||||
class XMLAttribute
|
||||
{
|
||||
|
||||
/**
|
||||
* The full name of the attribute.
|
||||
*/
|
||||
private String fullName;
|
||||
|
||||
|
||||
/**
|
||||
* The short name of the attribute.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* The namespace URI of the attribute.
|
||||
*/
|
||||
private String namespace;
|
||||
|
||||
|
||||
/**
|
||||
* The value of the attribute.
|
||||
*/
|
||||
private String value;
|
||||
|
||||
|
||||
/**
|
||||
* The type of the attribute.
|
||||
*/
|
||||
private String type;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new attribute.
|
||||
*
|
||||
* @param fullName the non-null full name
|
||||
* @param name the non-null short name
|
||||
* @param namespace the namespace URI, which may be null
|
||||
* @param value the value of the attribute
|
||||
* @param type the type of the attribute
|
||||
*/
|
||||
XMLAttribute(String fullName,
|
||||
String name,
|
||||
String namespace,
|
||||
String value,
|
||||
String type)
|
||||
{
|
||||
this.fullName = fullName;
|
||||
this.name = name;
|
||||
this.namespace = namespace;
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the full name of the attribute.
|
||||
*/
|
||||
String getFullName()
|
||||
{
|
||||
return this.fullName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the short name of the attribute.
|
||||
*/
|
||||
String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the namespace of the attribute.
|
||||
*/
|
||||
String getNamespace()
|
||||
{
|
||||
return this.namespace;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of the attribute.
|
||||
*/
|
||||
String getValue()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the value of the attribute.
|
||||
*
|
||||
* @param value the new value.
|
||||
*/
|
||||
void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the type of the attribute.
|
||||
*
|
||||
* @param type the new type.
|
||||
*/
|
||||
String getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,173 +0,0 @@
|
||||
/* XMLEntityResolver.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/01/04 21:03:29 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
|
||||
/**
|
||||
* An XMLEntityResolver resolves entities.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
|
||||
*/
|
||||
public class XMLEntityResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* The entities.
|
||||
*/
|
||||
private Hashtable<String, Object> entities;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the resolver.
|
||||
*/
|
||||
public XMLEntityResolver()
|
||||
{
|
||||
this.entities = new Hashtable<String, Object>();
|
||||
this.entities.put("amp", "&");
|
||||
this.entities.put("quot", """);
|
||||
this.entities.put("apos", "'");
|
||||
this.entities.put("lt", "<");
|
||||
this.entities.put("gt", ">");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.entities.clear();
|
||||
this.entities = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an internal entity.
|
||||
*
|
||||
* @param name the name of the entity.
|
||||
* @param value the value of the entity.
|
||||
*/
|
||||
public void addInternalEntity(String name,
|
||||
String value)
|
||||
{
|
||||
if (! this.entities.containsKey(name)) {
|
||||
this.entities.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an external entity.
|
||||
*
|
||||
* @param name the name of the entity.
|
||||
* @param publicID the public ID of the entity, which may be null.
|
||||
* @param systemID the system ID of the entity.
|
||||
*/
|
||||
public void addExternalEntity(String name,
|
||||
String publicID,
|
||||
String systemID)
|
||||
{
|
||||
if (! this.entities.containsKey(name)) {
|
||||
this.entities.put(name, new String[] { publicID, systemID } );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a Java reader containing the value of an entity.
|
||||
*
|
||||
* @param xmlReader the current XML reader
|
||||
* @param name the name of the entity.
|
||||
*
|
||||
* @return the reader, or null if the entity could not be resolved.
|
||||
*/
|
||||
public Reader getEntity(StdXMLReader xmlReader,
|
||||
String name)
|
||||
throws XMLParseException
|
||||
{
|
||||
Object obj = this.entities.get(name);
|
||||
|
||||
if (obj == null) {
|
||||
return null;
|
||||
} else if (obj instanceof java.lang.String) {
|
||||
return new StringReader((String)obj);
|
||||
} else {
|
||||
String[] id = (String[]) obj;
|
||||
return this.openExternalEntity(xmlReader, id[0], id[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if an entity is external.
|
||||
*
|
||||
* @param name the name of the entity.
|
||||
*/
|
||||
public boolean isExternalEntity(String name)
|
||||
{
|
||||
Object obj = this.entities.get(name);
|
||||
return ! (obj instanceof java.lang.String);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Opens an external entity.
|
||||
*
|
||||
* @param xmlReader the current XML reader
|
||||
* @param publicID the public ID, which may be null
|
||||
* @param systemID the system ID
|
||||
*
|
||||
* @return the reader, or null if the reader could not be created/opened
|
||||
*/
|
||||
protected Reader openExternalEntity(StdXMLReader xmlReader,
|
||||
String publicID,
|
||||
String systemID)
|
||||
throws XMLParseException
|
||||
{
|
||||
String parentSystemID = xmlReader.getSystemID();
|
||||
|
||||
try {
|
||||
return xmlReader.openStream(publicID, systemID);
|
||||
} catch (Exception e) {
|
||||
throw new XMLParseException(parentSystemID,
|
||||
xmlReader.getLineNr(),
|
||||
"Could not open external entity "
|
||||
+ "at system ID: " + systemID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,286 +0,0 @@
|
||||
/* XMLException.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/01/04 21:03:29 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
|
||||
/**
|
||||
* An XMLException is thrown when an exception occurred while processing the
|
||||
* XML data.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
|
||||
*/
|
||||
public class XMLException
|
||||
extends Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* The message of the exception.
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
|
||||
/**
|
||||
* The system ID of the XML data where the exception occurred.
|
||||
*/
|
||||
private String systemID;
|
||||
|
||||
|
||||
/**
|
||||
* The line number in the XML data where the exception occurred.
|
||||
*/
|
||||
private int lineNr;
|
||||
|
||||
|
||||
/**
|
||||
* Encapsulated exception.
|
||||
*/
|
||||
private Exception encapsulatedException;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param msg the message of the exception.
|
||||
*/
|
||||
public XMLException(String msg)
|
||||
{
|
||||
this(null, -1, null, msg, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param e the encapsulated exception.
|
||||
*/
|
||||
public XMLException(Exception e)
|
||||
{
|
||||
this(null, -1, e, "Nested Exception", false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param systemID the system ID of the XML data where the exception
|
||||
* occurred
|
||||
* @param lineNr the line number in the XML data where the exception
|
||||
* occurred.
|
||||
* @param e the encapsulated exception.
|
||||
*/
|
||||
public XMLException(String systemID,
|
||||
int lineNr,
|
||||
Exception e)
|
||||
{
|
||||
this(systemID, lineNr, e, "Nested Exception", true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param systemID the system ID of the XML data where the exception
|
||||
* occurred
|
||||
* @param lineNr the line number in the XML data where the exception
|
||||
* occurred.
|
||||
* @param msg the message of the exception.
|
||||
*/
|
||||
public XMLException(String systemID,
|
||||
int lineNr,
|
||||
String msg)
|
||||
{
|
||||
this(systemID, lineNr, null, msg, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param systemID the system ID from where the data came
|
||||
* @param lineNr the line number in the XML data where the exception
|
||||
* occurred.
|
||||
* @param e the encapsulated exception.
|
||||
* @param msg the message of the exception.
|
||||
* @param reportParams true if the systemID, lineNr and e params need to be
|
||||
* appended to the message
|
||||
*/
|
||||
public XMLException(String systemID,
|
||||
int lineNr,
|
||||
Exception e,
|
||||
String msg,
|
||||
boolean reportParams)
|
||||
{
|
||||
super(XMLException.buildMessage(systemID, lineNr, e, msg,
|
||||
reportParams));
|
||||
this.systemID = systemID;
|
||||
this.lineNr = lineNr;
|
||||
this.encapsulatedException = e;
|
||||
this.msg = XMLException.buildMessage(systemID, lineNr, e, msg,
|
||||
reportParams);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the exception message
|
||||
*
|
||||
* @param systemID the system ID from where the data came
|
||||
* @param lineNr the line number in the XML data where the exception
|
||||
* occurred.
|
||||
* @param e the encapsulated exception.
|
||||
* @param msg the message of the exception.
|
||||
* @param reportParams true if the systemID, lineNr and e params need to be
|
||||
* appended to the message
|
||||
*/
|
||||
private static String buildMessage(String systemID,
|
||||
int lineNr,
|
||||
Exception e,
|
||||
String msg,
|
||||
boolean reportParams)
|
||||
{
|
||||
String str = msg;
|
||||
|
||||
if (reportParams) {
|
||||
if (systemID != null) {
|
||||
str += ", SystemID='" + systemID + "'";
|
||||
}
|
||||
|
||||
if (lineNr >= 0) {
|
||||
str += ", Line=" + lineNr;
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
str += ", Exception: " + e;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.systemID = null;
|
||||
this.encapsulatedException = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the system ID of the XML data where the exception occurred.
|
||||
* If there is no system ID known, null is returned.
|
||||
*/
|
||||
public String getSystemID()
|
||||
{
|
||||
return this.systemID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the line number in the XML data where the exception occurred.
|
||||
* If there is no line number known, -1 is returned.
|
||||
*/
|
||||
public int getLineNr()
|
||||
{
|
||||
return this.lineNr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the encapsulated exception, or null if no exception is
|
||||
* encapsulated.
|
||||
*/
|
||||
public Exception getException()
|
||||
{
|
||||
return this.encapsulatedException;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the exception stack to a print writer.
|
||||
*
|
||||
* @param writer the print writer
|
||||
*/
|
||||
public void printStackTrace(PrintWriter writer)
|
||||
{
|
||||
super.printStackTrace(writer);
|
||||
|
||||
if (this.encapsulatedException != null) {
|
||||
writer.println("*** Nested Exception:");
|
||||
this.encapsulatedException.printStackTrace(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the exception stack to an output stream.
|
||||
*
|
||||
* @param stream the output stream
|
||||
*/
|
||||
public void printStackTrace(PrintStream stream)
|
||||
{
|
||||
super.printStackTrace(stream);
|
||||
|
||||
if (this.encapsulatedException != null) {
|
||||
stream.println("*** Nested Exception:");
|
||||
this.encapsulatedException.printStackTrace(stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the exception stack to System.err.
|
||||
*/
|
||||
public void printStackTrace()
|
||||
{
|
||||
super.printStackTrace();
|
||||
|
||||
if (this.encapsulatedException != null) {
|
||||
System.err.println("*** Nested Exception:");
|
||||
this.encapsulatedException.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string representation of the exception.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return this.msg;
|
||||
}
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/* XMLParseException.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2002/01/04 21:03:29 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
/**
|
||||
* An XMLParseException is thrown when the XML passed to the XML parser is not
|
||||
* well-formed.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $
|
||||
*/
|
||||
public class XMLParseException
|
||||
extends XMLException
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param msg the message of the exception.
|
||||
*/
|
||||
public XMLParseException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param systemID the system ID from where the data came
|
||||
* @param lineNr the line number in the XML data where the exception
|
||||
* occurred.
|
||||
* @param msg the message of the exception.
|
||||
*/
|
||||
public XMLParseException(String systemID,
|
||||
int lineNr,
|
||||
String msg)
|
||||
{
|
||||
super(systemID, lineNr, null, msg, true);
|
||||
}
|
||||
|
||||
}
|
@ -1,758 +0,0 @@
|
||||
/* XMLUtil.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2002/02/03 21:19:38 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
|
||||
/**
|
||||
* Utility methods for NanoXML.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.5 $
|
||||
*/
|
||||
class XMLUtil
|
||||
{
|
||||
|
||||
/**
|
||||
* Skips the remainder of a comment.
|
||||
* It is assumed that <!- is already read.
|
||||
*
|
||||
* @param reader the reader
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static void skipComment(StdXMLReader reader)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
if (reader.read() != '-') {
|
||||
XMLUtil.errorExpectedInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"<!--");
|
||||
}
|
||||
|
||||
int dashesRead = 0;
|
||||
|
||||
for (;;) {
|
||||
char ch = reader.read();
|
||||
|
||||
switch (ch) {
|
||||
case '-':
|
||||
dashesRead++;
|
||||
break;
|
||||
|
||||
case '>':
|
||||
if (dashesRead == 2) {
|
||||
return;
|
||||
}
|
||||
dashesRead = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
dashesRead = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skips the remainder of the current XML tag.
|
||||
*
|
||||
* @param reader the reader
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static void skipTag(StdXMLReader reader)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
int level = 1;
|
||||
|
||||
while (level > 0) {
|
||||
char ch = reader.read();
|
||||
|
||||
switch (ch) {
|
||||
case '<':
|
||||
++level;
|
||||
break;
|
||||
|
||||
case '>':
|
||||
--level;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans a public ID.
|
||||
*
|
||||
* @param publicID will contain the public ID
|
||||
* @param reader the reader
|
||||
*
|
||||
* @return the system ID
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static String scanPublicID(StringBuffer publicID,
|
||||
StdXMLReader reader)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
if (! XMLUtil.checkLiteral(reader, "UBLIC")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
publicID.append(XMLUtil.scanString(reader, '\0', null));
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
return XMLUtil.scanString(reader, '\0', null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans a system ID.
|
||||
*
|
||||
* @param reader the reader
|
||||
*
|
||||
* @return the system ID
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static String scanSystemID(StdXMLReader reader)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
if (! XMLUtil.checkLiteral(reader, "YSTEM")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
return XMLUtil.scanString(reader, '\0', null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves an identifier from the data.
|
||||
*
|
||||
* @param reader the reader
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static String scanIdentifier(StdXMLReader reader)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
||||
for (;;) {
|
||||
char ch = reader.read();
|
||||
|
||||
if ((ch == '_') || (ch == ':') || (ch == '-') || (ch == '.')
|
||||
|| ((ch >= 'a') && (ch <= 'z'))
|
||||
|| ((ch >= 'A') && (ch <= 'Z'))
|
||||
|| ((ch >= '0') && (ch <= '9')) || (ch > '\u007E')) {
|
||||
result.append(ch);
|
||||
} else {
|
||||
reader.unread(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a delimited string from the data.
|
||||
*
|
||||
* @param reader the reader
|
||||
* @param entityChar the escape character (& or %)
|
||||
* @param entityResolver the entity resolver
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static String scanString(StdXMLReader reader,
|
||||
char entityChar,
|
||||
XMLEntityResolver entityResolver)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
StringBuffer result = new StringBuffer();
|
||||
int startingLevel = reader.getStreamLevel();
|
||||
char delim = reader.read();
|
||||
|
||||
if ((delim != '\'') && (delim != '"')) {
|
||||
XMLUtil.errorExpectedInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
"delimited string");
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
String str = XMLUtil.read(reader, entityChar);
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch == entityChar) {
|
||||
if (str.charAt(1) == '#') {
|
||||
result.append(XMLUtil.processCharLiteral(str));
|
||||
} else {
|
||||
XMLUtil.processEntity(str, reader, entityResolver);
|
||||
}
|
||||
} else if (ch == '&') {
|
||||
reader.unread(ch);
|
||||
str = XMLUtil.read(reader, '&');
|
||||
if (str.charAt(1) == '#') {
|
||||
result.append(XMLUtil.processCharLiteral(str));
|
||||
} else {
|
||||
result.append(str);
|
||||
}
|
||||
} else if (reader.getStreamLevel() == startingLevel) {
|
||||
if (ch == delim) {
|
||||
break;
|
||||
} else if ((ch == 9) || (ch == 10) || (ch == 13)) {
|
||||
result.append(' ');
|
||||
} else {
|
||||
result.append(ch);
|
||||
}
|
||||
} else {
|
||||
result.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes an entity.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param reader the reader
|
||||
* @param entityResolver the entity resolver
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static void processEntity(String entity,
|
||||
StdXMLReader reader,
|
||||
XMLEntityResolver entityResolver)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
entity = entity.substring(1, entity.length() - 1);
|
||||
Reader entityReader = entityResolver.getEntity(reader, entity);
|
||||
|
||||
if (entityReader == null) {
|
||||
XMLUtil.errorInvalidEntity(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
entity);
|
||||
}
|
||||
|
||||
boolean externalEntity = entityResolver.isExternalEntity(entity);
|
||||
reader.startNewStream(entityReader, !externalEntity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a character literal.
|
||||
*
|
||||
* @param entity the entity
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static char processCharLiteral(String entity)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
if (entity.charAt(2) == 'x') {
|
||||
entity = entity.substring(3, entity.length() - 1);
|
||||
return (char) Integer.parseInt(entity, 16);
|
||||
} else {
|
||||
entity = entity.substring(2, entity.length() - 1);
|
||||
return (char) Integer.parseInt(entity, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skips whitespace from the reader.
|
||||
*
|
||||
* @param reader the reader
|
||||
* @param buffer where to put the whitespace; null if the
|
||||
* whitespace does not have to be stored.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static void skipWhitespace(StdXMLReader reader,
|
||||
StringBuffer buffer)
|
||||
throws IOException
|
||||
{
|
||||
char ch;
|
||||
|
||||
if (buffer == null) {
|
||||
do {
|
||||
ch = reader.read();
|
||||
} while ((ch == ' ') || (ch == '\t') || (ch == '\n'));
|
||||
} else {
|
||||
for (;;) {
|
||||
ch = reader.read();
|
||||
|
||||
if ((ch != ' ') && (ch != '\t') && (ch != '\n')) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ch == '\n') {
|
||||
buffer.append('\n');
|
||||
} else {
|
||||
buffer.append(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reader.unread(ch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a character from the reader.
|
||||
*
|
||||
* @param reader the reader
|
||||
* @param entityChar the escape character (& or %) used to indicate
|
||||
* an entity
|
||||
*
|
||||
* @return the character, or an entity expression (like e.g. &lt;)
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static String read(StdXMLReader reader,
|
||||
char entityChar) throws IOException, XMLParseException {
|
||||
char ch = reader.read();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(ch);
|
||||
|
||||
if (ch == entityChar) {
|
||||
while (ch != ';') {
|
||||
ch = reader.read();
|
||||
buf.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a character from the reader disallowing entities.
|
||||
*
|
||||
* @param reader the reader
|
||||
* @param entityChar the escape character (& or %) used to indicate
|
||||
* an entity
|
||||
*/
|
||||
static char readChar(StdXMLReader reader,
|
||||
char entityChar) throws IOException, XMLParseException {
|
||||
String str = XMLUtil.read(reader, entityChar);
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch == entityChar) {
|
||||
XMLUtil.errorUnexpectedEntity(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
str);
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the data starts with <I>literal</I>.
|
||||
* Enough chars are read to determine this result.
|
||||
*
|
||||
* @param reader the reader
|
||||
* @param literal the literal to check
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
* if an error occurred reading the data
|
||||
*/
|
||||
static boolean checkLiteral(StdXMLReader reader,
|
||||
String literal)
|
||||
throws IOException,
|
||||
XMLParseException
|
||||
{
|
||||
for (int i = 0; i < literal.length(); i++) {
|
||||
if (reader.read() != literal.charAt(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLParseException to indicate that an expected string is not
|
||||
* encountered.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param expectedString the string that is expected
|
||||
*/
|
||||
static void errorExpectedInput(String systemID,
|
||||
int lineNr,
|
||||
String expectedString)
|
||||
throws XMLParseException
|
||||
{
|
||||
throw new XMLParseException(systemID, lineNr,
|
||||
"Expected: " + expectedString);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLParseException to indicate that an entity could not be
|
||||
* resolved.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param entity the name of the entity
|
||||
*/
|
||||
static void errorInvalidEntity(String systemID,
|
||||
int lineNr,
|
||||
String entity)
|
||||
throws XMLParseException
|
||||
{
|
||||
throw new XMLParseException(systemID, lineNr,
|
||||
"Invalid entity: `&" + entity + ";'");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLParseException to indicate that an entity reference is
|
||||
* unexpected at this point.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param entity the name of the entity
|
||||
*/
|
||||
static void errorUnexpectedEntity(String systemID,
|
||||
int lineNr,
|
||||
String entity)
|
||||
throws XMLParseException
|
||||
{
|
||||
throw new XMLParseException(systemID, lineNr,
|
||||
"No entity reference is expected here ("
|
||||
+ entity + ")");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLParseException to indicate that a CDATA section is
|
||||
* unexpected at this point.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
*/
|
||||
static void errorUnexpectedCDATA(String systemID,
|
||||
int lineNr)
|
||||
throws XMLParseException
|
||||
{
|
||||
throw new XMLParseException(systemID, lineNr,
|
||||
"No CDATA section is expected here");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLParseException to indicate that a string is not expected
|
||||
* at this point.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param unexpectedString the string that is unexpected
|
||||
*/
|
||||
static void errorInvalidInput(String systemID,
|
||||
int lineNr,
|
||||
String unexpectedString)
|
||||
throws XMLParseException
|
||||
{
|
||||
throw new XMLParseException(systemID, lineNr,
|
||||
"Invalid input: " + unexpectedString);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLParseException to indicate that the closing tag of an
|
||||
* element does not match the opening tag.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param expectedName the name of the opening tag
|
||||
* @param wrongName the name of the closing tag
|
||||
*/
|
||||
static void errorWrongClosingTag(String systemID,
|
||||
int lineNr,
|
||||
String expectedName,
|
||||
String wrongName)
|
||||
throws XMLParseException
|
||||
{
|
||||
throw new XMLParseException(systemID, lineNr,
|
||||
"Closing tag does not match opening tag: `"
|
||||
+ wrongName + "' != `" + expectedName
|
||||
+ "'");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLParseException to indicate that extra data is encountered
|
||||
* in a closing tag.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
*/
|
||||
static void errorClosingTagNotEmpty(String systemID,
|
||||
int lineNr)
|
||||
throws XMLParseException
|
||||
{
|
||||
throw new XMLParseException(systemID, lineNr,
|
||||
"Closing tag must be empty");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException to indicate that an element is missing.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param parentElementName the name of the parent element
|
||||
* @param missingElementName the name of the missing element
|
||||
*/
|
||||
static void errorMissingElement(String systemID,
|
||||
int lineNr,
|
||||
String parentElementName,
|
||||
String missingElementName)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(
|
||||
XMLValidationException.MISSING_ELEMENT,
|
||||
systemID, lineNr,
|
||||
missingElementName,
|
||||
/*attributeName*/ null,
|
||||
/*attributeValue*/ null,
|
||||
"Element " + parentElementName
|
||||
+ " expects to have a " + missingElementName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException to indicate that an element is
|
||||
* unexpected.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param parentElementName the name of the parent element
|
||||
* @param unexpectedElementName the name of the unexpected element
|
||||
*/
|
||||
static void errorUnexpectedElement(String systemID,
|
||||
int lineNr,
|
||||
String parentElementName,
|
||||
String unexpectedElementName)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(
|
||||
XMLValidationException.UNEXPECTED_ELEMENT,
|
||||
systemID, lineNr,
|
||||
unexpectedElementName,
|
||||
/*attributeName*/ null,
|
||||
/*attributeValue*/ null,
|
||||
"Unexpected " + unexpectedElementName + " in a "
|
||||
+ parentElementName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException to indicate that an attribute is
|
||||
* missing.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param elementName the name of the element
|
||||
* @param attributeName the name of the missing attribute
|
||||
*/
|
||||
static void errorMissingAttribute(String systemID,
|
||||
int lineNr,
|
||||
String elementName,
|
||||
String attributeName)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(
|
||||
XMLValidationException.MISSING_ATTRIBUTE,
|
||||
systemID, lineNr,
|
||||
elementName,
|
||||
attributeName,
|
||||
/*attributeValue*/ null,
|
||||
"Element " + elementName + " expects an attribute named "
|
||||
+ attributeName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException to indicate that an attribute is
|
||||
* unexpected.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param elementName the name of the element
|
||||
* @param attributeName the name of the unexpected attribute
|
||||
*/
|
||||
static void errorUnexpectedAttribute(String systemID,
|
||||
int lineNr,
|
||||
String elementName,
|
||||
String attributeName)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(
|
||||
XMLValidationException.UNEXPECTED_ATTRIBUTE,
|
||||
systemID, lineNr,
|
||||
elementName,
|
||||
attributeName,
|
||||
/*attributeValue*/ null,
|
||||
"Element " + elementName + " did not expect an attribute "
|
||||
+ "named " + attributeName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException to indicate that an attribute has an
|
||||
* invalid value.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param elementName the name of the element
|
||||
* @param attributeName the name of the attribute
|
||||
* @param attributeValue the value of that attribute
|
||||
*/
|
||||
static void errorInvalidAttributeValue(String systemID,
|
||||
int lineNr,
|
||||
String elementName,
|
||||
String attributeName,
|
||||
String attributeValue)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(
|
||||
XMLValidationException.ATTRIBUTE_WITH_INVALID_VALUE,
|
||||
systemID, lineNr,
|
||||
elementName,
|
||||
attributeName,
|
||||
attributeValue,
|
||||
"Invalid value for attribute " + attributeName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException to indicate that a #PCDATA element was
|
||||
* missing.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param parentElementName the name of the parent element
|
||||
*/
|
||||
static void errorMissingPCData(String systemID,
|
||||
int lineNr,
|
||||
String parentElementName)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(
|
||||
XMLValidationException.MISSING_PCDATA,
|
||||
systemID, lineNr,
|
||||
/*elementName*/ null,
|
||||
/*attributeName*/ null,
|
||||
/*attributeValue*/ null,
|
||||
"Missing #PCDATA in element " + parentElementName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException to indicate that a #PCDATA element was
|
||||
* unexpected.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param parentElementName the name of the parent element
|
||||
*/
|
||||
static void errorUnexpectedPCData(String systemID,
|
||||
int lineNr,
|
||||
String parentElementName)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(
|
||||
XMLValidationException.UNEXPECTED_PCDATA,
|
||||
systemID, lineNr,
|
||||
/*elementName*/ null,
|
||||
/*attributeName*/ null,
|
||||
/*attributeValue*/ null,
|
||||
"Unexpected #PCDATA in element " + parentElementName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws an XMLValidationException.
|
||||
*
|
||||
* @param systemID the system ID of the data source
|
||||
* @param lineNr the line number in the data source
|
||||
* @param message the error message
|
||||
* @param elementName the name of the element
|
||||
* @param attributeName the name of the attribute
|
||||
* @param attributeValue the value of that attribute
|
||||
*/
|
||||
static void validationError(String systemID,
|
||||
int lineNr,
|
||||
String message,
|
||||
String elementName,
|
||||
String attributeName,
|
||||
String attributeValue)
|
||||
throws XMLValidationException
|
||||
{
|
||||
throw new XMLValidationException(XMLValidationException.MISC_ERROR,
|
||||
systemID, lineNr,
|
||||
elementName,
|
||||
attributeName,
|
||||
attributeValue,
|
||||
message);
|
||||
}
|
||||
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
/* XMLValidationException.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2002/01/04 21:03:29 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
/**
|
||||
* An XMLValidationException is thrown when the XML passed to the XML parser is
|
||||
* well-formed but not valid.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $
|
||||
*/
|
||||
public class XMLValidationException
|
||||
extends XMLException
|
||||
{
|
||||
|
||||
/**
|
||||
* An element was missing.
|
||||
*/
|
||||
public static final int MISSING_ELEMENT = 1;
|
||||
|
||||
|
||||
/**
|
||||
* An unexpected element was encountered.
|
||||
*/
|
||||
public static final int UNEXPECTED_ELEMENT = 2;
|
||||
|
||||
|
||||
/**
|
||||
* An attribute was missing.
|
||||
*/
|
||||
public static final int MISSING_ATTRIBUTE = 3;
|
||||
|
||||
|
||||
/**
|
||||
* An unexpected attribute was encountered.
|
||||
*/
|
||||
public static final int UNEXPECTED_ATTRIBUTE = 4;
|
||||
|
||||
|
||||
/**
|
||||
* An attribute has an invalid value.
|
||||
*/
|
||||
public static final int ATTRIBUTE_WITH_INVALID_VALUE = 5;
|
||||
|
||||
|
||||
/**
|
||||
* A PCDATA element was missing.
|
||||
*/
|
||||
public static final int MISSING_PCDATA = 6;
|
||||
|
||||
|
||||
/**
|
||||
* An unexpected PCDATA element was encountered.
|
||||
*/
|
||||
public static final int UNEXPECTED_PCDATA = 7;
|
||||
|
||||
|
||||
/**
|
||||
* Another error than those specified in this class was encountered.
|
||||
*/
|
||||
public static final int MISC_ERROR = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Which error occurred.
|
||||
*/
|
||||
//private int errorType;
|
||||
|
||||
|
||||
/**
|
||||
* The name of the element where the exception occurred.
|
||||
*/
|
||||
private String elementName;
|
||||
|
||||
|
||||
/**
|
||||
* The name of the attribute where the exception occurred.
|
||||
*/
|
||||
private String attributeName;
|
||||
|
||||
|
||||
/**
|
||||
* The value of the attribute where the exception occurred.
|
||||
*/
|
||||
private String attributeValue;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new exception.
|
||||
*
|
||||
* @param errorType the type of validity error
|
||||
* @param systemID the system ID from where the data came
|
||||
* @param lineNr the line number in the XML data where the
|
||||
* exception occurred.
|
||||
* @param elementName the name of the offending element
|
||||
* @param attributeName the name of the offending attribute
|
||||
* @param attributeValue the value of the offending attribute
|
||||
* @param msg the message of the exception.
|
||||
*/
|
||||
public XMLValidationException(int errorType,
|
||||
String systemID,
|
||||
int lineNr,
|
||||
String elementName,
|
||||
String attributeName,
|
||||
String attributeValue,
|
||||
String msg)
|
||||
{
|
||||
super(systemID, lineNr, null,
|
||||
msg + ((elementName == null) ? "" : (", element=" + elementName))
|
||||
+ ((attributeName == null) ? ""
|
||||
: (", attribute=" + attributeName))
|
||||
+ ((attributeValue == null) ? ""
|
||||
: (", value='" + attributeValue + "'")),
|
||||
false);
|
||||
this.elementName = elementName;
|
||||
this.attributeName = attributeName;
|
||||
this.attributeValue = attributeValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.elementName = null;
|
||||
this.attributeName = null;
|
||||
this.attributeValue = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the element in which the validation is violated.
|
||||
* If there is no current element, null is returned.
|
||||
*/
|
||||
public String getElementName()
|
||||
{
|
||||
return this.elementName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the attribute in which the validation is violated.
|
||||
* If there is no current attribute, null is returned.
|
||||
*/
|
||||
public String getAttributeName()
|
||||
{
|
||||
return this.attributeName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of the attribute in which the validation is violated.
|
||||
* If there is no current attribute, null is returned.
|
||||
*/
|
||||
public String getAttributeValue()
|
||||
{
|
||||
return this.attributeValue;
|
||||
}
|
||||
|
||||
}
|
@ -1,631 +0,0 @@
|
||||
/* NonValidator.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/02/03 21:19:38 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
/**
|
||||
* XMLValidator implementation based on NonValidator (which implemented
|
||||
* IXMLValidator in the original NanoXML).
|
||||
* This implementation processes the DTD and handles entity definitions.
|
||||
* It does not do any validation itself.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
* @author processing.org
|
||||
*/
|
||||
public class XMLValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* The parameter entity resolver.
|
||||
*/
|
||||
protected XMLEntityResolver parameterEntityResolver;
|
||||
|
||||
|
||||
/**
|
||||
* Contains the default values for attributes for the different element
|
||||
* types.
|
||||
*/
|
||||
protected Hashtable<String, Properties> attributeDefaultValues;
|
||||
|
||||
|
||||
/**
|
||||
* The stack of elements to be processed.
|
||||
*/
|
||||
protected Stack<Properties> currentElements;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the "validator".
|
||||
*/
|
||||
public XMLValidator()
|
||||
{
|
||||
this.attributeDefaultValues = new Hashtable<String, Properties>();
|
||||
this.currentElements = new Stack<Properties>();
|
||||
this.parameterEntityResolver = new XMLEntityResolver();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.parameterEntityResolver = null;
|
||||
this.attributeDefaultValues.clear();
|
||||
this.attributeDefaultValues = null;
|
||||
this.currentElements.clear();
|
||||
this.currentElements = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the parameter entity resolver.
|
||||
*
|
||||
* @param resolver the entity resolver.
|
||||
*/
|
||||
public void setParameterEntityResolver(XMLEntityResolver resolver)
|
||||
{
|
||||
this.parameterEntityResolver = resolver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the parameter entity resolver.
|
||||
*
|
||||
* @return the entity resolver.
|
||||
*/
|
||||
public XMLEntityResolver getParameterEntityResolver()
|
||||
{
|
||||
return this.parameterEntityResolver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the DTD. The validator object is responsible for reading the
|
||||
* full DTD.
|
||||
*
|
||||
* @param publicID the public ID, which may be null.
|
||||
* @param reader the reader to read the DTD from.
|
||||
* @param entityResolver the entity resolver.
|
||||
* @param external true if the DTD is external.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* If something went wrong.
|
||||
*/
|
||||
public void parseDTD(String publicID,
|
||||
StdXMLReader reader,
|
||||
XMLEntityResolver entityResolver,
|
||||
boolean external)
|
||||
throws Exception
|
||||
{
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
int origLevel = reader.getStreamLevel();
|
||||
|
||||
for (;;) {
|
||||
String str = XMLUtil.read(reader, '%');
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
continue;
|
||||
} else if (ch == '<') {
|
||||
this.processElement(reader, entityResolver);
|
||||
} else if (ch == ']') {
|
||||
return; // end internal DTD
|
||||
} else {
|
||||
XMLUtil.errorInvalidInput(reader.getSystemID(),
|
||||
reader.getLineNr(),
|
||||
str);
|
||||
}
|
||||
|
||||
do {
|
||||
ch = reader.read();
|
||||
|
||||
if (external && (reader.getStreamLevel() < origLevel)) {
|
||||
reader.unread(ch);
|
||||
return; // end external DTD
|
||||
}
|
||||
} while ((ch == ' ') || (ch == '\t') || (ch == '\n')
|
||||
|| (ch == '\r'));
|
||||
|
||||
reader.unread(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes an element in the DTD.
|
||||
*
|
||||
* @param reader the reader to read data from.
|
||||
* @param entityResolver the entity resolver.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* If something went wrong.
|
||||
*/
|
||||
protected void processElement(StdXMLReader reader,
|
||||
XMLEntityResolver entityResolver)
|
||||
throws Exception
|
||||
{
|
||||
String str = XMLUtil.read(reader, '%');
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch != '!') {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
|
||||
switch (ch) {
|
||||
case '-':
|
||||
XMLUtil.skipComment(reader);
|
||||
break;
|
||||
|
||||
case '[':
|
||||
this.processConditionalSection(reader, entityResolver);
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
this.processEntity(reader, entityResolver);
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
this.processAttList(reader, entityResolver);
|
||||
break;
|
||||
|
||||
default:
|
||||
XMLUtil.skipTag(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a conditional section.
|
||||
*
|
||||
* @param reader the reader to read data from.
|
||||
* @param entityResolver the entity resolver.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* If something went wrong.
|
||||
*/
|
||||
protected void processConditionalSection(StdXMLReader reader,
|
||||
XMLEntityResolver entityResolver)
|
||||
throws Exception
|
||||
{
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
|
||||
String str = XMLUtil.read(reader, '%');
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch != 'I') {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
|
||||
switch (ch) {
|
||||
case 'G':
|
||||
this.processIgnoreSection(reader, entityResolver);
|
||||
return;
|
||||
|
||||
case 'N':
|
||||
break;
|
||||
|
||||
default:
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
if (! XMLUtil.checkLiteral(reader, "CLUDE")) {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
|
||||
if (ch != '[') {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
Reader subreader = new CDATAReader(reader);
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
|
||||
for (;;) {
|
||||
int ch2 = subreader.read();
|
||||
|
||||
if (ch2 < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
buf.append((char) ch2);
|
||||
}
|
||||
|
||||
subreader.close();
|
||||
reader.startNewStream(new StringReader(buf.toString()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes an ignore section.
|
||||
*
|
||||
* @param reader the reader to read data from.
|
||||
* @param entityResolver the entity resolver.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* If something went wrong.
|
||||
*/
|
||||
protected void processIgnoreSection(StdXMLReader reader,
|
||||
XMLEntityResolver entityResolver)
|
||||
throws Exception
|
||||
{
|
||||
if (! XMLUtil.checkLiteral(reader, "NORE")) {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
|
||||
String str = XMLUtil.read(reader, '%');
|
||||
char ch = str.charAt(0);
|
||||
|
||||
if (ch != '[') {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
Reader subreader = new CDATAReader(reader);
|
||||
subreader.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes an ATTLIST element.
|
||||
*
|
||||
* @param reader the reader to read data from.
|
||||
* @param entityResolver the entity resolver.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* If something went wrong.
|
||||
*/
|
||||
protected void processAttList(StdXMLReader reader,
|
||||
XMLEntityResolver entityResolver)
|
||||
throws Exception
|
||||
{
|
||||
if (! XMLUtil.checkLiteral(reader, "TTLIST")) {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
String str = XMLUtil.read(reader, '%');
|
||||
char ch = str.charAt(0);
|
||||
while (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
}
|
||||
reader.unread(ch);
|
||||
String elementName = XMLUtil.scanIdentifier(reader);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
while (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
}
|
||||
|
||||
Properties props = new Properties();
|
||||
|
||||
while (ch != '>') {
|
||||
reader.unread(ch);
|
||||
String attName = XMLUtil.scanIdentifier(reader);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
while (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
}
|
||||
|
||||
if (ch == '(') {
|
||||
while (ch != ')') {
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
while (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reader.unread(ch);
|
||||
XMLUtil.scanIdentifier(reader);
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
while (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
}
|
||||
|
||||
if (ch == '#') {
|
||||
str = XMLUtil.scanIdentifier(reader);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
|
||||
if (! str.equals("FIXED")) {
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
while (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
reader.unread(ch);
|
||||
}
|
||||
|
||||
String value = XMLUtil.scanString(reader, '%',
|
||||
this.parameterEntityResolver);
|
||||
props.put(attName, value);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
while (ch == '%') {
|
||||
XMLUtil.processEntity(str, reader,
|
||||
this.parameterEntityResolver);
|
||||
str = XMLUtil.read(reader, '%');
|
||||
ch = str.charAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (! props.isEmpty()) {
|
||||
this.attributeDefaultValues.put(elementName, props);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes an ENTITY element.
|
||||
*
|
||||
* @param reader the reader to read data from.
|
||||
* @param entityResolver the entity resolver.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* If something went wrong.
|
||||
*/
|
||||
protected void processEntity(StdXMLReader reader,
|
||||
XMLEntityResolver entityResolver)
|
||||
throws Exception
|
||||
{
|
||||
if (! XMLUtil.checkLiteral(reader, "NTITY")) {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
char ch = XMLUtil.readChar(reader, '\0');
|
||||
|
||||
if (ch == '%') {
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
entityResolver = this.parameterEntityResolver;
|
||||
} else {
|
||||
reader.unread(ch);
|
||||
}
|
||||
|
||||
String key = XMLUtil.scanIdentifier(reader);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
ch = XMLUtil.readChar(reader, '%');
|
||||
String systemID = null;
|
||||
String publicID = null;
|
||||
|
||||
switch (ch) {
|
||||
case 'P':
|
||||
if (! XMLUtil.checkLiteral(reader, "UBLIC")) {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
publicID = XMLUtil.scanString(reader, '%',
|
||||
this.parameterEntityResolver);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
systemID = XMLUtil.scanString(reader, '%',
|
||||
this.parameterEntityResolver);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
XMLUtil.readChar(reader, '%');
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
if (! XMLUtil.checkLiteral(reader, "YSTEM")) {
|
||||
XMLUtil.skipTag(reader);
|
||||
return;
|
||||
}
|
||||
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
systemID = XMLUtil.scanString(reader, '%',
|
||||
this.parameterEntityResolver);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
XMLUtil.readChar(reader, '%');
|
||||
break;
|
||||
|
||||
case '"':
|
||||
case '\'':
|
||||
reader.unread(ch);
|
||||
String value = XMLUtil.scanString(reader, '%',
|
||||
this.parameterEntityResolver);
|
||||
entityResolver.addInternalEntity(key, value);
|
||||
XMLUtil.skipWhitespace(reader, null);
|
||||
XMLUtil.readChar(reader, '%');
|
||||
break;
|
||||
|
||||
default:
|
||||
XMLUtil.skipTag(reader);
|
||||
}
|
||||
|
||||
if (systemID != null) {
|
||||
entityResolver.addExternalEntity(key, publicID, systemID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that an element has been started.
|
||||
*
|
||||
* @param name the name of the element.
|
||||
* @param systemId the system ID of the XML data of the element.
|
||||
* @param lineNr the line number in the XML data of the element.
|
||||
*/
|
||||
public void elementStarted(String name,
|
||||
String systemId,
|
||||
int lineNr)
|
||||
{
|
||||
Properties attribs
|
||||
= (Properties) this.attributeDefaultValues.get(name);
|
||||
|
||||
if (attribs == null) {
|
||||
attribs = new Properties();
|
||||
} else {
|
||||
attribs = (Properties) attribs.clone();
|
||||
}
|
||||
|
||||
this.currentElements.push(attribs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that the current element has ended.
|
||||
*
|
||||
* @param name the name of the element.
|
||||
* @param systemId the system ID of the XML data of the element.
|
||||
* @param lineNr the line number in the XML data of the element.
|
||||
*/
|
||||
public void elementEnded(String name,
|
||||
String systemId,
|
||||
int lineNr)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when the attributes of an XML element have been
|
||||
* processed.
|
||||
* If there are attributes with a default value which have not been
|
||||
* specified yet, they have to be put into <I>extraAttributes</I>.
|
||||
*
|
||||
* @param name the name of the element.
|
||||
* @param extraAttributes where to put extra attributes.
|
||||
* @param systemId the system ID of the XML data of the element.
|
||||
* @param lineNr the line number in the XML data of the element.
|
||||
*/
|
||||
public void elementAttributesProcessed(String name,
|
||||
Properties extraAttributes,
|
||||
String systemId,
|
||||
int lineNr)
|
||||
{
|
||||
Properties props = (Properties) this.currentElements.pop();
|
||||
Enumeration<?> en = props.keys();
|
||||
|
||||
while (en.hasMoreElements()) {
|
||||
String key = (String) en.nextElement();
|
||||
extraAttributes.put(key, props.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that an attribute has been added to the current element.
|
||||
*
|
||||
* @param key the name of the attribute.
|
||||
* @param value the value of the attribute.
|
||||
* @param systemId the system ID of the XML data of the element.
|
||||
* @param lineNr the line number in the XML data of the element.
|
||||
*/
|
||||
public void attributeAdded(String key,
|
||||
String value,
|
||||
String systemId,
|
||||
int lineNr)
|
||||
{
|
||||
Properties props = (Properties) this.currentElements.peek();
|
||||
|
||||
if (props.containsKey(key)) {
|
||||
props.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that a new #PCDATA element has been encountered.
|
||||
*
|
||||
* @param systemId the system ID of the XML data of the element.
|
||||
* @param lineNr the line number in the XML data of the element.
|
||||
*/
|
||||
public void PCDataAdded(String systemId,
|
||||
int lineNr)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
@ -1,307 +0,0 @@
|
||||
/* XMLWriter.java NanoXML/Java
|
||||
*
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2002/03/24 11:37:51 $
|
||||
* $Name: RELEASE_2_2_1 $
|
||||
*
|
||||
* This file is part of NanoXML 2 for Java.
|
||||
* Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from the
|
||||
* use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
package processing.xml;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
|
||||
/**
|
||||
* An XMLWriter writes XML data to a stream.
|
||||
*
|
||||
* @author Marc De Scheemaecker
|
||||
*/
|
||||
public class XMLWriter
|
||||
{
|
||||
|
||||
/**
|
||||
* Where to write the output to.
|
||||
*/
|
||||
private PrintWriter writer;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new XML writer.
|
||||
*
|
||||
* @param writer where to write the output to.
|
||||
*/
|
||||
public XMLWriter(Writer writer)
|
||||
{
|
||||
if (writer instanceof PrintWriter) {
|
||||
this.writer = (PrintWriter) writer;
|
||||
} else {
|
||||
this.writer = new PrintWriter(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new XML writer.
|
||||
*
|
||||
* @param stream where to write the output to.
|
||||
*/
|
||||
public XMLWriter(OutputStream stream)
|
||||
{
|
||||
this.writer = new PrintWriter(stream);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up the object when it's destroyed.
|
||||
*/
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
this.writer = null;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes an XML element.
|
||||
*
|
||||
* @param xml the non-null XML element to write.
|
||||
*/
|
||||
public void write(XMLElement xml)
|
||||
throws IOException
|
||||
{
|
||||
this.write(xml, false, 0, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes an XML element.
|
||||
*
|
||||
* @param xml the non-null XML element to write.
|
||||
* @param prettyPrint if spaces need to be inserted to make the output more
|
||||
* readable
|
||||
*/
|
||||
public void write(XMLElement xml,
|
||||
boolean prettyPrint)
|
||||
throws IOException
|
||||
{
|
||||
this.write(xml, prettyPrint, 0, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes an XML element.
|
||||
*
|
||||
* @param xml the non-null XML element to write.
|
||||
* @param prettyPrint if spaces need to be inserted to make the output more
|
||||
* readable
|
||||
* @param indent how many spaces to indent the element.
|
||||
*/
|
||||
public void write(XMLElement xml,
|
||||
boolean prettyPrint,
|
||||
int indent)
|
||||
throws IOException
|
||||
{
|
||||
this.write(xml, prettyPrint, indent, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes an XML element.
|
||||
*
|
||||
* @param xml the non-null XML element to write.
|
||||
* @param prettyPrint if spaces need to be inserted to make the output more
|
||||
* readable
|
||||
* @param indent how many spaces to indent the element.
|
||||
*/
|
||||
public void write(XMLElement xml,
|
||||
boolean prettyPrint,
|
||||
int indent,
|
||||
boolean collapseEmptyElements)
|
||||
throws IOException
|
||||
{
|
||||
if (prettyPrint) {
|
||||
for (int i = 0; i < indent; i++) {
|
||||
this.writer.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if (xml.getLocalName() == null) {
|
||||
if (xml.getContent() != null) {
|
||||
if (prettyPrint) {
|
||||
this.writeEncoded(xml.getContent().trim());
|
||||
writer.println();
|
||||
} else {
|
||||
this.writeEncoded(xml.getContent());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.writer.print('<');
|
||||
this.writer.print(xml.getName());
|
||||
Vector<String> nsprefixes = new Vector<String>();
|
||||
|
||||
if (xml.getNamespace() != null) {
|
||||
if (xml.getLocalName().equals(xml.getName())) {
|
||||
this.writer.print(" xmlns=\"" + xml.getNamespace() + '"');
|
||||
} else {
|
||||
String prefix = xml.getName();
|
||||
prefix = prefix.substring(0, prefix.indexOf(':'));
|
||||
nsprefixes.addElement(prefix);
|
||||
this.writer.print(" xmlns:" + prefix);
|
||||
this.writer.print("=\"" + xml.getNamespace() + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
Enumeration<?> en = xml.enumerateAttributeNames();
|
||||
|
||||
while (en.hasMoreElements()) {
|
||||
String key = (String) en.nextElement();
|
||||
int index = key.indexOf(':');
|
||||
|
||||
if (index >= 0) {
|
||||
String namespace = xml.getAttributeNamespace(key);
|
||||
|
||||
if (namespace != null) {
|
||||
String prefix = key.substring(0, index);
|
||||
|
||||
if (! nsprefixes.contains(prefix)) {
|
||||
this.writer.print(" xmlns:" + prefix);
|
||||
this.writer.print("=\"" + namespace + '"');
|
||||
nsprefixes.addElement(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
en = xml.enumerateAttributeNames();
|
||||
|
||||
while (en.hasMoreElements()) {
|
||||
String key = (String) en.nextElement();
|
||||
String value = xml.getAttribute(key, null);
|
||||
this.writer.print(" " + key + "=\"");
|
||||
this.writeEncoded(value);
|
||||
this.writer.print('"');
|
||||
}
|
||||
|
||||
if ((xml.getContent() != null)
|
||||
&& (xml.getContent().length() > 0)) {
|
||||
writer.print('>');
|
||||
this.writeEncoded(xml.getContent());
|
||||
writer.print("</" + xml.getName() + '>');
|
||||
|
||||
if (prettyPrint) {
|
||||
writer.println();
|
||||
}
|
||||
} else if (xml.hasChildren() || (! collapseEmptyElements)) {
|
||||
writer.print('>');
|
||||
|
||||
if (prettyPrint) {
|
||||
writer.println();
|
||||
}
|
||||
|
||||
en = xml.enumerateChildren();
|
||||
|
||||
while (en.hasMoreElements()) {
|
||||
XMLElement child = (XMLElement) en.nextElement();
|
||||
this.write(child, prettyPrint, indent + 4,
|
||||
collapseEmptyElements);
|
||||
}
|
||||
|
||||
if (prettyPrint) {
|
||||
for (int i = 0; i < indent; i++) {
|
||||
this.writer.print(' ');
|
||||
}
|
||||
}
|
||||
|
||||
this.writer.print("</" + xml.getName() + ">");
|
||||
|
||||
if (prettyPrint) {
|
||||
writer.println();
|
||||
}
|
||||
} else {
|
||||
this.writer.print("/>");
|
||||
|
||||
if (prettyPrint) {
|
||||
writer.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.writer.flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes a string encoding reserved characters.
|
||||
*
|
||||
* @param str the string to write.
|
||||
*/
|
||||
private void writeEncoded(String str)
|
||||
{
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char c = str.charAt(i);
|
||||
|
||||
switch (c) {
|
||||
case 0x0A:
|
||||
this.writer.print(c);
|
||||
break;
|
||||
|
||||
case '<':
|
||||
this.writer.print("<");
|
||||
break;
|
||||
|
||||
case '>':
|
||||
this.writer.print(">");
|
||||
break;
|
||||
|
||||
case '&':
|
||||
this.writer.print("&");
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
this.writer.print("'");
|
||||
break;
|
||||
|
||||
case '"':
|
||||
this.writer.print(""");
|
||||
break;
|
||||
|
||||
default:
|
||||
if ((c < ' ') || (c > 0x7E)) {
|
||||
this.writer.print("&#x");
|
||||
this.writer.print(Integer.toString(c, 16));
|
||||
this.writer.print(';');
|
||||
} else {
|
||||
this.writer.print(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
782
core/todo.txt
782
core/todo.txt
@ -1,782 +0,0 @@
|
||||
0179 core
|
||||
X screenWidth/Height instead of screenW/H
|
||||
X open up the pdf library more (philho)
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=1343
|
||||
X cache font information for the PDF library to improve setup time
|
||||
X when using createFont("xxxx.ttf"), should use textMode(SHAPE) with PDF
|
||||
X because ttf files will not be installed on the system when opening pdf
|
||||
X added error messages for users
|
||||
X bring back old-style textAscent()
|
||||
X needs to just quickly run characters d and p
|
||||
X only takes a couple ms, so no problem
|
||||
X pdf library
|
||||
X throw an error with the black boxes
|
||||
X throw an error if loading fonts from a file, and not using mode(SHAPE)
|
||||
X implement default font
|
||||
X this can be done to replace the exception handler in PGraphics
|
||||
o however it needs to be a legit font, so that it works w/ pdf
|
||||
o or maybe pdf just has its own default?
|
||||
X create characters on the fly when createFont() is used
|
||||
o memory leak problem with fonts in JAVA2D
|
||||
X can't get this to crash anymore
|
||||
o http://dev.processing.org/bugs/show_bug.cgi?id=1252
|
||||
|
||||
earlier
|
||||
X if no draw() method, and renderer is not displayable, then exit
|
||||
X static mode PDFs shouldn't just hang
|
||||
|
||||
|
||||
big ones
|
||||
_ ortho() behaving differently in P3D vs OPENGL
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=100
|
||||
_ shows a blank canvas
|
||||
_ (was only happening once b/c was drawing first in perspective)
|
||||
_ seems to be mapping to 0, 0 - width/2, height/2
|
||||
_ fix 3D > OrthoVsPerspective example once ortho works properly
|
||||
_ there's a depth problem in addition to the ortho weirdness
|
||||
_ modelx/y/z broken when aiming a camera
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1074
|
||||
_ opengl + resize window => window content garbled
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1360
|
||||
_ modify PVector to include better methods for chaining operations
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1415
|
||||
|
||||
quickies
|
||||
_ img.get() weirdness
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1198
|
||||
_ copy and blend scale when unnecessary
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1482
|
||||
_ add a limit to pushStyle() to catch unmatched sets?
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1368
|
||||
_ P2D transformation bug from ira
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1175
|
||||
_ resize not working in revision 5707
|
||||
_ camera() and perspective() were commented out in setSize()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1391
|
||||
_ chopping out triangles in OpenGL (though it's only 2D drawing)
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1359
|
||||
_ make sure that get() and set() (for pixels and subsets) work w/ loaded images
|
||||
_ make sure that get() and set() (for pixels and subsets) work w/ P2D
|
||||
_ make sure that get() and set() (for pixels and subsets) work w/ P3D
|
||||
_ consider adding skewX/Y
|
||||
_ do them as shearX/Y
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1448
|
||||
|
||||
_ add setOutput() method across other renderers?
|
||||
|
||||
_ opengl applet problems
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1364
|
||||
|
||||
_ method of threading but queue an event to be run when safe
|
||||
_ e.g. queueing items like mouse/keybd, but generic fxns
|
||||
|
||||
_ inconsistent anti-aliasing with OpenGL
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1413
|
||||
_ modify PVector to include better methods for chaining operations
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1415
|
||||
|
||||
_ selectInput() fails when called from within keyPressed()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1220
|
||||
|
||||
_ add java.io.Reader (and Writer?) to imports
|
||||
|
||||
_ changing vertex alpha in P3D in a QUAD_STRIP is ignored
|
||||
_ with smoothing, it works fine, but with PTriangle, it's not
|
||||
_ smooth() not working with applets an createGraphics(JAVA2D)
|
||||
_ but works fine with applications
|
||||
_ get() with OPENGL is grabbing the wrong coords
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1349
|
||||
|
||||
_ gl power of 2 with textures
|
||||
_ P3D also seems to have trouble w/ textures edges.. bad math?
|
||||
|
||||
_ No textures render with hint(ENABLE_ACCURATE_TEXTURES)
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=985
|
||||
_ need to remove the hint from the reference
|
||||
_ need to throw an error when it's used
|
||||
_ deal with issue of single pixel seam at the edge of textures
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=602
|
||||
_ should vertexTexture() divide by width/height or width-1/height-1?
|
||||
|
||||
looping/events
|
||||
_ key and mouse events delivered out of order
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=638
|
||||
_ key/mouse events have concurrency problems with noLoop()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1323
|
||||
_ need to say "no drawing inside mouse/key events w/ noLoop"
|
||||
_ redraw() doesn't work from within draw()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1363
|
||||
|
||||
_ make the index lookup use numbers up to 256?
|
||||
|
||||
_ decide whether to keep:
|
||||
_ public float textWidth(char[] chars, int start, int length)
|
||||
|
||||
_ textAlign(JUSTIFY) (with implementation)
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1309
|
||||
|
||||
_ Semitransparent rect drawn over image not rendered correctly
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1280
|
||||
|
||||
_ should map() actually constrain to the low and high values?
|
||||
|
||||
_ file chooser fails with opengl on linux
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1221
|
||||
|
||||
_ resizing opengl destroys context and textures
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1176
|
||||
_ what's the difference with ascent on loadFont vs. createFont?
|
||||
_ noCursor() doesn't work in present mode
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1177
|
||||
_ in P2D, two vertex() line calls with fill() causes duplicate output
|
||||
_ works fine in other renderers, has to do with tesselation
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1191
|
||||
_ extra triangles being seen in P2D
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1192
|
||||
_ noloop ref even says that redraw will be called on resize, make sure it is
|
||||
_ public PImage(java.awt.Image) sets format to RGB (but could be ARGB)
|
||||
|
||||
|
||||
[ features ]
|
||||
|
||||
_ add version of math functions that use doubles?
|
||||
_ what other methods should work with doubles? all math functions?
|
||||
_ seems like internal (mostly static) things, but not graphics api
|
||||
_ look into replacing nanoxml
|
||||
_ http://www.exampledepot.com/egs/javax.xml.parsers/pkg.html
|
||||
|
||||
|
||||
[ known problems ]
|
||||
|
||||
_ OPENGL sketches flicker w/ Vista when background() not used inside draw()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=930
|
||||
_ Disabling Aero scheme sometimes prevents the problem
|
||||
_ Updating graphics drivers may prevent the problem
|
||||
|
||||
[ need problem sketch ]
|
||||
|
||||
_ if too many errors come through during setup, app will terminate
|
||||
_ printStackTrace() throttles on osx and poops out
|
||||
_ seen especially on old mac laptops (slow ppc garbage)
|
||||
_ can this be confirmed properly?
|
||||
_ * this may just be an OutOfMemoryError happening
|
||||
|
||||
[ needs verification ]
|
||||
|
||||
_ Frame skipping with processor intensive applets using 1.6
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=766
|
||||
_ may be fixed, but not verified
|
||||
_ focus not coming through, ESC no longer working(?)
|
||||
|
||||
|
||||
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
createGraphics() and load/updatePixels() mess [1.0]
|
||||
_ text characters showing up as opaque rectangles in tga files
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=641
|
||||
_ solution is to implement alpha compositing across all of P3D
|
||||
_ http://en.wikipedia.org/wiki/Alpha_compositing
|
||||
_ text() not setting zbuffer in P3D because not fully opaque
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=696
|
||||
_ alpha not set on saveFrame, so can't be used in photoshop as a layer
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=general;action=display;num=1078441623
|
||||
_ when drawing into a JAVA2D surface, have to call loadPixels()
|
||||
_ to draw it later with P3D (or OPENGL prolly)
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1171574044
|
||||
_ an offscreen JAVA2D graphics needs loadPixels() before being drawn
|
||||
_ i.e. offscreen JAVA2D, then image() with OPENGL renderer as main
|
||||
_ needs to be marked as its cache needs an update, but not its pixels
|
||||
X begin/endPixels.. change has been made
|
||||
_ on PImage, sets a flag that marks it to be updated on next render
|
||||
_ for PImage, begin after an end is ignored, no pixels are re-loaded
|
||||
_ the "changed" bit gets turned off when the PImage is rendered
|
||||
_ for subclasses of PGraphics, the reload bit needs to be set on endFrame
|
||||
_ filter() checks to see if inside begin/endPixels, if so doesn't call
|
||||
o if line() is called inside beginpixels, call updatepixels?
|
||||
_ when NPE on line with pixels[], suggest user includes beginPixels
|
||||
_ need to test/straighten out load/update pixels
|
||||
_ loadPixels() and updatePixels() only need to be used when
|
||||
_ touching pixels[]. All other functions including get(), set(),
|
||||
_ filter(), etc shouldn't need them.
|
||||
_ image memory use.. how to handle lots of images
|
||||
_ need to figure out exactly how they should/can unload
|
||||
_ don't do a loadPixels unless an updatePixels has completed
|
||||
_ tho this won't affect anything, since either it's an image buffer
|
||||
_ or it's the PGraphics object, which does an updatePixels() immediately
|
||||
_ if (modified) don't loadPixels again, just ignore it
|
||||
_ make a note that updatePixels() only sets a flag in PImage
|
||||
_ (but not PGraphics, which does it immediately)
|
||||
o filter() doesn't need a loadPixels
|
||||
o but if you want to filter *and* mess w/ pixels (avoid double load)
|
||||
o then do loadPixels() /before/ filter, and updatePixels after messing
|
||||
o same will go for blend()
|
||||
_ make sure that filter, blend, copy, etc say that no loadPixels necessary
|
||||
|
||||
|
||||
rework some text/font code [1.0]
|
||||
_ text placement is ugly, seems like fractional metrics problem
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=866
|
||||
_ text(char c) with char 0 and undefined should print nothing
|
||||
_ perhaps also DEL or other nonprintables?
|
||||
_ book example 25-03
|
||||
_ text position is quantized in JAVA2D
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=806
|
||||
_ accessors inside PFont need a lot of work
|
||||
_ osx 10.5 (not 10.4) performing text width calculation differently
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=972
|
||||
_ Automatically use textMode(SCREEN) with text() when possible
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1020
|
||||
|
||||
|
||||
P2D, P3D, PPolygon [1.0]
|
||||
_ smoothing
|
||||
_ how to handle smoothing images in P3D even though it has no smoothing?
|
||||
_ noSmooth() in opengl should switch to nearest neighbor on textures/images
|
||||
_ same for P3D
|
||||
_ P3D smooshes the top row of pixels when drawing text (or images)
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=466
|
||||
_ textAlign(CENTER) with P3D and OPENGL produces messy result
|
||||
_ probably rounding error with the images
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=475
|
||||
X textures truly did get worse in P3D
|
||||
_ problem is that bilinear is turned on by default starting in 0124(?)
|
||||
X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1205171649
|
||||
_ when turning smoothing on, internal lines of shapes are visible
|
||||
_ add an edge flag when tesselating
|
||||
_ mind the opengl tesselation flags
|
||||
_ need to turn off smoothing for the interior of shapes
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=200
|
||||
_ Implement support for complex shapes when using P2D and P3D
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1053
|
||||
_ Implement support for complex shapes when using the OpenGL renderer
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=947
|
||||
_ in opengl mode, use its tesselator
|
||||
_ because the vertex calls can just come right back to regular vertex calls
|
||||
_ this way we can also implement breakShape() for opengl
|
||||
_ smooth in P3D has zbuffer glitches
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1000
|
||||
_ smoothing is slow
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1001
|
||||
_ textured sphere example needs to set normals
|
||||
_ also needs fix for last edge and the seam
|
||||
|
||||
|
||||
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
threading and exiting
|
||||
_ writing image file (missing a flush() call?) on exit() fails
|
||||
_ lots of zero length files
|
||||
_ saveFrame() at the end of a draw mode program is problematic
|
||||
_ app might exit before the file has finished writing to disk
|
||||
_ need to block other activity inside screenGrab until finished
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1081706752
|
||||
|
||||
_ for begin/endRecord, use a piggyback mechanism
|
||||
_ that way won't have to pass a PApplet around
|
||||
_ this has a big impact on the SVG library
|
||||
_ in fact, this maybe should be a library that does it
|
||||
_ so that the file size can be much smaller
|
||||
|
||||
_ STROKE_WEIGHT field in PGraphics3 is a disaster, because it's an int
|
||||
_ use the SW from vertex instead.. why set stroke in triangle vars at all?
|
||||
_ currently truncating to an int inside add_line_no_clip
|
||||
_ need to clean all this crap up
|
||||
|
||||
stop() mess
|
||||
_ double stop() called with noLoop()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1270
|
||||
_ stop() not getting called
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=183
|
||||
_ major problem for libraries
|
||||
_ and start() is supposedly called by the applet viewer
|
||||
_ http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html#start()
|
||||
_ need to track this stuff down a bit
|
||||
_ when closing a sketch via the close box, make sure stop() getting called
|
||||
X found a problem for release 0133
|
||||
_ test to see if it's working
|
||||
_ what's up with stop() vs exit()?
|
||||
_ need to get this straightened for p5 (i.e. bc has this problem)
|
||||
_ make sure the main() doesn't exit until the applet has finished
|
||||
_ i.e. problem with main calling itself multiple times in Alpheus
|
||||
_ if exit() (or stop) is called, then System.exit() gets called,
|
||||
_ even though the main() wants to keep going
|
||||
_ more chatter with this
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=131
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
CORE / PApplet
|
||||
|
||||
_ PApplet.main(new String[] { "classname" }) won't pass in args
|
||||
_ this means that no args are after passed to the class
|
||||
_ the fix would be to use the following as the call to main()
|
||||
_ PApplet.main(append(new String[] { "classname }, args));
|
||||
_ figure out why 1024x768 image takes 3.5 seconds to load
|
||||
_ would using a BufferedImage work better?
|
||||
_ is the image actually a BufferedImage so PixelGrabber is a waste?
|
||||
_ detect when using full screen
|
||||
_ and if so, remove decoration and don't bother with bg present frame
|
||||
_ frame.setUndecorated(true);
|
||||
_ frame.setLocation(0,0);
|
||||
_ size(screen.width,screen,height);
|
||||
_ this will help for exported applets that don't need 'present'
|
||||
_ check for what else inside PApplet should be static
|
||||
_ maybe catch RuntimeExceptions in the called sub-functions
|
||||
_ that way more stuff can be static w/o losing useful error handling
|
||||
_ (emitting errors when closest to source.. i.e. w/ the filename)
|
||||
o size() inside draw is missing a new call to cameraMode, etc
|
||||
_ fix param() to use a sketch.properties file when run as an app
|
||||
_ make this also be used in generating the html file
|
||||
_ test winding polygons in different directions
|
||||
_ test P3D lighting to see how it compares with native OpenGL
|
||||
_ ed's thread re: fullscreen strategies
|
||||
_ could add a new BApplet that uses BufferStrategy?
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Programs;action=display;num=1081335361;start=15
|
||||
_ size() has memory limitations (pitaru)
|
||||
_ catch OutOfMemoryError inside size() and let the user know
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1038847001
|
||||
_ loadBytes() needs optimization
|
||||
_ don't bother using a buffering stream, just handle internally. gah!
|
||||
_ remove some of the bloat, how can we make things more compact?
|
||||
_ i.e. if not using 3D, can leave out PGraphics3, PTriangle, PLine
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=127
|
||||
E4 _ add shuffle methods for arrays
|
||||
E4 _ http://dev.processing.org/bugs/show_bug.cgi?id=1462
|
||||
|
||||
|
||||
CORE / PApplet - main()
|
||||
|
||||
_ refactor PApplet.main() and Runner.startInternal() to remove duplication
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=245
|
||||
_ implement full screen mode.. this takes over the screen as best it can
|
||||
_ size(screen.width, screen.height, OPENGL);
|
||||
_ if size is screen.width and screen.height, does its best
|
||||
_ needs to get the size of the main screen
|
||||
_ this probably works but just needs to be tested
|
||||
_ exceptions in full screen mode will quit the app completely
|
||||
_ can't keep window open because things are hosed
|
||||
_ default is that full screen app doesn't cover multiple displays
|
||||
_ this is fine since opengl can't usually go across both
|
||||
_ but include an example for how to use full in gl
|
||||
_ ability to select monitor via preferences panel
|
||||
_ this applies to any applet that's run externally currently (verify)
|
||||
_ make it also work with anything that's run inside of p5 itself
|
||||
_ this means changing the frame creation code inside Runner
|
||||
_ check current present code with multiple monitors
|
||||
_ hitting cmd-q when an applet is running quits p5 (on macosx)
|
||||
_ but cmd-q when running externally is ok because it just quits
|
||||
_ is there a way to catch cmd-q when running a sketch?
|
||||
_ so that it could avoid quitting if the sketch hasn't been stopped
|
||||
_ or if the sketch window is foremost
|
||||
_ maybe a hack where a new menubar is added?
|
||||
_ --display not working on osx
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=531
|
||||
_ "Target VM failed to initialize" when using Present mode on Mac OS X
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1257
|
||||
|
||||
CORE / PFont and text()
|
||||
|
||||
_ improve font metrics
|
||||
_ http://java.sun.com/products/java-media/2D/reference/faqs/index.html#Q_How_do_I_obtain_font_metrics
|
||||
_ font encoding issues
|
||||
_ java seems to force straight windows encoding.. (problem for pi fonts)
|
||||
_ opentype/cff fonts don't work with live loading from the app
|
||||
_ many (all?) opentype fonts won't show up or aren't supported
|
||||
_ this may be only cff fonts that have trouble
|
||||
_ when encoding is not the standard encoding, problematic
|
||||
_ so sonata otf and sonata don't seem to have any chars at all
|
||||
_ text() with a z coordinate is now using translate, very slow
|
||||
X also puts up a weird error message about translate() in 2D mode
|
||||
_ make screen space fonts use get/set as well?
|
||||
_ too much to debug on their own
|
||||
_ unfortunately tint not set with setImpl, but...
|
||||
_ optimize textMode(MODEL) with textMode(SCREEN)
|
||||
_ in PGraphics and PGraphics3, check to see if matrix is within epsilon
|
||||
_ of one of the rotation matrices (many fewer steps)
|
||||
_ if identity, or just translate, or a rotate, make OBJECT into SCREEN
|
||||
_ not having kerning really blows
|
||||
_ could this be pulled from the OpenType font stuff?
|
||||
_ it could be placed at the end of the file
|
||||
_ not having fractional widths on small fonts really blows
|
||||
_ screen space text looks crappy
|
||||
_ working with vector fonts?
|
||||
_ need to be able to handle shapes within shapes (reverse winding)
|
||||
_ ftgl: main code is in FTVectoriser
|
||||
_ uses gluTessBeginContour and gluTessEndContour
|
||||
_ and then does 5 step sizes for each curveto
|
||||
|
||||
|
||||
CORE / PGraphics
|
||||
|
||||
_ stroke showing above fill when used with P3D
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1032
|
||||
_ strokeCap() and strokeJoin() for use with P2D, P3D and OPENGL
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=955
|
||||
_ y2 position of rectangles not same as y2 position of lines
|
||||
_ happens when the rectangle is flipped on the x or y axis
|
||||
_ probably a hack that draws the "last" point differently
|
||||
_ beginShape()
|
||||
_ better lockout inside beginShape() to keep other things from happening
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1022
|
||||
_ don't allow you to draw stroked items unless stroke() is called
|
||||
_ don't allow beginShape() if shape is already set
|
||||
_ (otherwise will cause some very strange errors)
|
||||
_ lines
|
||||
_ z value hack for lines is causing trouble for 2D
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1089737928;start=0
|
||||
_ rewrite line and stroke code, it's a buggy mess
|
||||
_ lines become 2 pixels thick after a 3D transform
|
||||
_ better handling of single-pixel special case
|
||||
_ flat_line_retribution is a hack, can go away
|
||||
_ fix-up the curve_init() and the rest to use matrices
|
||||
_ and not have ugly names (i.e. just g.curveDetail is good)
|
||||
_ ellipse scaling method isn't great
|
||||
_ toxi ellipses don't adapt properly with transformations
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=695
|
||||
_ weird ellipse bug with an alpha line in same image
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1083221401;start=0
|
||||
_ scaled ellipse showing up as a hexagon
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1083674213
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1084652597;start=0
|
||||
_ problem with the fill
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1077834735
|
||||
_ z values not set properly on ellipses?
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1068752615
|
||||
_ ellipses are just plain ugly
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1073409011;start=0
|
||||
|
||||
|
||||
CORE / PGraphics2D
|
||||
|
||||
_ should noSmooth() disable image smoothing consistently (does for Java2D)
|
||||
_ may need to bring back a hint, or use smoothMode() or smooth(IMAGES)
|
||||
_ lines are conflicting with type in 2D
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1094174791;start=0
|
||||
_ mgorbet stroke transparency problem
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1076383048;start=0
|
||||
_ make sure line() commands don't try to have a fill
|
||||
|
||||
|
||||
CORE / PGraphicsJava2D
|
||||
|
||||
_ some optimizations from zach
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=os_core_pde;action=display;num=1121670787
|
||||
_ textMode(SCREEN) needs to be faster
|
||||
_ need flat image implementation that takes no transforms
|
||||
_ along with 90, 180 and 270 versions of it as well
|
||||
_ tie to glDrawPixels.. how to clear matrix properly for that?
|
||||
_ maybe just disable this for JAVA2D cuz it's silly?
|
||||
_ catch sun.dc.pr.PRException?
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=104
|
||||
|
||||
|
||||
CORE / PGraphics3D
|
||||
|
||||
_ make thick lines draw perpendicular to the screen with P3D
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=956
|
||||
_ ewjordan suggests building the quad in screen coords after perspective
|
||||
_ improve hint(ENABLE_DEPTH_SORT) to use proper painter's algo
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=176
|
||||
_ polygon z-order depth sorting with alpha in opengl
|
||||
_ complete the implementation of hint() with proper implementation
|
||||
_ gl alpha on images when flipped around backwards
|
||||
_ will sorting based on depth help this? also ask simon for ideas
|
||||
_ need to merge sorting/drawing of lines and triangles
|
||||
_ lines will occlude tris and vice versa
|
||||
_ will need to split each based on the other
|
||||
_ sort issues will affect both
|
||||
_ images are losing pixels at the edges
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=102
|
||||
_ odd error with some pixels from images not drawing properly
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1115681453
|
||||
_ clipping not implemented
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1393
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1114184516
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1058491568;start=0
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1052313604;start=0
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1095170607;start=0
|
||||
_ things are flying into the camera and halting apps
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1042699742
|
||||
_ NullPointerException apparently when things way offscreen
|
||||
_ i.e. glyphrot with scale set to 4
|
||||
_ or at least that things get ridiculously slow
|
||||
_ clipping issues here.. but also something in scan converter
|
||||
_ not clipping areas from offscreen
|
||||
_ huge geometry slows things way down
|
||||
_ Stroking a rect() leaves off the upper right pixel
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=501
|
||||
_ box is not opaque
|
||||
_ problem is that lines are drawn second
|
||||
_ one pixel lines have no z value.. argh
|
||||
_ bug re: 3d depth sorting on lines
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1043894019;start=0
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1042004618
|
||||
_ translate(58, 48, 0);
|
||||
_ rotateY(0.5);
|
||||
_ box(40);
|
||||
|
||||
|
||||
CORE / PImage
|
||||
|
||||
_ accuracy problems make alpha channel go to FE with image.copy()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1420
|
||||
_ improve blend() accuracy when using ADD
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1008
|
||||
_ includes code for a slow but more accurate mode
|
||||
_ for a PGraphics2D, should its image cache object be the memoryimagesource?
|
||||
_ loading lots of images is a problem, describe how to unload
|
||||
_ is it possible? necessary to call delay(5) or something?
|
||||
_ don't grab pixels of java2d images unless asked
|
||||
_ this is the difference between a lot of loadPixels() and not
|
||||
_ so important to have it in before beta if that's the change
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=356
|
||||
_ add ability to control jpeg compression level with save() and saveFrame()
|
||||
_ or just write a better example for this one?
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=342
|
||||
_ when drawing an image, sense whether drawn rotated
|
||||
_ specifically, if drawn rotated 90 in either direction, or 180
|
||||
_ if just rotate/translate, then can use SCREEN_SPACE for fonts
|
||||
_ updatePixels() is slow to create a BufferedImage
|
||||
_ therefore the incomplete rendering
|
||||
_ could this be an issue fixed by a MediaTracker?
|
||||
|
||||
|
||||
CORE / PShape
|
||||
|
||||
_ we can do hit testing (at least in 2D) now that we rely on java2d
|
||||
_ for subclasses, make it easy to grab the structure of vertices
|
||||
_ actually, just use PShape internally and this will be easier
|
||||
_ for PShape, need to be able to set the origin (flash people)
|
||||
|
||||
|
||||
CORE / PShapeSVG
|
||||
|
||||
_ breaking up classes / figure out how to handle fonts subclass
|
||||
_ when using get(), reset the bounds for the objects
|
||||
_ otherwise it's always relative to the original document
|
||||
_ support for text (shouldn't be too bad, use createFont)
|
||||
_ implement text spans for svg output
|
||||
_ get entity tags working in xml library
|
||||
_ try enabling blending modes
|
||||
_ add better support for attributes buried in styles (support ai9/10/11)
|
||||
_ test what happens when transparency is used with gradient fill
|
||||
_ look into transformation issues... guessing this is probably wrong
|
||||
_ this may be what's throwing off the radial radius transform
|
||||
_ implement A and a (elliptical arcs)
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=996
|
||||
_ check for any other pieces of missing path api
|
||||
_ multiple sets of coordinates after a command not supported
|
||||
_ i.e. M with several coords means moveto followed by many linetos
|
||||
_ also curveto with multiple sets of points is ignored
|
||||
_ document somehow.. svg viewer will be discontinued
|
||||
_ http://www.adobe.com/svg/eol.html
|
||||
|
||||
|
||||
CORE / Mac OS X
|
||||
|
||||
_ set the application name to sketch name (not processing.core.PApplet)
|
||||
_ System.setProperty("com.apple.mrj.application.apple.menu.about.name", ...)
|
||||
_ -Xdock:name=<application name>
|
||||
_ -Xdock:icon=<path to icon file>
|
||||
_ first line of applets is missing on java 1.4+ on the mac
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=283
|
||||
_ cursor() broken in applets on macosx?
|
||||
_ or is it a java 1.4 versus java 1.3 problem?
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1081645955
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
LIBRARIES / PGraphicsOpenGL
|
||||
|
||||
_ switch to glWindowPos() instead of glRasterPos() silliness
|
||||
_ implement setImpl() instead of set() inside PGraphicsOpenGL
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=943
|
||||
_ use glCopyPixels() or glReadPixels() instead of copy() method
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=941
|
||||
_ implement a more efficient version of blend()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=942
|
||||
_ copy() does not update the screen with OpenGL
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=933
|
||||
_ set() requires updatePixels() with OpenGL
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=705
|
||||
_ first few frames of OpenGL sketches on Windows run slowly
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=874
|
||||
_ updatePixels wth OpenGL requires a lot of memory, need better texture update
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=610
|
||||
_ with opengl optimizations via call lists..
|
||||
_ watch out to make sure raw recording still works
|
||||
_ (optimizations will have to be disabled to some extent)
|
||||
_ look into using glu quadrics to handle shape geometries quickly
|
||||
_ optimizations to opengl
|
||||
_ disabling error reporting (what's taking it so long?)
|
||||
_ maybe use a hint() to enable it? or a getError() function?
|
||||
_ make cached display list of filled/non-filled ellipse.. rect.. etc
|
||||
_ these don't work when the vertex colors change, but..
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=657
|
||||
_ or maybe should be using vertex arrays?
|
||||
_ maybe break out a separate timage object in textures?
|
||||
_ needs tindex and tbuffer, both gl specific
|
||||
_ and for tpixels and twidth/theight, could use another PImage
|
||||
_ under assumption that most will just need an extra image object
|
||||
_ this could also be used by people eventually to control tex themselves
|
||||
_ or maybe call the object "texture"?
|
||||
_ in opengl lib, need beginTexture(PImage) and endTexture()
|
||||
_ this will be helpful to have access to the raw texture data
|
||||
_ that way it can be re-bound by itself, and ppl can write directly to it
|
||||
_ make textMode(SHAPE) faster in opengl
|
||||
_ cache for type should be per-renderer
|
||||
_ make the opengl textmode shape stuff get better and use PShape
|
||||
_ because opengl needs vectors, but also the image cache for textures
|
||||
_ opengl needs to shut itself down properly when closing applet
|
||||
_ otherwise can crash the whole browser
|
||||
_ get rid of some of the sillier IntBuffer stuff where it's not needed
|
||||
_ use the version of the prototypes that use an offset into the array
|
||||
_ need to test performance either way
|
||||
_ make a note about the anti-aliasing types in the faq
|
||||
_ polygon vs line etc.. may want to enable lines but disable polys
|
||||
_ invocationtargetexception in gl with aioobe:
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1115185737
|
||||
_ resolve ARGB versus RGBA versus just A issues for fonts
|
||||
_ make sure that current scenario works identically on mac
|
||||
_ if so, just switch the image code to expect alpha in the high bits
|
||||
_ fonts probably need to be RGBA, not ALPHA style images
|
||||
_ there's nothing really ALPHA about them?
|
||||
_ bit shifting in opengl, get down to 2 ops by using other image modes
|
||||
_ i.e. ABGR_EXT might allow for just two shifts instead of 4
|
||||
_ allow access to native pixel buffer in opengl and power of 2
|
||||
_ so that no need to copy/update everything
|
||||
_ how to handle gluTessVertex calls
|
||||
_ need to re-map through the regular "vertex" command,
|
||||
_ but that makes things messy because the glu calls make calls to vertex()
|
||||
_ and i don't want an additional "pathVertex()" function
|
||||
|
||||
|
||||
LIBRARIES / PGraphicsPDF
|
||||
|
||||
_ pdf not rendering unicode with beginRecord()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=727
|
||||
_ pdf sketches exiting before writing has finished
|
||||
_ people have to call exit() (so that dispose() is called in particular)
|
||||
_ when using noLoop() and the PDF renderer, sketch should exit gracefully
|
||||
_ because isDisplayable() returns false, there's no coming back from noLoop
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
LATER / Optimize
|
||||
|
||||
_ put a wrapper around InputStream returned by createInput
|
||||
_ that actually has some notion of the length of its input
|
||||
_ that way, methods could use the information when reading
|
||||
_ can loadBytes() be improved by querying file size first?
|
||||
_ background
|
||||
_ this would require a new version of createInput(), which would query
|
||||
_ the URL (or file) for an actual file size. the size is not always
|
||||
_ available, so it can't be relied upon, but would help in some cases.
|
||||
_ loadBytes() is used for images.. ouch
|
||||
_ might be worth doing a test to see if it actually would help at all
|
||||
_ before rewriting all of createInput()
|
||||
_ too much object creation in java2d
|
||||
_ causes inconsistency/hiccups as the gc runs?
|
||||
_ work through loadPixels in PImage, how consistent do we need to be?
|
||||
_ with get() and set() methods, this gets really tricky (too slow)
|
||||
_ could optimize by keeping a java image around, but table for later
|
||||
_ it's too significant a change, and not enough time to test
|
||||
|
||||
|
||||
LATER (post 1.0)
|
||||
|
||||
_ add getSketchSize() and getSketchRenderer()
|
||||
_ these could simply have the defaults at the outset
|
||||
_ opengl.jar with eclipse
|
||||
_ auto-extract native libs from opengl.jar
|
||||
_ to remove java.library.path problems (!)
|
||||
_ introduce calc()
|
||||
_ semantics of this are just too tricky, especially when it's not clear
|
||||
_ what's actually gained by the split--would have to do weird hacks
|
||||
_ to get the accum buffer, etc. to work anyway
|
||||
_ add some sort of unprojectX/Y/Z method (based on glu fxn)
|
||||
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1176483247
|
||||
_ implement method for lightweight components with processing applets
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=686
|
||||
_ Use getContextClassLoader() instead of Class.forName()
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=514
|
||||
_ add a timer(obj, "functionname", 45) method
|
||||
_ this can be used to schedule something to happen at a specific time
|
||||
_ or import the swing timer (for actionPerformed)
|
||||
X look into javascript timers to see how they work
|
||||
_ also add interval("functionname", 40)
|
||||
_ and thread("functionname");
|
||||
_ problem is that this will
|
||||
_ cmyk version of tiff encoder code?
|
||||
_ because 'color' isn't a real data type
|
||||
_ color(0, 0, 0, 0) produces black
|
||||
_ because color(0, 0, 0, 0) creates an int that is simply '0'
|
||||
_ although fill(0, 0, 0, 0) does the right thing
|
||||
_ also, rgb255 not getting set
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=382
|
||||
_ should fill(c) instead be fillColor(c)?
|
||||
_ should color(123, 4, 99) instead be createColor()?
|
||||
_ gray that's greater than the colorMode() can produce strange colors
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=432
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1083650609
|
||||
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1082481891
|
||||
_ add stroke() to type
|
||||
_ more for doing outlines-only and that sort of business
|
||||
_ gradients
|
||||
_ use gradients in a class for the svg lib for now
|
||||
_ don't add api to main p5 stuff (though maybe setPaint/noPaint api?)
|
||||
_ gradient-painted lines and fills
|
||||
_ java2d will do both line and fill, illusfarter only does fills
|
||||
_ gradients not supported in java2d
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=371
|
||||
_ illustrator export / rendering mode
|
||||
_ also postscript or pdf export?
|
||||
_ update illustrator code to use core api
|
||||
_ even if not actually working properly.. just in naming of things
|
||||
_ sorting of polygons/lines on simple painters algorithm
|
||||
_ better lighting model to show darkness at various depths
|
||||
_ maybe just ultra-high res bitmaps from gl
|
||||
_ bspline or nurbs (later, want to do the 3D/arch stuff correctly)
|
||||
_ cairo tesselation used:
|
||||
_ John Hobby, Practical Segment Intersection with Finite Precision Output.
|
||||
_ Computational Geometry Theory and Application, 13(4), 1999.
|
||||
_ http://citeseer.ist.psu.edu/hobby93practical.html
|
||||
_ color
|
||||
_ rounding errors on color conversion
|
||||
_ colorMode(RGB, 1.0); colorMode(255); println(red(color(0.5,1,1)));
|
||||
_ will return 127, instead of 128.
|
||||
_ curves
|
||||
_ non-homogenous coloring for curve vertices
|
||||
_ textMode(SHAPE) and textMode(IMAGE)?
|
||||
_ textMode(SCREEN) is out of its league?
|
||||
_ textMode(SHAPE) and hint(SMOOTHING) calls are really awkward
|
||||
_ maybe need to add properties to the size() command?
|
||||
_ or use a getXxxx() method?
|
||||
_ should beginRecord inherit settings from its parent renderer?
|
||||
_ textFont() is null on beginRecord
|
||||
_ same would be the case for strokeWeight, background, etc.
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=346
|
||||
_ repeating texture support
|
||||
_ exactly how should pixel filling work with single pixel strokes?
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=1025
|
||||
_ Writing XML files (clean up the API)
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=964
|
||||
_ consider bringing back text/image using cache/names
|
Reference in New Issue
Block a user