@@ -254,6 +254,16 @@ else if (!font.isEmbedded() && !font.isStandard14())
254254 */
255255 public void showTextWithPositioning (Object [] textWithPositioningArray ) throws IOException
256256 {
257+ if (!inTextMode )
258+ {
259+ throw new IllegalStateException ("Must call beginText() before showTextWithPositioning()" );
260+ }
261+
262+ if (fontStack .isEmpty ())
263+ {
264+ throw new IllegalStateException ("Must call setFont() before showTextWithPositioning()" );
265+ }
266+
257267 write ("[" );
258268 for (Object obj : textWithPositioningArray )
259269 {
@@ -275,10 +285,12 @@ else if (obj instanceof Float)
275285 }
276286
277287 /**
278- * Show the given glyphs at the specified positions
288+ * Show the given glyphs at the specified positions. This method is meant to be called from
289+ * within a GlyphLayoutProcessorInterface implementation and only for PDType0Font.
279290 *
280291 * @param glyphsAndPositions List of glyphs and positions
281292 * @throws IOException if an IO error occurs
293+ * @throws IllegalStateException if the current font isn't a PDType0Font.
282294 */
283295 @ Override
284296 public void showGlyphsWithPositioning (GlyphsAndPositions glyphsAndPositions ) throws IOException
@@ -355,6 +367,7 @@ public void showText(String text) throws IOException
355367 *
356368 * @param glyphCodes Array of glyph codes of the content font
357369 * @throws IOException if an I/O exception occurs
370+ * @throws IllegalStateException if the current font isn't a PDType0Font.
358371 */
359372 @ Override
360373 public void showGlyphCodes (int [] glyphCodes ) throws IOException
@@ -370,22 +383,22 @@ public void showGlyphCodes(int[] glyphCodes) throws IOException
370383 * @param glyphCodes The glyph codes to write
371384 *
372385 * @throws IOException in case of I/O error
386+ * @throws IllegalStateException if the current font isn't a PDType0Font.
373387 */
374388 protected void writeTextPDType0Font (int [] glyphCodes ) throws IOException
375389 {
376390 if (!inTextMode )
377391 {
378- throw new IllegalStateException ("Must call beginText() before showText ()" );
392+ throw new IllegalStateException ("Must call beginText() before writeTextPDType0Font ()" );
379393 }
380394 if (fontStack .isEmpty ())
381395 {
382- throw new IllegalStateException ("Must call setFont() before showText ()" );
396+ throw new IllegalStateException ("Must call setFont() before writeTextPDType0Font ()" );
383397 }
384398 PDFont font = fontStack .peek ();
385399 if (!(font instanceof PDType0Font ))
386400 {
387401 throw new IllegalStateException ("Must be called with current font instance of PDType0Font" );
388-
389402 }
390403 PDType0Font pdType0Font = (PDType0Font ) font ;
391404
@@ -414,23 +427,15 @@ protected void writeTextPDType0Font(int[] glyphCodes) throws IOException
414427
415428 /**
416429 * Outputs a string using the correct encoding and subsetting as required.
430+ * <p>
431+ * inTextMode and fontStack must already have already been checked before calling this method.
417432 *
418433 * @param text The Unicode text to show.
419434 *
420435 * @throws IOException If an io exception occurs.
421436 */
422437 protected void showTextInternal (String text ) throws IOException
423438 {
424- if (!inTextMode )
425- {
426- throw new IllegalStateException ("Must call beginText() before showText()" );
427- }
428-
429- if (fontStack .isEmpty ())
430- {
431- throw new IllegalStateException ("Must call setFont() before showText()" );
432- }
433-
434439 PDFont font = fontStack .peek ();
435440
436441 // complex text layout
0 commit comments