[
https://issues.apache.org/jira/browse/PDFBOX-6192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18073727#comment-18073727
]
Stefan Ziegler commented on PDFBOX-6192:
----------------------------------------
Simple test code:
{code:java}
static final String BASE25 = "BCDEFGHIJKLMNOPQRSTUVWXYZ";
/** Verbatim copy from PDFBox 3.0.7 TrueTypeEmbedder.getTag(). */
static String getTag(Map<Integer, Integer> gidToCid) {
long num = gidToCid.hashCode();
StringBuilder sb = new StringBuilder();
do {
long div = num / 25;
int mod = (int) (num % 25);
sb.append(BASE25.charAt(mod));
num = div;
} while (num != 0 && sb.length() < 6);
while (sb.length() < 6) {
sb.insert(0, 'A');
}
sb.append('+');
return sb.toString();
}
public static void main(String[] args) {
Map<Integer, Integer> m = new HashMap<>();
m.put(1, Integer.MIN_VALUE);
System.out.println("Map.hashCode() = " + m.hashCode());
System.out.println("getTag() = " + getTag(m));
}
{code}
> PDIndexed() no-arg constructor, setBaseColorSpace(), and setHighValue() all
> deprecated in 3.x with no usable replacement for incremental construction
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: PDFBOX-6192
> URL: https://issues.apache.org/jira/browse/PDFBOX-6192
> Project: PDFBox
> Issue Type: Wish
> Affects Versions: 3.0.7 PDFBox
> Reporter: Stefan Ziegler
> Priority: Major
>
> We are converting PostScript to PDF using PDFBox 3.x. PostScript's Indexed
> color space is defined as:
> {code:java}
> [/Indexed base hival lookup]
> {code}
> where base, hival, and lookup arrive as separate, independently parsed
> PostScript values. We need to construct a PDIndexed object incrementally:
> first set the base color space, then set the high value, and later
> (optionally) supply the lookup table.
> The current 3.x API offers exactly one approach for this:
> {code:java}
> PDIndexed indexed = new PDIndexed(); // @Deprecated
> indexed.setBaseColorSpace(base); // @Deprecated
> indexed.setHighValue(hival); // @Deprecated{code}
> All three of these are now marked {{@Deprecated}} with the note _"This will
> be removed in 4.0. If you need it, please contact us."_ — but {*}no
> replacement is suggested{*}.
> The only non-deprecated constructor is:
> {code:java}
> public PDIndexed(COSArray indexedArray) throws IOException{code}
> This constructor immediately calls {{readColorTable()}} and
> {{initRgbColorTable()}} in its body, which require a fully assembled
> {{COSArray}} including a valid lookup table at slot index 3. This makes it
> {*}impossible to use for incremental construction{*}: we cannot assemble the
> complete {{COSArray}} up front because the base color space, hival, and
> lookup data are parsed from separate PostScript operands at different points
> in the execution.
> Attempting to pass a partially built {{COSArray}} (e.g. with {{COSNull}} as
> the lookup entry, as the deprecated default constructor does internally) to
> the non-deprecated constructor would either throw an {{IOException}} during
> table initialization or produce a broken object.
>
> *Request:*
> Please provide one of the following:
> # A *builder or factory method* such as {{PDIndexed.create(PDColorSpace
> base, int hival, byte[] lookupData)}} that accepts the fully resolved
> components and handles internal construction — allowing callers to avoid
> piecemeal mutation without requiring a pre-built {{{}COSArray{}}}.
> # Or *retain the no-arg constructor and the three setters as non-deprecated*
> (or re-deprecate only after a builder is in place), since there is currently
> no way to construct a {{PDIndexed}} from dynamically parsed components
> without them.
> The deprecation of all mutation entry points simultaneously, without
> providing an incremental-construction alternative, leaves consumers of
> PostScript/PDF generation pipelines with no supported path forward.
> *PDFBox version:* 3.0.7 *Affected class:*
> {{org.apache.pdfbox.pdmodel.graphics.color.PDIndexed}}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]