| 1 |
/* ===================================================================== |
| 2 |
* JFreePDF : a fast, light-weight PDF library for the Java(tm) platform |
| 3 |
* ===================================================================== |
| 4 |
* |
| 5 |
* (C)opyright 2013-2022, by David Gilbert. All rights reserved. |
| 6 |
* |
| 7 |
* https://github.com/jfree/orsonpdf |
| 8 |
* |
| 9 |
* This program is free software: you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as published by |
| 11 |
* the Free Software Foundation, either version 3 of the License, or |
| 12 |
* (at your option) any later version. |
| 13 |
* |
| 14 |
* This program is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
* |
| 22 |
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
| 23 |
* Other names may be trademarks of their respective owners.] |
| 24 |
* |
| 25 |
* If you do not wish to be bound by the terms of the GPL, an alternative |
| 26 |
* runtime license is available to JFree sponsors: |
| 27 |
* |
| 28 |
* https://github.com/sponsors/jfree |
| 29 |
* |
| 30 |
*/ |
| 31 |
|
| 32 |
package org.jfree.pdf; |
| 33 |
|
| 34 |
import java.awt.RenderingHints; |
| 35 |
|
| 36 |
/** |
| 37 |
* Defines the rendering hints that can be used with the {@link PDFGraphics2D} |
| 38 |
* class. There is just one hint defined at present:<br> |
| 39 |
* <ul> |
| 40 |
* <li>{@link #KEY_DRAW_STRING_TYPE} that controls how the drawString() methods |
| 41 |
* generate output (regular text or vector graphics);</li> |
| 42 |
* </ul> |
| 43 |
* |
| 44 |
* @since 1.5 |
| 45 |
*/ |
| 46 |
public final class PDFHints { |
| 47 |
|
| 48 |
private PDFHints() { |
| 49 |
// no need to instantiate this |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* The key for the hint that controls whether strings are rendered as |
| 54 |
* characters (standard PDF output) or vector graphics (implemented using |
| 55 |
* <code>TextLayout</code>). The latter will result in larger output files |
| 56 |
* but permits rendering Unicode characters without font embedding (which is |
| 57 |
* not supported by <strong>JFreePDF</strong> at this point). Valid hint |
| 58 |
* values are {@link #VALUE_DRAW_STRING_TYPE_STANDARD} and |
| 59 |
* {@link #VALUE_DRAW_STRING_TYPE_VECTOR}. |
| 60 |
*/ |
| 61 |
public static final PDFHints.Key KEY_DRAW_STRING_TYPE = new PDFHints.Key(0); |
| 62 |
|
| 63 |
/** |
| 64 |
* Hint value for <code>KEY_DRAW_STRING_TYPE</code> to specify that strings |
| 65 |
* should be written to the output using standard PDF text primitives. |
| 66 |
*/ |
| 67 |
public static final Object VALUE_DRAW_STRING_TYPE_STANDARD |
| 68 |
= "VALUE_DRAW_STRING_TYPE_STANDARD"; |
| 69 |
|
| 70 |
/** |
| 71 |
* Hint value for <code>KEY_DRAW_STRING_TYPE</code> to say that strings |
| 72 |
* should be written to the output using vector graphics primitives. |
| 73 |
*/ |
| 74 |
public static final Object VALUE_DRAW_STRING_TYPE_VECTOR |
| 75 |
= "VALUE_DRAW_STRING_TYPE_VECTOR"; |
| 76 |
|
| 77 |
/** |
| 78 |
* A key for hints used by the {@link PDFGraphics2D} class. |
| 79 |
*/ |
| 80 |
public static class Key extends RenderingHints.Key { |
| 81 |
|
| 82 |
/** |
| 83 |
* Creates a new instance with the specified key. |
| 84 |
* |
| 85 |
* @param privateKey the key. |
| 86 |
*/ |
| 87 |
public Key(int privateKey) { |
| 88 |
super(privateKey); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Returns {@code true} if {@code val} is a value that is |
| 93 |
* compatible with this key, and {@code false} otherwise. |
| 94 |
* |
| 95 |
* @param val the value. |
| 96 |
* |
| 97 |
* @return A boolean. |
| 98 |
*/ |
| 99 |
@Override |
| 100 |
public boolean isCompatibleValue(Object val) { |
| 101 |
switch (intKey()) { |
| 102 |
case 0: |
| 103 |
return val == null |
| 104 |
|| VALUE_DRAW_STRING_TYPE_STANDARD.equals(val) |
| 105 |
|| VALUE_DRAW_STRING_TYPE_VECTOR.equals(val); |
| 106 |
default: |
| 107 |
throw new RuntimeException("Not expected!"); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
} |