Merged branch
https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ProcessingFeedback
into Trunk.
Changes on branch:
........
r615153 | jeremias | 2008-01-25 10:07:21 +0100 (Fr, 25 Jan 2008) | 1 line
Created temporary branch for processing feedback.
........
r615155 | jeremias | 2008-01-25 10:11:59 +0100 (Fr, 25 Jan 2008) | 1 line
Initial commit of what I've built already for those who prefer code to minimalistic design docs.
........
r615278 | jeremias | 2008-01-25 18:25:00 +0100 (Fr, 25 Jan 2008) | 1 line
EventProducer interfaces now operational.
........
r615773 | jeremias | 2008-01-28 10:06:16 +0100 (Mo, 28 Jan 2008) | 1 line
No casting in client code when creating EventProducer instances.
........
r616242 | vhennebert | 2008-01-29 11:34:45 +0100 (Di, 29 Jan 2008) | 3 lines
Trick to avoid hard-coding the class name of EventProducer in the source file.
Feel free to revert if it's not ok.
........
r616900 | jeremias | 2008-01-30 21:59:31 +0100 (Mi, 30 Jan 2008) | 1 line
Generate event model XMLs in to the build directory: build/gensrc and build/test-gensrc (the latter is new and needs to be setup as source folder in your IDE!)
........
r616907 | jeremias | 2008-01-30 22:12:59 +0100 (Mi, 30 Jan 2008) | 1 line
Added an XMLResourceBundle that uses an XML file instead of a properties file to load the translations. The XML format is the same as for Cocoon's XMLResourceBundle.
........
r617097 | vhennebert | 2008-01-31 11:53:21 +0100 (Do, 31 Jan 2008) | 2 lines
Minor typo + slight improvement of Javadoc
........
r617176 | jeremias | 2008-01-31 19:14:19 +0100 (Do, 31 Jan 2008) | 5 lines
Renamed FopEvent to Event as suggested by Simon.
EventProducerCollectorTask.java now reads the EventSeverity from a doclet tag.
Added generation of EventProducer translations (including simple merging, no validation, yet)
EventFormatter introduced (only basic functionality, yet).
Added a simple EventListener implementation that uses EventFormatter to convert the events to human-readable, localized messages that are sent to the log via Commons Logging.
........
r617362 | jeremias | 2008-02-01 08:18:07 +0100 (Fr, 01 Feb 2008) | 1 line
Some remaining rename operations based on an earlier discussion.
........
r617413 | jeremias | 2008-02-01 10:46:26 +0100 (Fr, 01 Feb 2008) | 2 lines
Extracted formatting functionality into utility class AdvancedMessageFormat.java.
AdvancedMessageFormat.java now supports conditional sub-groups (delimited by []).
........
r618682 | jeremias | 2008-02-05 17:07:08 +0100 (Di, 05 Feb 2008) | 1 line
Add support for special object formatters (where toString() isn't good enough). ATM, it's hard-coded but could later be hooked into dynamic discovery if we have multiple such formatters. The SAX Locator is the only example for now.
........
r618686 | jeremias | 2008-02-05 17:12:56 +0100 (Di, 05 Feb 2008) | 3 lines
Hooked most of FONode into the new event mechanism. The FOUserAgent provides a DefaultEventBroadcaster instance.
If a producer method declares throwing an exception, the event is automatically marked FATAL and the dynamic proxy throws an exception right after notifying the listeners.
The exceptions are created through the EventExceptionManager. It currently contains only one exception factory for ValidationException. If we need more such factories it's better to register them dynamically. Right now, they're hard-coded.
........
r619313 | jeremias | 2008-02-07 10:14:15 +0100 (Do, 07 Feb 2008) | 1 line
Make sure no events are now just silently swallowed because after upgrading a user doesn't know about the event system.
........
r619314 | jeremias | 2008-02-07 10:14:46 +0100 (Do, 07 Feb 2008) | 1 line
Log what translation file is being written.
........
r619320 | jeremias | 2008-02-07 10:31:00 +0100 (Do, 07 Feb 2008) | 2 lines
FObj hooked into the event system.
Code reduction using a protected method on FONode to acquire a FOValidationEventProducer.
........
r619359 | jeremias | 2008-02-07 11:59:19 +0100 (Do, 07 Feb 2008) | 2 lines
Fop's QName now extends XGCommons' QName to initiate a transition.
Hooked PropertyList into the event mechanism.
........
r631252 | jeremias | 2008-02-26 16:24:33 +0100 (Di, 26 Feb 2008) | 1 line
Removed superfluous warning.
........
r631268 | jeremias | 2008-02-26 17:08:11 +0100 (Di, 26 Feb 2008) | 1 line
Deprecated two methods which are a problem for localization. Also helps finding additional spots to switch over to the event mechanism.
........
r633852 | jeremias | 2008-03-05 15:20:24 +0100 (Mi, 05 Mrz 2008) | 1 line
Add severity to formatting parameters.
........
r633855 | jeremias | 2008-03-05 15:21:57 +0100 (Mi, 05 Mrz 2008) | 4 lines
Added support for additional field styles:
{<fieldname>,if,<true-text>,<false-text>}
{<fieldname>,equals,<test-string>,<true-text>,<false-text>}
........
r633856 | jeremias | 2008-03-05 15:24:04 +0100 (Mi, 05 Mrz 2008) | 2 lines
Javadocs and TODOs.
EventListeners can change the event severity.
........
r633857 | jeremias | 2008-03-05 15:27:08 +0100 (Mi, 05 Mrz 2008) | 4 lines
Javadocs.
Moved out event listener registration into a CompositeEventListener.
Event broadcaster uses the events effective severity, not the initial value (for the case where listeners override the initial value).
Set up a special EventBroadCaster in the FOUserAgent that filters events through a class (FOValidationEventListenerProxy) that adjusts the event severity for relaxed validation.
........
r633858 | jeremias | 2008-03-05 15:32:07 +0100 (Mi, 05 Mrz 2008) | 2 lines
Instead of always decentrally checking whether strict validation is enabled or not, this is now done in a special event listener. The event producer method caller simply indicates whether it can recover from the error condition and continue.
Started switching to event production in table FOs.
........
r634027 | jeremias | 2008-03-05 21:58:35 +0100 (Mi, 05 Mrz 2008) | 7 lines
Moved AdvancedMessageFormat into its own package.
AdvancedMessageFormat got the following added functionality:
- Alternative conditional regions [ bla {field}] -> [ bla {field1}| even more bla {field2}]
- Functions: functions get access to the parameters and they can produce an object that is then formatted ({#gatherContextInfo})
- "if" and "equals" format moved to top-level classes and added by dynamic registration.
EventFormatter now supports includes in the form {{includeName}} so you can include other entries from the resource bundle for better reuse.
Some more events in table code.
........
r634031 | jeremias | 2008-03-05 22:05:22 +0100 (Mi, 05 Mrz 2008) | 1 line
SVN Props
........
r634208 | jeremias | 2008-03-06 11:26:52 +0100 (Do, 06 Mrz 2008) | 2 lines
Improved context gathering.
Moved GatherContextInfoFunction to an inner class of FONode to reduce visibilities.
........
r634209 | jeremias | 2008-03-06 11:28:14 +0100 (Do, 06 Mrz 2008) | 1 line
Made FOPException localizable.
........
r634280 | jeremias | 2008-03-06 15:38:30 +0100 (Do, 06 Mrz 2008) | 2 lines
ExceptionFactory is now dynamically registered.
More table warnings and errors switch to events.
........
r634326 | jeremias | 2008-03-06 17:08:16 +0100 (Do, 06 Mrz 2008) | 1 line
Remaining table FOs switched to events.
........
r634328 | jeremias | 2008-03-06 17:09:21 +0100 (Do, 06 Mrz 2008) | 1 line
Deprecated FOP's QName. Mixing with Commons' variant only produces problems.
........
r634381 | jeremias | 2008-03-06 20:12:57 +0100 (Do, 06 Mrz 2008) | 2 lines
Made the "invalidChild" event fully localizable by adding a "lookup" field for the optional rule to be displayed.
And a few switches to the event system.
........
r634692 | jeremias | 2008-03-07 15:31:43 +0100 (Fr, 07 Mrz 2008) | 1 line
More FO tree stuff switched to events.
........
r634712 | jeremias | 2008-03-07 16:19:21 +0100 (Fr, 07 Mrz 2008) | 1 line
Avoid an NPE that says nothing (ex. could happen if the message template is wrong).
........
r634738 | jeremias | 2008-03-07 17:38:21 +0100 (Fr, 07 Mrz 2008) | 2 lines
Non-FO children were not properly run through validation by FOTreeBuilder.
Unified the way that non-FO elements are validated. Some FOs were already fixed. I now fixed the rest, so foreign elements can occur everywhere.
........
r637833 | jeremias | 2008-03-17 12:01:41 +0100 (Mo, 17 Mrz 2008) | 1 line
Exception while cloning for RetrieveMarker to be handled by user as suggested by Andreas.
........
r637835 | jeremias | 2008-03-17 12:03:31 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a RuntimeException of no other Exception class is specified for an event as a fallback if someone just sets the event severity to FATAL.
........
r637838 | jeremias | 2008-03-17 12:06:10 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637859 | jeremias | 2008-03-17 13:35:26 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637938 | jeremias | 2008-03-17 16:19:51 +0100 (Mo, 17 Mrz 2008) | 1 line
Switched pagination package to events.
........
r637947 | jeremias | 2008-03-17 16:45:16 +0100 (Mo, 17 Mrz 2008) | 1 line
Removed unlocalizable validation helper methods.
........
r637952 | jeremias | 2008-03-17 16:59:02 +0100 (Mo, 17 Mrz 2008) | 1 line
Events on FOTreeBuilder.
........
r638299 | jeremias | 2008-03-18 11:09:30 +0100 (Di, 18 Mrz 2008) | 2 lines
Added support for java.util.text's ChoiceFormat to AdvancedMessageFormat.
Reuse the regexes as constants.
........
r638302 | jeremias | 2008-03-18 11:17:06 +0100 (Di, 18 Mrz 2008) | 1 line
Events for inline-level layout managers.
........
r638774 | jeremias | 2008-03-19 11:17:36 +0100 (Mi, 19 Mrz 2008) | 1 line
Added DEBUG level.
........
r638777 | jeremias | 2008-03-19 11:23:40 +0100 (Mi, 19 Mrz 2008) | 3 lines
Generalized FOValidationEventListenerProxy into FOPEventListenerProxy, the main proxy for FOP's own event manipulation proxy. Done because of support for overflow="hidden" vs. overflow="error-if-overflow".
Switched block-level layout managers to events.
Some cleanup along the way.
........
r639222 | jeremias | 2008-03-20 10:27:34 +0100 (Do, 20 Mrz 2008) | 2 lines
Some initial work for event forwarding from Batik.
Missing errors/exceptions converted to events in PageSequenceMaster.
........
r639270 | jeremias | 2008-03-20 13:50:35 +0100 (Do, 20 Mrz 2008) | 1 line
Removed DEBUG event severity again. Promoted constrained geometry adjustment event to INFO level as per discussion.
........
r640395 | jeremias | 2008-03-24 13:39:13 +0100 (Mo, 24 Mrz 2008) | 3 lines
Moved the creation of the fallback LoggingEventListener to FOUserAgent so event before the startDocument() SAX event arrive in the log.
Dynamic discovery of event models. Renderers and extensions can register renderer-specific event models.
Switched the most important parts of the renderers to events (maybe not everything is converted).
........
r640397 | jeremias | 2008-03-24 13:43:04 +0100 (Mo, 24 Mrz 2008) | 1 line
Remaining fixcrlfs. Xalan likes to mix CRLF and LF on Windows.
........
r640398 | jeremias | 2008-03-24 13:43:54 +0100 (Mo, 24 Mrz 2008) | 1 line
Ignore namespace declarations for property handling.
........
r640463 | jeremias | 2008-03-24 17:59:52 +0100 (Mo, 24 Mrz 2008) | 2 lines
Event in area package.
Exposed getUserAgent() in Renderer interface (was already public in AbstractRenderer).
........
r642972 | jeremias | 2008-03-31 14:18:39 +0200 (Mo, 31 Mrz 2008) | 1 line
Code restructured a bit.
........
r642975 | jeremias | 2008-03-31 14:24:07 +0200 (Mo, 31 Mrz 2008) | 2 lines
Plugged fonts package into the event subsystem. Note: I did not follow the same pattern as for the rest as the font package is to be considered FOP-external, so I just added a manual adapter for the FontEventListener. This demonstrates how an external library can be integrated with the event system.
Missing warning for unknown formatting objects added. Warning is not issued by the ElementMappingRegistry anymore but by FOTreeBuilder which has access to more context information.
........
r642997 | jeremias | 2008-03-31 16:10:08 +0200 (Mo, 31 Mrz 2008) | 1 line
Added an example to demonstrate how to write your own event listener and how to deal with the exceptions thrown in the process.
........
r642998 | jeremias | 2008-03-31 16:13:40 +0200 (Mo, 31 Mrz 2008) | 1 line
Removed unused method. Event formatting should not be part of the Event class. Use EventFormatter.format(Event) instead.
........
r643066 | jeremias | 2008-03-31 19:18:54 +0200 (Mo, 31 Mrz 2008) | 1 line
First part of the event subsystem documentation (DRAFT).
........
r643784 | jeremias | 2008-04-02 10:05:33 +0200 (Mi, 02 Apr 2008) | 1 line
More documentation.
........
r643785 | jeremias | 2008-04-02 10:06:38 +0200 (Mi, 02 Apr 2008) | 1 line
Some nits.
........
r643787 | jeremias | 2008-04-02 10:24:41 +0200 (Mi, 02 Apr 2008) | 1 line
Completed javadocs
........
r643824 | jeremias | 2008-04-02 12:00:30 +0200 (Mi, 02 Apr 2008) | 1 line
Javadocs.
........
r645847 | vhennebert | 2008-04-08 12:54:16 +0200 (Di, 08 Apr 2008) | 2 lines
Minor typo fixes
........
r645848 | vhennebert | 2008-04-08 12:58:30 +0200 (Di, 08 Apr 2008) | 2 lines
Another small typo fix
........
r647678 | jeremias | 2008-04-14 09:20:26 +0200 (Mo, 14 Apr 2008) | 1 line
Renamed *EventProducer.Factory.create() to *EventProducer.Provider.get() to better reflect what the method does (instances may be cached and reused).
........
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@647742 13f79535-47bb-0310-9956-ffa450edef68
пре 16 година Merged branch
https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ProcessingFeedback
into Trunk.
Changes on branch:
........
r615153 | jeremias | 2008-01-25 10:07:21 +0100 (Fr, 25 Jan 2008) | 1 line
Created temporary branch for processing feedback.
........
r615155 | jeremias | 2008-01-25 10:11:59 +0100 (Fr, 25 Jan 2008) | 1 line
Initial commit of what I've built already for those who prefer code to minimalistic design docs.
........
r615278 | jeremias | 2008-01-25 18:25:00 +0100 (Fr, 25 Jan 2008) | 1 line
EventProducer interfaces now operational.
........
r615773 | jeremias | 2008-01-28 10:06:16 +0100 (Mo, 28 Jan 2008) | 1 line
No casting in client code when creating EventProducer instances.
........
r616242 | vhennebert | 2008-01-29 11:34:45 +0100 (Di, 29 Jan 2008) | 3 lines
Trick to avoid hard-coding the class name of EventProducer in the source file.
Feel free to revert if it's not ok.
........
r616900 | jeremias | 2008-01-30 21:59:31 +0100 (Mi, 30 Jan 2008) | 1 line
Generate event model XMLs in to the build directory: build/gensrc and build/test-gensrc (the latter is new and needs to be setup as source folder in your IDE!)
........
r616907 | jeremias | 2008-01-30 22:12:59 +0100 (Mi, 30 Jan 2008) | 1 line
Added an XMLResourceBundle that uses an XML file instead of a properties file to load the translations. The XML format is the same as for Cocoon's XMLResourceBundle.
........
r617097 | vhennebert | 2008-01-31 11:53:21 +0100 (Do, 31 Jan 2008) | 2 lines
Minor typo + slight improvement of Javadoc
........
r617176 | jeremias | 2008-01-31 19:14:19 +0100 (Do, 31 Jan 2008) | 5 lines
Renamed FopEvent to Event as suggested by Simon.
EventProducerCollectorTask.java now reads the EventSeverity from a doclet tag.
Added generation of EventProducer translations (including simple merging, no validation, yet)
EventFormatter introduced (only basic functionality, yet).
Added a simple EventListener implementation that uses EventFormatter to convert the events to human-readable, localized messages that are sent to the log via Commons Logging.
........
r617362 | jeremias | 2008-02-01 08:18:07 +0100 (Fr, 01 Feb 2008) | 1 line
Some remaining rename operations based on an earlier discussion.
........
r617413 | jeremias | 2008-02-01 10:46:26 +0100 (Fr, 01 Feb 2008) | 2 lines
Extracted formatting functionality into utility class AdvancedMessageFormat.java.
AdvancedMessageFormat.java now supports conditional sub-groups (delimited by []).
........
r618682 | jeremias | 2008-02-05 17:07:08 +0100 (Di, 05 Feb 2008) | 1 line
Add support for special object formatters (where toString() isn't good enough). ATM, it's hard-coded but could later be hooked into dynamic discovery if we have multiple such formatters. The SAX Locator is the only example for now.
........
r618686 | jeremias | 2008-02-05 17:12:56 +0100 (Di, 05 Feb 2008) | 3 lines
Hooked most of FONode into the new event mechanism. The FOUserAgent provides a DefaultEventBroadcaster instance.
If a producer method declares throwing an exception, the event is automatically marked FATAL and the dynamic proxy throws an exception right after notifying the listeners.
The exceptions are created through the EventExceptionManager. It currently contains only one exception factory for ValidationException. If we need more such factories it's better to register them dynamically. Right now, they're hard-coded.
........
r619313 | jeremias | 2008-02-07 10:14:15 +0100 (Do, 07 Feb 2008) | 1 line
Make sure no events are now just silently swallowed because after upgrading a user doesn't know about the event system.
........
r619314 | jeremias | 2008-02-07 10:14:46 +0100 (Do, 07 Feb 2008) | 1 line
Log what translation file is being written.
........
r619320 | jeremias | 2008-02-07 10:31:00 +0100 (Do, 07 Feb 2008) | 2 lines
FObj hooked into the event system.
Code reduction using a protected method on FONode to acquire a FOValidationEventProducer.
........
r619359 | jeremias | 2008-02-07 11:59:19 +0100 (Do, 07 Feb 2008) | 2 lines
Fop's QName now extends XGCommons' QName to initiate a transition.
Hooked PropertyList into the event mechanism.
........
r631252 | jeremias | 2008-02-26 16:24:33 +0100 (Di, 26 Feb 2008) | 1 line
Removed superfluous warning.
........
r631268 | jeremias | 2008-02-26 17:08:11 +0100 (Di, 26 Feb 2008) | 1 line
Deprecated two methods which are a problem for localization. Also helps finding additional spots to switch over to the event mechanism.
........
r633852 | jeremias | 2008-03-05 15:20:24 +0100 (Mi, 05 Mrz 2008) | 1 line
Add severity to formatting parameters.
........
r633855 | jeremias | 2008-03-05 15:21:57 +0100 (Mi, 05 Mrz 2008) | 4 lines
Added support for additional field styles:
{<fieldname>,if,<true-text>,<false-text>}
{<fieldname>,equals,<test-string>,<true-text>,<false-text>}
........
r633856 | jeremias | 2008-03-05 15:24:04 +0100 (Mi, 05 Mrz 2008) | 2 lines
Javadocs and TODOs.
EventListeners can change the event severity.
........
r633857 | jeremias | 2008-03-05 15:27:08 +0100 (Mi, 05 Mrz 2008) | 4 lines
Javadocs.
Moved out event listener registration into a CompositeEventListener.
Event broadcaster uses the events effective severity, not the initial value (for the case where listeners override the initial value).
Set up a special EventBroadCaster in the FOUserAgent that filters events through a class (FOValidationEventListenerProxy) that adjusts the event severity for relaxed validation.
........
r633858 | jeremias | 2008-03-05 15:32:07 +0100 (Mi, 05 Mrz 2008) | 2 lines
Instead of always decentrally checking whether strict validation is enabled or not, this is now done in a special event listener. The event producer method caller simply indicates whether it can recover from the error condition and continue.
Started switching to event production in table FOs.
........
r634027 | jeremias | 2008-03-05 21:58:35 +0100 (Mi, 05 Mrz 2008) | 7 lines
Moved AdvancedMessageFormat into its own package.
AdvancedMessageFormat got the following added functionality:
- Alternative conditional regions [ bla {field}] -> [ bla {field1}| even more bla {field2}]
- Functions: functions get access to the parameters and they can produce an object that is then formatted ({#gatherContextInfo})
- "if" and "equals" format moved to top-level classes and added by dynamic registration.
EventFormatter now supports includes in the form {{includeName}} so you can include other entries from the resource bundle for better reuse.
Some more events in table code.
........
r634031 | jeremias | 2008-03-05 22:05:22 +0100 (Mi, 05 Mrz 2008) | 1 line
SVN Props
........
r634208 | jeremias | 2008-03-06 11:26:52 +0100 (Do, 06 Mrz 2008) | 2 lines
Improved context gathering.
Moved GatherContextInfoFunction to an inner class of FONode to reduce visibilities.
........
r634209 | jeremias | 2008-03-06 11:28:14 +0100 (Do, 06 Mrz 2008) | 1 line
Made FOPException localizable.
........
r634280 | jeremias | 2008-03-06 15:38:30 +0100 (Do, 06 Mrz 2008) | 2 lines
ExceptionFactory is now dynamically registered.
More table warnings and errors switch to events.
........
r634326 | jeremias | 2008-03-06 17:08:16 +0100 (Do, 06 Mrz 2008) | 1 line
Remaining table FOs switched to events.
........
r634328 | jeremias | 2008-03-06 17:09:21 +0100 (Do, 06 Mrz 2008) | 1 line
Deprecated FOP's QName. Mixing with Commons' variant only produces problems.
........
r634381 | jeremias | 2008-03-06 20:12:57 +0100 (Do, 06 Mrz 2008) | 2 lines
Made the "invalidChild" event fully localizable by adding a "lookup" field for the optional rule to be displayed.
And a few switches to the event system.
........
r634692 | jeremias | 2008-03-07 15:31:43 +0100 (Fr, 07 Mrz 2008) | 1 line
More FO tree stuff switched to events.
........
r634712 | jeremias | 2008-03-07 16:19:21 +0100 (Fr, 07 Mrz 2008) | 1 line
Avoid an NPE that says nothing (ex. could happen if the message template is wrong).
........
r634738 | jeremias | 2008-03-07 17:38:21 +0100 (Fr, 07 Mrz 2008) | 2 lines
Non-FO children were not properly run through validation by FOTreeBuilder.
Unified the way that non-FO elements are validated. Some FOs were already fixed. I now fixed the rest, so foreign elements can occur everywhere.
........
r637833 | jeremias | 2008-03-17 12:01:41 +0100 (Mo, 17 Mrz 2008) | 1 line
Exception while cloning for RetrieveMarker to be handled by user as suggested by Andreas.
........
r637835 | jeremias | 2008-03-17 12:03:31 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a RuntimeException of no other Exception class is specified for an event as a fallback if someone just sets the event severity to FATAL.
........
r637838 | jeremias | 2008-03-17 12:06:10 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637859 | jeremias | 2008-03-17 13:35:26 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637938 | jeremias | 2008-03-17 16:19:51 +0100 (Mo, 17 Mrz 2008) | 1 line
Switched pagination package to events.
........
r637947 | jeremias | 2008-03-17 16:45:16 +0100 (Mo, 17 Mrz 2008) | 1 line
Removed unlocalizable validation helper methods.
........
r637952 | jeremias | 2008-03-17 16:59:02 +0100 (Mo, 17 Mrz 2008) | 1 line
Events on FOTreeBuilder.
........
r638299 | jeremias | 2008-03-18 11:09:30 +0100 (Di, 18 Mrz 2008) | 2 lines
Added support for java.util.text's ChoiceFormat to AdvancedMessageFormat.
Reuse the regexes as constants.
........
r638302 | jeremias | 2008-03-18 11:17:06 +0100 (Di, 18 Mrz 2008) | 1 line
Events for inline-level layout managers.
........
r638774 | jeremias | 2008-03-19 11:17:36 +0100 (Mi, 19 Mrz 2008) | 1 line
Added DEBUG level.
........
r638777 | jeremias | 2008-03-19 11:23:40 +0100 (Mi, 19 Mrz 2008) | 3 lines
Generalized FOValidationEventListenerProxy into FOPEventListenerProxy, the main proxy for FOP's own event manipulation proxy. Done because of support for overflow="hidden" vs. overflow="error-if-overflow".
Switched block-level layout managers to events.
Some cleanup along the way.
........
r639222 | jeremias | 2008-03-20 10:27:34 +0100 (Do, 20 Mrz 2008) | 2 lines
Some initial work for event forwarding from Batik.
Missing errors/exceptions converted to events in PageSequenceMaster.
........
r639270 | jeremias | 2008-03-20 13:50:35 +0100 (Do, 20 Mrz 2008) | 1 line
Removed DEBUG event severity again. Promoted constrained geometry adjustment event to INFO level as per discussion.
........
r640395 | jeremias | 2008-03-24 13:39:13 +0100 (Mo, 24 Mrz 2008) | 3 lines
Moved the creation of the fallback LoggingEventListener to FOUserAgent so event before the startDocument() SAX event arrive in the log.
Dynamic discovery of event models. Renderers and extensions can register renderer-specific event models.
Switched the most important parts of the renderers to events (maybe not everything is converted).
........
r640397 | jeremias | 2008-03-24 13:43:04 +0100 (Mo, 24 Mrz 2008) | 1 line
Remaining fixcrlfs. Xalan likes to mix CRLF and LF on Windows.
........
r640398 | jeremias | 2008-03-24 13:43:54 +0100 (Mo, 24 Mrz 2008) | 1 line
Ignore namespace declarations for property handling.
........
r640463 | jeremias | 2008-03-24 17:59:52 +0100 (Mo, 24 Mrz 2008) | 2 lines
Event in area package.
Exposed getUserAgent() in Renderer interface (was already public in AbstractRenderer).
........
r642972 | jeremias | 2008-03-31 14:18:39 +0200 (Mo, 31 Mrz 2008) | 1 line
Code restructured a bit.
........
r642975 | jeremias | 2008-03-31 14:24:07 +0200 (Mo, 31 Mrz 2008) | 2 lines
Plugged fonts package into the event subsystem. Note: I did not follow the same pattern as for the rest as the font package is to be considered FOP-external, so I just added a manual adapter for the FontEventListener. This demonstrates how an external library can be integrated with the event system.
Missing warning for unknown formatting objects added. Warning is not issued by the ElementMappingRegistry anymore but by FOTreeBuilder which has access to more context information.
........
r642997 | jeremias | 2008-03-31 16:10:08 +0200 (Mo, 31 Mrz 2008) | 1 line
Added an example to demonstrate how to write your own event listener and how to deal with the exceptions thrown in the process.
........
r642998 | jeremias | 2008-03-31 16:13:40 +0200 (Mo, 31 Mrz 2008) | 1 line
Removed unused method. Event formatting should not be part of the Event class. Use EventFormatter.format(Event) instead.
........
r643066 | jeremias | 2008-03-31 19:18:54 +0200 (Mo, 31 Mrz 2008) | 1 line
First part of the event subsystem documentation (DRAFT).
........
r643784 | jeremias | 2008-04-02 10:05:33 +0200 (Mi, 02 Apr 2008) | 1 line
More documentation.
........
r643785 | jeremias | 2008-04-02 10:06:38 +0200 (Mi, 02 Apr 2008) | 1 line
Some nits.
........
r643787 | jeremias | 2008-04-02 10:24:41 +0200 (Mi, 02 Apr 2008) | 1 line
Completed javadocs
........
r643824 | jeremias | 2008-04-02 12:00:30 +0200 (Mi, 02 Apr 2008) | 1 line
Javadocs.
........
r645847 | vhennebert | 2008-04-08 12:54:16 +0200 (Di, 08 Apr 2008) | 2 lines
Minor typo fixes
........
r645848 | vhennebert | 2008-04-08 12:58:30 +0200 (Di, 08 Apr 2008) | 2 lines
Another small typo fix
........
r647678 | jeremias | 2008-04-14 09:20:26 +0200 (Mo, 14 Apr 2008) | 1 line
Renamed *EventProducer.Factory.create() to *EventProducer.Provider.get() to better reflect what the method does (instances may be cached and reused).
........
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@647742 13f79535-47bb-0310-9956-ffa450edef68
пре 16 година Merged branch
https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ProcessingFeedback
into Trunk.
Changes on branch:
........
r615153 | jeremias | 2008-01-25 10:07:21 +0100 (Fr, 25 Jan 2008) | 1 line
Created temporary branch for processing feedback.
........
r615155 | jeremias | 2008-01-25 10:11:59 +0100 (Fr, 25 Jan 2008) | 1 line
Initial commit of what I've built already for those who prefer code to minimalistic design docs.
........
r615278 | jeremias | 2008-01-25 18:25:00 +0100 (Fr, 25 Jan 2008) | 1 line
EventProducer interfaces now operational.
........
r615773 | jeremias | 2008-01-28 10:06:16 +0100 (Mo, 28 Jan 2008) | 1 line
No casting in client code when creating EventProducer instances.
........
r616242 | vhennebert | 2008-01-29 11:34:45 +0100 (Di, 29 Jan 2008) | 3 lines
Trick to avoid hard-coding the class name of EventProducer in the source file.
Feel free to revert if it's not ok.
........
r616900 | jeremias | 2008-01-30 21:59:31 +0100 (Mi, 30 Jan 2008) | 1 line
Generate event model XMLs in to the build directory: build/gensrc and build/test-gensrc (the latter is new and needs to be setup as source folder in your IDE!)
........
r616907 | jeremias | 2008-01-30 22:12:59 +0100 (Mi, 30 Jan 2008) | 1 line
Added an XMLResourceBundle that uses an XML file instead of a properties file to load the translations. The XML format is the same as for Cocoon's XMLResourceBundle.
........
r617097 | vhennebert | 2008-01-31 11:53:21 +0100 (Do, 31 Jan 2008) | 2 lines
Minor typo + slight improvement of Javadoc
........
r617176 | jeremias | 2008-01-31 19:14:19 +0100 (Do, 31 Jan 2008) | 5 lines
Renamed FopEvent to Event as suggested by Simon.
EventProducerCollectorTask.java now reads the EventSeverity from a doclet tag.
Added generation of EventProducer translations (including simple merging, no validation, yet)
EventFormatter introduced (only basic functionality, yet).
Added a simple EventListener implementation that uses EventFormatter to convert the events to human-readable, localized messages that are sent to the log via Commons Logging.
........
r617362 | jeremias | 2008-02-01 08:18:07 +0100 (Fr, 01 Feb 2008) | 1 line
Some remaining rename operations based on an earlier discussion.
........
r617413 | jeremias | 2008-02-01 10:46:26 +0100 (Fr, 01 Feb 2008) | 2 lines
Extracted formatting functionality into utility class AdvancedMessageFormat.java.
AdvancedMessageFormat.java now supports conditional sub-groups (delimited by []).
........
r618682 | jeremias | 2008-02-05 17:07:08 +0100 (Di, 05 Feb 2008) | 1 line
Add support for special object formatters (where toString() isn't good enough). ATM, it's hard-coded but could later be hooked into dynamic discovery if we have multiple such formatters. The SAX Locator is the only example for now.
........
r618686 | jeremias | 2008-02-05 17:12:56 +0100 (Di, 05 Feb 2008) | 3 lines
Hooked most of FONode into the new event mechanism. The FOUserAgent provides a DefaultEventBroadcaster instance.
If a producer method declares throwing an exception, the event is automatically marked FATAL and the dynamic proxy throws an exception right after notifying the listeners.
The exceptions are created through the EventExceptionManager. It currently contains only one exception factory for ValidationException. If we need more such factories it's better to register them dynamically. Right now, they're hard-coded.
........
r619313 | jeremias | 2008-02-07 10:14:15 +0100 (Do, 07 Feb 2008) | 1 line
Make sure no events are now just silently swallowed because after upgrading a user doesn't know about the event system.
........
r619314 | jeremias | 2008-02-07 10:14:46 +0100 (Do, 07 Feb 2008) | 1 line
Log what translation file is being written.
........
r619320 | jeremias | 2008-02-07 10:31:00 +0100 (Do, 07 Feb 2008) | 2 lines
FObj hooked into the event system.
Code reduction using a protected method on FONode to acquire a FOValidationEventProducer.
........
r619359 | jeremias | 2008-02-07 11:59:19 +0100 (Do, 07 Feb 2008) | 2 lines
Fop's QName now extends XGCommons' QName to initiate a transition.
Hooked PropertyList into the event mechanism.
........
r631252 | jeremias | 2008-02-26 16:24:33 +0100 (Di, 26 Feb 2008) | 1 line
Removed superfluous warning.
........
r631268 | jeremias | 2008-02-26 17:08:11 +0100 (Di, 26 Feb 2008) | 1 line
Deprecated two methods which are a problem for localization. Also helps finding additional spots to switch over to the event mechanism.
........
r633852 | jeremias | 2008-03-05 15:20:24 +0100 (Mi, 05 Mrz 2008) | 1 line
Add severity to formatting parameters.
........
r633855 | jeremias | 2008-03-05 15:21:57 +0100 (Mi, 05 Mrz 2008) | 4 lines
Added support for additional field styles:
{<fieldname>,if,<true-text>,<false-text>}
{<fieldname>,equals,<test-string>,<true-text>,<false-text>}
........
r633856 | jeremias | 2008-03-05 15:24:04 +0100 (Mi, 05 Mrz 2008) | 2 lines
Javadocs and TODOs.
EventListeners can change the event severity.
........
r633857 | jeremias | 2008-03-05 15:27:08 +0100 (Mi, 05 Mrz 2008) | 4 lines
Javadocs.
Moved out event listener registration into a CompositeEventListener.
Event broadcaster uses the events effective severity, not the initial value (for the case where listeners override the initial value).
Set up a special EventBroadCaster in the FOUserAgent that filters events through a class (FOValidationEventListenerProxy) that adjusts the event severity for relaxed validation.
........
r633858 | jeremias | 2008-03-05 15:32:07 +0100 (Mi, 05 Mrz 2008) | 2 lines
Instead of always decentrally checking whether strict validation is enabled or not, this is now done in a special event listener. The event producer method caller simply indicates whether it can recover from the error condition and continue.
Started switching to event production in table FOs.
........
r634027 | jeremias | 2008-03-05 21:58:35 +0100 (Mi, 05 Mrz 2008) | 7 lines
Moved AdvancedMessageFormat into its own package.
AdvancedMessageFormat got the following added functionality:
- Alternative conditional regions [ bla {field}] -> [ bla {field1}| even more bla {field2}]
- Functions: functions get access to the parameters and they can produce an object that is then formatted ({#gatherContextInfo})
- "if" and "equals" format moved to top-level classes and added by dynamic registration.
EventFormatter now supports includes in the form {{includeName}} so you can include other entries from the resource bundle for better reuse.
Some more events in table code.
........
r634031 | jeremias | 2008-03-05 22:05:22 +0100 (Mi, 05 Mrz 2008) | 1 line
SVN Props
........
r634208 | jeremias | 2008-03-06 11:26:52 +0100 (Do, 06 Mrz 2008) | 2 lines
Improved context gathering.
Moved GatherContextInfoFunction to an inner class of FONode to reduce visibilities.
........
r634209 | jeremias | 2008-03-06 11:28:14 +0100 (Do, 06 Mrz 2008) | 1 line
Made FOPException localizable.
........
r634280 | jeremias | 2008-03-06 15:38:30 +0100 (Do, 06 Mrz 2008) | 2 lines
ExceptionFactory is now dynamically registered.
More table warnings and errors switch to events.
........
r634326 | jeremias | 2008-03-06 17:08:16 +0100 (Do, 06 Mrz 2008) | 1 line
Remaining table FOs switched to events.
........
r634328 | jeremias | 2008-03-06 17:09:21 +0100 (Do, 06 Mrz 2008) | 1 line
Deprecated FOP's QName. Mixing with Commons' variant only produces problems.
........
r634381 | jeremias | 2008-03-06 20:12:57 +0100 (Do, 06 Mrz 2008) | 2 lines
Made the "invalidChild" event fully localizable by adding a "lookup" field for the optional rule to be displayed.
And a few switches to the event system.
........
r634692 | jeremias | 2008-03-07 15:31:43 +0100 (Fr, 07 Mrz 2008) | 1 line
More FO tree stuff switched to events.
........
r634712 | jeremias | 2008-03-07 16:19:21 +0100 (Fr, 07 Mrz 2008) | 1 line
Avoid an NPE that says nothing (ex. could happen if the message template is wrong).
........
r634738 | jeremias | 2008-03-07 17:38:21 +0100 (Fr, 07 Mrz 2008) | 2 lines
Non-FO children were not properly run through validation by FOTreeBuilder.
Unified the way that non-FO elements are validated. Some FOs were already fixed. I now fixed the rest, so foreign elements can occur everywhere.
........
r637833 | jeremias | 2008-03-17 12:01:41 +0100 (Mo, 17 Mrz 2008) | 1 line
Exception while cloning for RetrieveMarker to be handled by user as suggested by Andreas.
........
r637835 | jeremias | 2008-03-17 12:03:31 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a RuntimeException of no other Exception class is specified for an event as a fallback if someone just sets the event severity to FATAL.
........
r637838 | jeremias | 2008-03-17 12:06:10 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637859 | jeremias | 2008-03-17 13:35:26 +0100 (Mo, 17 Mrz 2008) | 1 line
Throw a meaningful exception when the property name is wrong. Otherwise, there will be an ArrayIndexOutOfBoundsException.
........
r637938 | jeremias | 2008-03-17 16:19:51 +0100 (Mo, 17 Mrz 2008) | 1 line
Switched pagination package to events.
........
r637947 | jeremias | 2008-03-17 16:45:16 +0100 (Mo, 17 Mrz 2008) | 1 line
Removed unlocalizable validation helper methods.
........
r637952 | jeremias | 2008-03-17 16:59:02 +0100 (Mo, 17 Mrz 2008) | 1 line
Events on FOTreeBuilder.
........
r638299 | jeremias | 2008-03-18 11:09:30 +0100 (Di, 18 Mrz 2008) | 2 lines
Added support for java.util.text's ChoiceFormat to AdvancedMessageFormat.
Reuse the regexes as constants.
........
r638302 | jeremias | 2008-03-18 11:17:06 +0100 (Di, 18 Mrz 2008) | 1 line
Events for inline-level layout managers.
........
r638774 | jeremias | 2008-03-19 11:17:36 +0100 (Mi, 19 Mrz 2008) | 1 line
Added DEBUG level.
........
r638777 | jeremias | 2008-03-19 11:23:40 +0100 (Mi, 19 Mrz 2008) | 3 lines
Generalized FOValidationEventListenerProxy into FOPEventListenerProxy, the main proxy for FOP's own event manipulation proxy. Done because of support for overflow="hidden" vs. overflow="error-if-overflow".
Switched block-level layout managers to events.
Some cleanup along the way.
........
r639222 | jeremias | 2008-03-20 10:27:34 +0100 (Do, 20 Mrz 2008) | 2 lines
Some initial work for event forwarding from Batik.
Missing errors/exceptions converted to events in PageSequenceMaster.
........
r639270 | jeremias | 2008-03-20 13:50:35 +0100 (Do, 20 Mrz 2008) | 1 line
Removed DEBUG event severity again. Promoted constrained geometry adjustment event to INFO level as per discussion.
........
r640395 | jeremias | 2008-03-24 13:39:13 +0100 (Mo, 24 Mrz 2008) | 3 lines
Moved the creation of the fallback LoggingEventListener to FOUserAgent so event before the startDocument() SAX event arrive in the log.
Dynamic discovery of event models. Renderers and extensions can register renderer-specific event models.
Switched the most important parts of the renderers to events (maybe not everything is converted).
........
r640397 | jeremias | 2008-03-24 13:43:04 +0100 (Mo, 24 Mrz 2008) | 1 line
Remaining fixcrlfs. Xalan likes to mix CRLF and LF on Windows.
........
r640398 | jeremias | 2008-03-24 13:43:54 +0100 (Mo, 24 Mrz 2008) | 1 line
Ignore namespace declarations for property handling.
........
r640463 | jeremias | 2008-03-24 17:59:52 +0100 (Mo, 24 Mrz 2008) | 2 lines
Event in area package.
Exposed getUserAgent() in Renderer interface (was already public in AbstractRenderer).
........
r642972 | jeremias | 2008-03-31 14:18:39 +0200 (Mo, 31 Mrz 2008) | 1 line
Code restructured a bit.
........
r642975 | jeremias | 2008-03-31 14:24:07 +0200 (Mo, 31 Mrz 2008) | 2 lines
Plugged fonts package into the event subsystem. Note: I did not follow the same pattern as for the rest as the font package is to be considered FOP-external, so I just added a manual adapter for the FontEventListener. This demonstrates how an external library can be integrated with the event system.
Missing warning for unknown formatting objects added. Warning is not issued by the ElementMappingRegistry anymore but by FOTreeBuilder which has access to more context information.
........
r642997 | jeremias | 2008-03-31 16:10:08 +0200 (Mo, 31 Mrz 2008) | 1 line
Added an example to demonstrate how to write your own event listener and how to deal with the exceptions thrown in the process.
........
r642998 | jeremias | 2008-03-31 16:13:40 +0200 (Mo, 31 Mrz 2008) | 1 line
Removed unused method. Event formatting should not be part of the Event class. Use EventFormatter.format(Event) instead.
........
r643066 | jeremias | 2008-03-31 19:18:54 +0200 (Mo, 31 Mrz 2008) | 1 line
First part of the event subsystem documentation (DRAFT).
........
r643784 | jeremias | 2008-04-02 10:05:33 +0200 (Mi, 02 Apr 2008) | 1 line
More documentation.
........
r643785 | jeremias | 2008-04-02 10:06:38 +0200 (Mi, 02 Apr 2008) | 1 line
Some nits.
........
r643787 | jeremias | 2008-04-02 10:24:41 +0200 (Mi, 02 Apr 2008) | 1 line
Completed javadocs
........
r643824 | jeremias | 2008-04-02 12:00:30 +0200 (Mi, 02 Apr 2008) | 1 line
Javadocs.
........
r645847 | vhennebert | 2008-04-08 12:54:16 +0200 (Di, 08 Apr 2008) | 2 lines
Minor typo fixes
........
r645848 | vhennebert | 2008-04-08 12:58:30 +0200 (Di, 08 Apr 2008) | 2 lines
Another small typo fix
........
r647678 | jeremias | 2008-04-14 09:20:26 +0200 (Mo, 14 Apr 2008) | 1 line
Renamed *EventProducer.Factory.create() to *EventProducer.Provider.get() to better reflect what the method does (instances may be cached and reused).
........
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@647742 13f79535-47bb-0310-9956-ffa450edef68
пре 16 година |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290 |
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /* $Id$ */
-
- package org.apache.fop.render.pcl;
-
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.image.BufferedImage;
- import java.awt.image.ColorModel;
- import java.awt.image.DataBuffer;
- import java.awt.image.DataBufferByte;
- import java.awt.image.DataBufferInt;
- import java.awt.image.DirectColorModel;
- import java.awt.image.IndexColorModel;
- import java.awt.image.MultiPixelPackedSampleModel;
- import java.awt.image.Raster;
- import java.awt.image.RenderedImage;
- import java.awt.image.SinglePixelPackedSampleModel;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.text.DecimalFormat;
- import java.text.DecimalFormatSymbols;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.Locale;
- import java.util.Map;
-
- import org.apache.commons.io.IOUtils;
- import org.apache.commons.io.output.ByteArrayOutputStream;
- import org.apache.commons.io.output.CountingOutputStream;
-
- import org.apache.xmlgraphics.util.UnitConv;
-
- import org.apache.fop.fonts.Typeface;
- import org.apache.fop.render.pcl.fonts.PCLFontReader;
- import org.apache.fop.render.pcl.fonts.PCLSoftFontManager;
- import org.apache.fop.util.bitmap.BitmapImageUtil;
- import org.apache.fop.util.bitmap.DitherUtil;
-
- /**
- * This class provides methods for generating PCL print files.
- */
- public class PCLGenerator {
-
- private static final String US_ASCII = "US-ASCII";
-
- private static final String ISO_8859_1 = "ISO-8859-1";
-
- /** The ESC (escape) character */
- public static final char ESC = '\033';
-
- /** A list of all supported resolutions in PCL (values in dpi) */
- public static final int[] PCL_RESOLUTIONS = new int[] {75, 100, 150, 200, 300, 600};
-
- private final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
- private final DecimalFormat df2 = new DecimalFormat("0.##", symbols);
- private final DecimalFormat df4 = new DecimalFormat("0.####", symbols);
-
- private final CountingOutputStream out;
- protected Map<Typeface, PCLFontReader> fontReaderMap = new HashMap<Typeface, PCLFontReader>();
- protected Map<PCLSoftFontManager, Map<Typeface, Long>> fontManagerMap
- = new LinkedHashMap<PCLSoftFontManager, Map<Typeface, Long>>();
-
- private boolean currentSourceTransparency = true;
- private boolean currentPatternTransparency = true;
-
- private int maxBitmapResolution = PCL_RESOLUTIONS[PCL_RESOLUTIONS.length - 1];
- private float ditheringQuality = 0.5f;
-
- /**
- * true: Standard PCL shades are used (poor quality). false: user-defined pattern are used
- * to create custom dither patterns for better grayscale quality.
- */
- private static final boolean USE_PCL_SHADES = false;
-
- /**
- * Main constructor.
- * @param out the OutputStream to write the PCL stream to
- */
- public PCLGenerator(OutputStream out) {
- this.out = new CountingOutputStream(out);
- }
-
- /**
- * Main constructor.
- * @param out the OutputStream to write the PCL stream to
- * @param maxResolution the maximum resolution to encode bitmap images at
- */
- public PCLGenerator(OutputStream out, int maxResolution) {
- this(out);
- boolean found = false;
- for (int pclResolutions : PCL_RESOLUTIONS) {
- if (pclResolutions == maxResolution) {
- found = true;
- break;
- }
- }
- if (!found) {
- throw new IllegalArgumentException("Illegal value for maximum resolution!");
- }
- this.maxBitmapResolution = maxResolution;
- }
-
- public void addFont(PCLSoftFontManager sfManager, Typeface font) {
- if (!fontManagerMap.containsKey(sfManager)) {
- fontManagerMap.put(sfManager, new LinkedHashMap<Typeface, Long>());
- }
- Map<Typeface, Long> fonts = fontManagerMap.get(sfManager);
- if (!fonts.containsKey(font)) {
- fonts.put(font, out.getByteCount());
- }
- }
-
- /** @return the OutputStream that this generator writes to */
- public OutputStream getOutputStream() {
- return this.out;
- }
-
- /**
- * Returns the currently active text encoding.
- * @return the text encoding
- */
- public String getTextEncoding() {
- return ISO_8859_1;
- }
-
- /** @return the maximum resolution to encode bitmap images at */
- public int getMaximumBitmapResolution() {
- return this.maxBitmapResolution;
- }
-
- /**
- * Writes a PCL escape command to the output stream.
- * @param cmd the command (without the ESCAPE character)
- * @throws IOException In case of an I/O error
- */
- public void writeCommand(String cmd) throws IOException {
- out.write(27); //ESC
- out.write(cmd.getBytes(US_ASCII));
- }
-
- /**
- * Writes raw text (in ISO-8859-1 encoding) to the output stream.
- * @param s the text
- * @throws IOException In case of an I/O error
- */
- public void writeText(String s) throws IOException {
- out.write(s.getBytes(ISO_8859_1));
- }
-
- /**
- * Writes raw bytes to the output stream
- * @param bytes The bytes
- * @throws IOException In case of an I/O error
- */
- public void writeBytes(byte[] bytes) throws IOException {
- out.write(bytes);
- }
-
- /**
- * Formats a double value with two decimal positions for PCL output.
- *
- * @param value value to format
- * @return the formatted value
- */
- public final String formatDouble2(double value) {
- return df2.format(value);
- }
-
- /**
- * Formats a double value with four decimal positions for PCL output.
- *
- * @param value value to format
- * @return the formatted value
- */
- public final String formatDouble4(double value) {
- return df4.format(value);
- }
-
- /**
- * Sends the universal end of language command (UEL).
- * @throws IOException In case of an I/O error
- */
- public void universalEndOfLanguage() throws IOException {
- writeCommand("%-12345X");
- }
-
- /**
- * Resets the printer and restores the user default environment.
- * @throws IOException In case of an I/O error
- */
- public void resetPrinter() throws IOException {
- writeCommand("E");
- }
-
- /**
- * Sends the job separation command.
- * @throws IOException In case of an I/O error
- */
- public void separateJobs() throws IOException {
- writeCommand("&l1T");
- }
-
- /**
- * Sends the form feed character.
- * @throws IOException In case of an I/O error
- */
- public void formFeed() throws IOException {
- out.write(12); //=OC ("FF", Form feed)
- }
-
- /**
- * Sets the unit of measure.
- * @param value the resolution value (units per inch)
- * @throws IOException In case of an I/O error
- */
- public void setUnitOfMeasure(int value) throws IOException {
- writeCommand("&u" + value + "D");
- }
-
- /**
- * Sets the raster graphics resolution
- * @param value the resolution value (units per inch)
- * @throws IOException In case of an I/O error
- */
- public void setRasterGraphicsResolution(int value) throws IOException {
- writeCommand("*t" + value + "R");
- }
-
- /**
- * Selects the page size.
- * @param selector the integer representing the page size
- * @throws IOException In case of an I/O error
- */
- public void selectPageSize(int selector) throws IOException {
- writeCommand("&l" + selector + "A");
- }
-
- /**
- * Selects the paper source. The parameter is usually printer-specific. Usually, "1" is the
- * default tray, "2" is the manual paper feed, "3" is the manual envelope feed, "4" is the
- * "lower" tray and "7" is "auto-select". Consult the technical reference for your printer
- * for all available values.
- * @param selector the integer representing the paper source/tray
- * @throws IOException In case of an I/O error
- */
- public void selectPaperSource(int selector) throws IOException {
- writeCommand("&l" + selector + "H");
- }
-
- /**
- * Selects the output bin. The parameter is usually printer-specific. Usually, "1" is the
- * default output bin (upper bin) and "2" is the lower (rear) output bin. Some printers
- * may support additional output bins. Consult the technical reference for your printer
- * for all available values.
- * @param selector the integer representing the output bin
- * @throws IOException In case of an I/O error
- */
- public void selectOutputBin(int selector) throws IOException {
- writeCommand("&l" + selector + "G");
- }
-
- /**
- * Selects the duplexing mode for the page.
- * The parameter is usually printer-specific.
- * "0" means Simplex,
- * "1" means Duplex, Long-Edge Binding,
- * "2" means Duplex, Short-Edge Binding.
- * @param selector the integer representing the duplexing mode of the page
- * @throws IOException In case of an I/O error
- */
- public void selectDuplexMode(int selector) throws IOException {
- writeCommand("&l" + selector + "S");
- }
-
- /**
- * Clears the horizontal margins.
- * @throws IOException In case of an I/O error
- */
- public void clearHorizontalMargins() throws IOException {
- writeCommand("9");
- }
-
- /**
- * The Top Margin command designates the number of lines between
- * the top of the logical page and the top of the text area.
- * @param numberOfLines the number of lines (See PCL specification for details)
- * @throws IOException In case of an I/O error
- */
- public void setTopMargin(int numberOfLines) throws IOException {
- writeCommand("&l" + numberOfLines + "E");
- }
-
- /**
- * The Text Length command can be used to define the bottom border. See the PCL specification
- * for details.
- * @param numberOfLines the number of lines
- * @throws IOException In case of an I/O error
- */
- public void setTextLength(int numberOfLines) throws IOException {
- writeCommand("&l" + numberOfLines + "F");
- }
-
- /**
- * Sets the Vertical Motion Index (VMI).
- * @param value the VMI value
- * @throws IOException In case of an I/O error
- */
- public void setVMI(double value) throws IOException {
- writeCommand("&l" + formatDouble4(value) + "C");
- }
-
- /**
- * Sets the cursor to a new absolute coordinate.
- * @param x the X coordinate (in millipoints)
- * @param y the Y coordinate (in millipoints)
- * @throws IOException In case of an I/O error
- */
- public void setCursorPos(double x, double y) throws IOException {
- if (x < 0) {
- //A negative x value will result in a relative movement so go to "0" first.
- //But this will most probably have no effect anyway since you can't paint to the left
- //of the logical page
- writeCommand("&a0h" + formatDouble2(x / 100) + "h" + formatDouble2(y / 100) + "V");
- } else {
- writeCommand("&a" + formatDouble2(x / 100) + "h" + formatDouble2(y / 100) + "V");
- }
- }
-
- /**
- * Pushes the current cursor position on a stack (stack size: max 20 entries)
- * @throws IOException In case of an I/O error
- */
- public void pushCursorPos() throws IOException {
- writeCommand("&f0S");
- }
-
- /**
- * Pops the current cursor position from the stack.
- * @throws IOException In case of an I/O error
- */
- public void popCursorPos() throws IOException {
- writeCommand("&f1S");
- }
-
- /**
- * Changes the current print direction while maintaining the current cursor position.
- * @param rotate the rotation angle (counterclockwise), one of 0, 90, 180 and 270.
- * @throws IOException In case of an I/O error
- */
- public void changePrintDirection(int rotate) throws IOException {
- writeCommand("&a" + rotate + "P");
- }
-
- /**
- * Enters the HP GL/2 mode.
- * @param restorePreviousHPGL2Cursor true if the previous HP GL/2 pen position should be
- * restored, false if the current position is maintained
- * @throws IOException In case of an I/O error
- */
- public void enterHPGL2Mode(boolean restorePreviousHPGL2Cursor) throws IOException {
- if (restorePreviousHPGL2Cursor) {
- writeCommand("%0B");
- } else {
- writeCommand("%1B");
- }
- }
-
- /**
- * Enters the PCL mode.
- * @param restorePreviousPCLCursor true if the previous PCL cursor position should be restored,
- * false if the current position is maintained
- * @throws IOException In case of an I/O error
- */
- public void enterPCLMode(boolean restorePreviousPCLCursor) throws IOException {
- if (restorePreviousPCLCursor) {
- writeCommand("%0A");
- } else {
- writeCommand("%1A");
- }
- }
-
- /**
- * Generate a filled rectangle at the current cursor position.
- *
- * @param w the width in millipoints
- * @param h the height in millipoints
- * @param col the fill color
- * @throws IOException In case of an I/O error
- */
- protected void fillRect(int w, int h, Color col, boolean colorEnabled) throws IOException {
- if ((w == 0) || (h == 0)) {
- return;
- }
- if (h < 0) {
- h *= -1;
- } else {
- //y += h;
- }
- setPatternTransparencyMode(false);
- if (USE_PCL_SHADES
- || Color.black.equals(col)
- || Color.white.equals(col)) {
- writeCommand("*c" + formatDouble4(w / 100.0) + "h"
- + formatDouble4(h / 100.0) + "V");
- int lineshade = convertToPCLShade(col);
- writeCommand("*c" + lineshade + "G");
- writeCommand("*c2P"); //Shaded fill
- } else {
- if (colorEnabled) {
- selectColor(col);
- writeCommand("*c" + formatDouble4(w / 100.0) + "h"
- + formatDouble4(h / 100.0) + "V");
- writeCommand("*c0P"); //Solid fill
- } else {
- defineGrayscalePattern(col, 32, DitherUtil.DITHER_MATRIX_4X4);
-
- writeCommand("*c" + formatDouble4(w / 100.0) + "h"
- + formatDouble4(h / 100.0) + "V");
- writeCommand("*c32G");
- writeCommand("*c4P"); //User-defined pattern
- }
- }
- // Reset pattern transparency mode.
- setPatternTransparencyMode(true);
- }
-
- /**
- * Generates a user-defined pattern for a dithering pattern matching the grayscale value
- * of the color given.
- * @param col the color to create the pattern for
- * @param patternID the pattern ID to use
- * @param ditherMatrixSize the size of the Bayer dither matrix to use (4 or 8 supported)
- * @throws IOException In case of an I/O error
- */
- public void defineGrayscalePattern(Color col, int patternID, int ditherMatrixSize)
- throws IOException {
- ByteArrayOutputStream baout = new ByteArrayOutputStream();
- DataOutputStream data = new DataOutputStream(baout);
- data.writeByte(0); //Format
- data.writeByte(0); //Continuation
- data.writeByte(1); //Pixel Encoding
- data.writeByte(0); //Reserved
- data.writeShort(8); //Width in Pixels
- data.writeShort(8); //Height in Pixels
- //data.writeShort(600); //X Resolution (didn't manage to get that to work)
- //data.writeShort(600); //Y Resolution
- int gray255 = convertToGray(col.getRed(), col.getGreen(), col.getBlue());
-
- byte[] pattern;
- if (ditherMatrixSize == 8) {
- pattern = DitherUtil.getBayerDither(DitherUtil.DITHER_MATRIX_8X8, gray255, false);
- } else {
- //Since a 4x4 pattern did not work, the 4x4 pattern is applied 4 times to an
- //8x8 pattern. Maybe this could be changed to use an 8x8 bayer dither pattern
- //instead of the 4x4 one.
- pattern = DitherUtil.getBayerDither(DitherUtil.DITHER_MATRIX_4X4, gray255, true);
- }
- data.write(pattern);
- if ((baout.size() % 2) > 0) {
- baout.write(0);
- }
- writeCommand("*c" + patternID + "G");
- writeCommand("*c" + baout.size() + "W");
- baout.writeTo(this.out);
- IOUtils.closeQuietly(data);
- IOUtils.closeQuietly(baout);
- writeCommand("*c4Q"); //temporary pattern
- }
-
- /**
- * Sets the source transparency mode.
- * @param transparent true if transparent, false for opaque
- * @throws IOException In case of an I/O error
- */
- public void setSourceTransparencyMode(boolean transparent) throws IOException {
- setTransparencyMode(transparent, currentPatternTransparency);
- }
-
- /**
- * Sets the pattern transparency mode.
- * @param transparent true if transparent, false for opaque
- * @throws IOException In case of an I/O error
- */
- public void setPatternTransparencyMode(boolean transparent) throws IOException {
- setTransparencyMode(currentSourceTransparency, transparent);
- }
-
- /**
- * Sets the transparency modes.
- * @param source source transparency: true if transparent, false for opaque
- * @param pattern pattern transparency: true if transparent, false for opaque
- * @throws IOException In case of an I/O error
- */
- public void setTransparencyMode(boolean source, boolean pattern) throws IOException {
- if (source != currentSourceTransparency && pattern != currentPatternTransparency) {
- writeCommand("*v" + (source ? '0' : '1') + "n" + (pattern ? '0' : '1') + "O");
- } else if (source != currentSourceTransparency) {
- writeCommand("*v" + (source ? '0' : '1') + "N");
- } else if (pattern != currentPatternTransparency) {
- writeCommand("*v" + (pattern ? '0' : '1') + "O");
- }
- this.currentSourceTransparency = source;
- this.currentPatternTransparency = pattern;
- }
-
- /**
- * Convert an RGB color value to a grayscale from 0 to 100.
- * @param r the red component
- * @param g the green component
- * @param b the blue component
- * @return the gray value
- */
- public final int convertToGray(int r, int g, int b) {
- return BitmapImageUtil.convertToGray(r, g, b);
- }
-
- /**
- * Convert a Color value to a PCL shade value (0-100).
- * @param col the color
- * @return the PCL shade value (100=black)
- */
- public final int convertToPCLShade(Color col) {
- float gray = convertToGray(col.getRed(), col.getGreen(), col.getBlue()) / 255f;
- return (int)(100 - (gray * 100f));
- }
-
- /**
- * Selects the current grayscale color (the given color is converted to grayscales).
- * @param col the color
- * @throws IOException In case of an I/O error
- */
- public void selectGrayscale(Color col) throws IOException {
- if (Color.black.equals(col)) {
- selectCurrentPattern(0, 0); //black
- } else if (Color.white.equals(col)) {
- selectCurrentPattern(0, 1); //white
- } else {
- if (USE_PCL_SHADES) {
- selectCurrentPattern(convertToPCLShade(col), 2);
- } else {
- defineGrayscalePattern(col, 32, DitherUtil.DITHER_MATRIX_4X4);
- selectCurrentPattern(32, 4);
- }
- }
- }
-
- public void selectColor(Color col) throws IOException {
- writeCommand("*v6W");
- writeBytes(new byte[]{0, 1, 1, 8, 8, 8});
- writeCommand(String.format("*v%da%db%dc0I", col.getRed(), col.getGreen(), col.getBlue()));
- writeCommand("*v0S");
- }
-
- /**
- * Select the current pattern
- * @param patternID the pattern ID (<ESC>*c#G command)
- * @param pattern the pattern type (<ESC>*v#T command)
- * @throws IOException In case of an I/O error
- */
- public void selectCurrentPattern(int patternID, int pattern) throws IOException {
- if (pattern > 1) {
- writeCommand("*c" + patternID + "G");
- }
- writeCommand("*v" + pattern + "T");
- }
-
- /**
- * Sets the dithering quality used when encoding gray or color images. If not explicitely
- * set a medium setting (0.5f) is used.
- * @param quality a quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)
- */
- public void setDitheringQuality(float quality) {
- quality = Math.min(Math.max(0f, quality), 1.0f);
- this.ditheringQuality = quality;
- }
-
- /**
- * Returns the dithering quality used when encoding gray or color images.
- * @return the quality setting between 0.0f (worst/fastest) and 1.0f (best/slowest)
- */
- public float getDitheringQuality() {
- return this.ditheringQuality;
- }
-
- /**
- * Indicates whether an image is a monochrome (b/w) image.
- * @param img the image
- * @return true if it's a monochrome image
- */
- public static boolean isMonochromeImage(RenderedImage img) {
- return BitmapImageUtil.isMonochromeImage(img);
- }
-
- /**
- * Indicates whether an image is a grayscale image.
- * @param img the image
- * @return true if it's a grayscale image
- */
- public static boolean isGrayscaleImage(RenderedImage img) {
- return BitmapImageUtil.isGrayscaleImage(img);
- }
-
- private static int jaiAvailable = -1; //no synchronization necessary, not critical
-
- /**
- * Indicates whether JAI is available. JAI has shown to be reliable when dithering a
- * grayscale or color image to monochrome bitmaps (1-bit).
- * @return true if JAI is available
- */
- public static boolean isJAIAvailable() {
- if (jaiAvailable < 0) {
- try {
- String clName = "javax.media.jai.JAI";
- Class.forName(clName);
- jaiAvailable = 1;
- } catch (ClassNotFoundException cnfe) {
- jaiAvailable = 0;
- }
- }
- return (jaiAvailable > 0);
- }
-
- private int calculatePCLResolution(int resolution) {
- return calculatePCLResolution(resolution, false);
- }
-
- /**
- * Calculates the ideal PCL resolution for a given resolution.
- * @param resolution the input resolution
- * @param increased true if you want to go to a higher resolution, for example if you
- * convert grayscale or color images to monochrome images so dithering has
- * a chance to generate better quality.
- * @return the resulting PCL resolution (one of 75, 100, 150, 200, 300, 600)
- */
- private int calculatePCLResolution(int resolution, boolean increased) {
- int choice = -1;
- for (int i = PCL_RESOLUTIONS.length - 2; i >= 0; i--) {
- if (resolution > PCL_RESOLUTIONS[i]) {
- int idx = i + 1;
- if (idx < PCL_RESOLUTIONS.length - 2) {
- idx += increased ? 2 : 0;
- } else if (idx < PCL_RESOLUTIONS.length - 1) {
- idx += increased ? 1 : 0;
- }
- choice = idx;
- break;
- //return PCL_RESOLUTIONS[idx];
- }
- }
- if (choice < 0) {
- choice = (increased ? 2 : 0);
- }
- while (choice > 0 && PCL_RESOLUTIONS[choice] > getMaximumBitmapResolution()) {
- choice--;
- }
- return PCL_RESOLUTIONS[choice];
- }
-
- private boolean isValidPCLResolution(int resolution) {
- return resolution == calculatePCLResolution(resolution);
- }
-
- //Threshold table to convert an alpha channel (8-bit) into a clip mask (1-bit)
- private static final byte[] THRESHOLD_TABLE = new byte[256];
- static { // Initialize the arrays
- for (int i = 0; i < 256; i++) {
- THRESHOLD_TABLE[i] = (byte) ((i < 240) ? 255 : 0);
- }
- }
-
- /* not used
- private RenderedImage getMask(RenderedImage img, Dimension targetDim) {
- ColorModel cm = img.getColorModel();
- if (cm.hasAlpha()) {
- BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(),
- BufferedImage.TYPE_BYTE_GRAY);
- Raster raster = img.getData();
- GraphicsUtil.copyBand(raster, cm.getNumColorComponents(), alpha.getRaster(), 0);
-
- BufferedImageOp op1 = new LookupOp(new ByteLookupTable(0, THRESHOLD_TABLE), null);
- BufferedImage alphat = op1.filter(alpha, null);
-
- BufferedImage mask;
- if (true) {
- mask = new BufferedImage(targetDim.width, targetDim.height,
- BufferedImage.TYPE_BYTE_BINARY);
- } else {
- byte[] arr = {(byte)0, (byte)0xff};
- ColorModel colorModel = new IndexColorModel(1, 2, arr, arr, arr);
- WritableRaster wraster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE,
- targetDim.width, targetDim.height, 1, 1, null);
- mask = new BufferedImage(colorModel, wraster, false, null);
- }
-
- Graphics2D g2d = mask.createGraphics();
- try {
- AffineTransform at = new AffineTransform();
- double sx = targetDim.getWidth() / img.getWidth();
- double sy = targetDim.getHeight() / img.getHeight();
- at.scale(sx, sy);
- g2d.drawRenderedImage(alphat, at);
- } finally {
- g2d.dispose();
- }
- return mask;
- } else {
- return null;
- }
- }
- */
-
- /**
- * Paint a bitmap at the current cursor position. The bitmap is converted to a monochrome
- * (1-bit) bitmap image.
- * @param img the bitmap image
- * @param targetDim the target Dimention (in mpt)
- * @param sourceTransparency true if the background should not be erased
- * @throws IOException In case of an I/O error
- */
- public void paintBitmap(RenderedImage img, Dimension targetDim, boolean sourceTransparency,
- PCLRenderingUtil pclUtil) throws IOException {
- final boolean printerSupportsColor = pclUtil.isColorEnabled();
- boolean monochrome = isMonochromeImage(img);
- double targetHResolution = img.getWidth() / UnitConv.mpt2in(targetDim.width);
- double targetVResolution = img.getHeight() / UnitConv.mpt2in(targetDim.height);
- double targetResolution = Math.max(targetHResolution, targetVResolution);
- int resolution = (int)Math.round(targetResolution);
- int effResolution = calculatePCLResolution(resolution, !(printerSupportsColor && !monochrome));
- Dimension orgDim = new Dimension(img.getWidth(), img.getHeight());
- Dimension effDim;
- if (targetResolution == effResolution) {
- effDim = orgDim; //avoid scaling side-effects
- } else {
- effDim = new Dimension(
- (int)Math.ceil(UnitConv.mpt2px(targetDim.width, effResolution)),
- (int)Math.ceil(UnitConv.mpt2px(targetDim.height, effResolution)));
- }
- boolean scaled = !orgDim.equals(effDim);
- if (!monochrome) {
- if (printerSupportsColor) {
- RenderedImage effImg = img;
- if (scaled) {
- effImg = BitmapImageUtil.convertTosRGB(img, effDim);
- }
- selectCurrentPattern(0, 0); //Solid black
- renderImageAsColor(effImg, effResolution);
- } else {
- //Transparency mask disabled. Doesn't work reliably
- /*
- final boolean transparencyDisabled = true;
- RenderedImage mask = (transparencyDisabled ? null : getMask(img, effDim));
- if (mask != null) {
- pushCursorPos();
- selectCurrentPattern(0, 1); //Solid white
- setTransparencyMode(true, true);
- paintMonochromeBitmap(mask, effResolution);
- popCursorPos();
- }
- */
-
- RenderedImage red = BitmapImageUtil.convertToMonochrome(
- img, effDim, this.ditheringQuality);
- selectCurrentPattern(0, 0); //Solid black
- setTransparencyMode(sourceTransparency /*|| mask != null*/, true);
- paintMonochromeBitmap(red, effResolution);
- }
- } else {
- RenderedImage effImg = img;
- if (scaled) {
- effImg = BitmapImageUtil.convertToMonochrome(img, effDim);
- }
- setSourceTransparencyMode(sourceTransparency);
- selectCurrentPattern(0, 0); //Solid black
- paintMonochromeBitmap(effImg, effResolution);
- }
- }
-
- private int toGray(int rgb) {
- // see http://www.jguru.com/faq/view.jsp?EID=221919
- double greyVal = 0.072169d * (rgb & 0xff);
- rgb >>= 8;
- greyVal += 0.715160d * (rgb & 0xff);
- rgb >>= 8;
- greyVal += 0.212671d * (rgb & 0xff);
- return (int)greyVal;
- }
-
- private void renderImageAsColor(RenderedImage imgOrg, int dpi) throws IOException {
- BufferedImage img = new BufferedImage(imgOrg.getWidth(), imgOrg.getHeight(), BufferedImage.TYPE_INT_RGB);
- Graphics2D g = img.createGraphics();
- g.setColor(Color.WHITE);
- g.fillRect(0, 0, imgOrg.getWidth(), imgOrg.getHeight());
- g.drawImage((Image) imgOrg, 0, 0, null);
-
- if (!isValidPCLResolution(dpi)) {
- throw new IllegalArgumentException("Invalid PCL resolution: " + dpi);
- }
- int w = img.getWidth();
- ColorModel cm = img.getColorModel();
- if (cm instanceof DirectColorModel) {
- writeCommand("*v6W"); // ImagingMode
- out.write(new byte[]{0, 3, 0, 8, 8, 8});
- } else {
- IndexColorModel icm = (IndexColorModel)cm;
- writeCommand("*v6W"); // ImagingMode
- out.write(new byte[]{0, 1, (byte)icm.getMapSize(), 8, 8, 8});
-
- byte[] reds = new byte[256];
- byte[] greens = new byte[256];
- byte[] blues = new byte[256];
-
- icm.getReds(reds);
- icm.getGreens(greens);
- icm.getBlues(blues);
- for (int i = 0; i < icm.getMapSize(); i++) {
- writeCommand("*v" + (reds[i] & 0xFF) + "A"); //ColorComponentOne
- writeCommand("*v" + (greens[i] & 0xFF) + "B"); //ColorComponentTwo
- writeCommand("*v" + (blues[i] & 0xFF) + "C"); //ColorComponentThree
- writeCommand("*v" + i + "I"); //AssignColorIndex
- }
- }
- setRasterGraphicsResolution(dpi);
- writeCommand("*r0f" + img.getHeight() + "t" + (w) + "S");
- writeCommand("*r1A");
-
- Raster raster = img.getData();
-
- ColorEncoder encoder = new ColorEncoder(img);
- // Transfer graphics data
- if (cm.getTransferType() == DataBuffer.TYPE_BYTE) {
- DataBufferByte dataBuffer = (DataBufferByte)raster.getDataBuffer();
- if (img.getSampleModel() instanceof MultiPixelPackedSampleModel && dataBuffer.getNumBanks() == 1) {
- byte[] buf = dataBuffer.getData();
- MultiPixelPackedSampleModel sampleModel = (MultiPixelPackedSampleModel)img.getSampleModel();
- int scanlineStride = sampleModel.getScanlineStride();
- int idx = 0;
- for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
- for (int x = 0; x < scanlineStride; x++) {
- encoder.add8Bits(buf[idx]);
- idx++;
- }
- encoder.endLine();
- }
- } else {
- throw new IOException("Unsupported image");
- }
- } else if (cm.getTransferType() == DataBuffer.TYPE_INT) {
- DataBufferInt dataBuffer = (DataBufferInt)raster.getDataBuffer();
- if (img.getSampleModel() instanceof SinglePixelPackedSampleModel && dataBuffer.getNumBanks() == 1) {
- int[] buf = dataBuffer.getData();
- SinglePixelPackedSampleModel sampleModel = (SinglePixelPackedSampleModel)img.getSampleModel();
- int scanlineStride = sampleModel.getScanlineStride();
- int idx = 0;
- for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
- for (int x = 0; x < scanlineStride; x++) {
- encoder.add8Bits((byte)(buf[idx] >> 16));
- encoder.add8Bits((byte)(buf[idx] >> 8));
- encoder.add8Bits((byte)(buf[idx] >> 0));
- idx++;
- }
- encoder.endLine();
- }
- } else {
- throw new IOException("Unsupported image");
- }
- } else {
- throw new IOException("Unsupported image");
- }
- // End raster graphics
- writeCommand("*rB");
- }
- /**
- * Paint a bitmap at the current cursor position. The bitmap must be a monochrome
- * (1-bit) bitmap image.
- * @param img the bitmap image (must be 1-bit b/w)
- * @param resolution the resolution of the image (must be a PCL resolution)
- * @throws IOException In case of an I/O error
- */
- public void paintMonochromeBitmap(RenderedImage img, int resolution) throws IOException {
- if (!isValidPCLResolution(resolution)) {
- throw new IllegalArgumentException("Invalid PCL resolution: " + resolution);
- }
- boolean monochrome = isMonochromeImage(img);
- if (!monochrome) {
- throw new IllegalArgumentException("img must be a monochrome image");
- }
-
- setRasterGraphicsResolution(resolution);
- writeCommand("*r0f" + img.getHeight() + "t" + img.getWidth() + "s1A");
- Raster raster = img.getData();
-
- Encoder encoder = new Encoder(img);
- // Transfer graphics data
- int imgw = img.getWidth();
- IndexColorModel cm = (IndexColorModel)img.getColorModel();
- if (cm.getTransferType() == DataBuffer.TYPE_BYTE) {
- DataBufferByte dataBuffer = (DataBufferByte)raster.getDataBuffer();
- MultiPixelPackedSampleModel packedSampleModel = new MultiPixelPackedSampleModel(
- DataBuffer.TYPE_BYTE, img.getWidth(), img.getHeight(), 1);
- if (img.getSampleModel().equals(packedSampleModel)
- && dataBuffer.getNumBanks() == 1) {
- //Optimized packed encoding
- byte[] buf = dataBuffer.getData();
- int scanlineStride = packedSampleModel.getScanlineStride();
- int idx = 0;
- int c0 = toGray(cm.getRGB(0));
- int c1 = toGray(cm.getRGB(1));
- boolean zeroIsWhite = c0 > c1;
- for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
- for (int x = 0, maxx = scanlineStride; x < maxx; x++) {
- if (zeroIsWhite) {
- encoder.add8Bits(buf[idx]);
- } else {
- encoder.add8Bits((byte)~buf[idx]);
- }
- idx++;
- }
- encoder.endLine();
- }
- } else {
- //Optimized non-packed encoding
- for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
- byte[] line = (byte[])raster.getDataElements(0, y, imgw, 1, null);
- for (int x = 0, maxx = imgw; x < maxx; x++) {
- encoder.addBit(line[x] == 0);
- }
- encoder.endLine();
- }
- }
- } else {
- //Safe but slow fallback
- for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
- for (int x = 0, maxx = imgw; x < maxx; x++) {
- int sample = raster.getSample(x, y, 0);
- encoder.addBit(sample == 0);
- }
- encoder.endLine();
- }
- }
-
- // End raster graphics
- writeCommand("*rB");
- }
-
- private class Encoder {
-
- private int imgw;
- private int bytewidth;
- private byte[] rle; //compressed (RLE)
- private byte[] uncompressed; //uncompressed
- private int lastcount = -1;
- private byte lastbyte;
- private int rlewidth;
- private byte ib; //current image bits
- private int x;
- private boolean zeroRow = true;
-
- public Encoder(RenderedImage img) {
- imgw = img.getWidth();
- bytewidth = (imgw / 8);
- if ((imgw % 8) != 0) {
- bytewidth++;
- }
- rle = new byte[bytewidth * 2];
- uncompressed = new byte[bytewidth];
- }
-
- public void addBit(boolean bit) {
- //Set image bit for black
- if (bit) {
- ib |= 1;
- }
-
- //RLE encoding
- if ((x % 8) == 7 || ((x + 1) == imgw)) {
- finishedByte();
- } else {
- ib <<= 1;
- }
- x++;
- }
-
- public void add8Bits(byte b) {
- ib = b;
- finishedByte();
- x += 8;
- }
-
- private void finishedByte() {
- if (rlewidth < bytewidth) {
- if (lastcount >= 0) {
- if (ib == lastbyte) {
- lastcount++;
- } else {
- rle[rlewidth++] = (byte)(lastcount & 0xFF);
- rle[rlewidth++] = lastbyte;
- lastbyte = ib;
- lastcount = 0;
- }
- } else {
- lastbyte = ib;
- lastcount = 0;
- }
- if (lastcount == 255 || ((x + 1) == imgw)) {
- rle[rlewidth++] = (byte)(lastcount & 0xFF);
- rle[rlewidth++] = lastbyte;
- lastbyte = 0;
- lastcount = -1;
- }
- }
- uncompressed[x / 8] = ib;
- if (ib != 0) {
- zeroRow = false;
- }
- ib = 0;
- }
-
- public void endLine() throws IOException {
- if (zeroRow && PCLGenerator.this.currentSourceTransparency) {
- writeCommand("*b1Y");
- } else if (rlewidth < bytewidth) {
- writeCommand("*b1m" + rlewidth + "W");
- out.write(rle, 0, rlewidth);
- } else {
- writeCommand("*b0m" + bytewidth + "W");
- out.write(uncompressed);
- }
- lastcount = -1;
- rlewidth = 0;
- ib = 0;
- x = 0;
- zeroRow = true;
- }
-
-
- }
-
- private class ColorEncoder {
- private int imgw;
- private int bytewidth;
- private byte ib; //current image bits
-
- private int currentIndex;
- private int len;
- private int shiftBit = 0x80;
- private int whiteLines;
- final byte[] zeros;
- final byte[] buff1;
- final byte[] buff2;
- final byte[] encodedRun;
- final byte[] encodedTagged;
- final byte[] encodedDelta;
- byte[] seed;
- byte[] current;
- int compression;
- int seedLen;
-
- public ColorEncoder(RenderedImage img) {
- imgw = img.getWidth();
- bytewidth = imgw * 3 + 1;
-
- zeros = new byte[bytewidth];
- buff1 = new byte[bytewidth];
- buff2 = new byte[bytewidth];
- encodedRun = new byte[bytewidth];
- encodedTagged = new byte[bytewidth];
- encodedDelta = new byte[bytewidth];
-
- seed = buff1;
- current = buff2;
-
- seedLen = 0;
- compression = (-1);
- System.arraycopy(zeros, 0, seed, 0, zeros.length);
-
- }
-
- private int runCompression(byte[] buff, int len) {
- int bytes = 0;
-
- try {
- for (int i = 0; i < len;) {
- int sameCount;
- byte seed = current[i++];
-
- for (sameCount = 1; i < len && current[i] == seed; i++) {
- sameCount++;
- }
-
- for (; sameCount > 256; sameCount -= 256) {
- buff[bytes++] = (byte)255;
- buff[bytes++] = seed;
- }
- if (sameCount > 0) {
- buff[bytes++] = (byte)(sameCount - 1);
- buff[bytes++] = seed;
- }
-
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- return len + 1;
- }
- return bytes;
- }
-
- private int deltaCompression(byte[] seed, byte[] buff, int len) {
- int bytes = 0;
-
- try {
- for (int i = 0; i < len;) {
- int sameCount;
- int diffCount;
-
- for (sameCount = 0; i < len && current[i] == seed[i]; i++) {
- sameCount++;
- }
- for (diffCount = 0; i < len && current[i] != seed[i]; i++) {
- diffCount++;
- }
-
- for (; diffCount != 0;) {
- int diffToWrite = (diffCount > 8) ? 8 : diffCount;
- int sameToWrite = (sameCount > 31) ? 31 : sameCount;
-
- buff[bytes++] = (byte)(((diffToWrite - 1) << 5) | sameToWrite);
- sameCount -= sameToWrite;
- if (sameToWrite == 31) {
- for (; sameCount >= 255; sameCount -= 255) {
- buff[bytes++] = (byte)255;
- }
- buff[bytes++] = (byte)sameCount;
- sameCount = 0;
- }
-
- System.arraycopy(current, i - diffCount, buff, bytes, diffToWrite);
- bytes += diffToWrite;
-
- diffCount -= diffToWrite;
- }
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- return len + 1;
- }
- return bytes;
- }
-
- private int tiffCompression(byte[] encodedTagged, int len) {
- int literalCount = 0;
- int bytes = 0;
-
- try {
- for (int from = 0; from < len;) {
- int repeatLength;
- int repeatValue = current[from];
-
- for (repeatLength = 1; repeatLength < 128
- && from + repeatLength < len
- && current[from + repeatLength] == repeatValue;) {
- repeatLength++;
- }
-
- if (literalCount == 128 || (repeatLength > 2 && literalCount > 0)) {
- encodedTagged[bytes++] = (byte)(literalCount - 1);
- System.arraycopy(current, from - literalCount, encodedTagged, bytes, literalCount);
- bytes += literalCount;
- literalCount = 0;
- }
- if (repeatLength > 2) {
- encodedTagged[bytes++] = (byte)(1 - repeatLength);
- encodedTagged[bytes++] = current[from];
- from += repeatLength;
- } else {
- literalCount++;
- from++;
- }
- }
- if (literalCount > 0) {
- encodedTagged[bytes++] = (byte)(literalCount - 1);
- System.arraycopy(current, (3 * len) - literalCount, encodedTagged, bytes, literalCount);
- bytes += literalCount;
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- return len + 1;
- }
- return bytes;
- }
-
- public void addBit(boolean bit) {
- //Set image bit for black
- if (bit) {
- ib |= shiftBit;
- }
- shiftBit >>= 1;
- if (shiftBit == 0) {
- add8Bits(ib);
- shiftBit = 0x80;
- ib = 0;
- }
- }
-
- public void add8Bits(byte b) {
- current[currentIndex++] = b;
- if (b != 0) {
- len = currentIndex;
- }
- }
-
- public void endLine() throws IOException {
- if (len == 0) {
- whiteLines++;
- } else {
- if (whiteLines > 0) {
- writeCommand("*b" + whiteLines + "Y");
- whiteLines = 0;
- }
-
- int unencodedCount = len;
- int runCount = runCompression(encodedRun, len);
- int tiffCount = tiffCompression(encodedTagged, len);
- int deltaCount = deltaCompression(seed, encodedDelta, Math.max(len, seedLen));
-
- int bestCount = Math.min(unencodedCount, Math.min(runCount, Math.min(tiffCount, deltaCount)));
- int bestCompression;
-
- if (bestCount == unencodedCount) {
- bestCompression = 0;
- } else if (bestCount == runCount) {
- bestCompression = 1;
- } else if (bestCount == tiffCount) {
- bestCompression = 2;
- } else {
- bestCompression = 3;
- }
-
- if (compression != bestCompression) {
- compression = bestCompression;
- writeCommand("*b" + compression + "M");
- }
-
- if (bestCompression == 0) {
- writeCommand("*b" + unencodedCount + "W");
- out.write(current, 0, unencodedCount);
- } else if (bestCompression == 1) {
- writeCommand("*b" + runCount + "W");
- out.write(encodedRun, 0, runCount);
- } else if (bestCompression == 2) {
- writeCommand("*b" + tiffCount + "W");
- out.write(encodedTagged, 0, tiffCount);
- } else if (bestCompression == 3) {
- writeCommand("*b" + deltaCount + "W");
- out.write(encodedDelta, 0, deltaCount);
- }
-
- if (current == buff1) {
- seed = buff1;
- current = buff2;
- } else {
- seed = buff2;
- current = buff1;
- }
- seedLen = len;
- }
- shiftBit = 0x80;
- ib = 0;
- len = 0;
- currentIndex = 0;
- }
- }
-
- }
|