diff --git a/.gitignore b/.gitignore index 6936b1ad..34e47eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ nb-configuration.xml .classpath .project .vscode -private.key \ No newline at end of file +private.key +src/test/resources/fonts/* \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..37f78a6a --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..adff685a --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed 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 +# +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/src/main/java/be/quodlibet/boxable/Paragraph.java b/src/main/java/be/quodlibet/boxable/Paragraph.java index d673b3a2..d58edf3a 100644 --- a/src/main/java/be/quodlibet/boxable/Paragraph.java +++ b/src/main/java/be/quodlibet/boxable/Paragraph.java @@ -578,10 +578,28 @@ public List getLines() { String word = token.getData(); float wordWidth = token.getWidth(currentFont); if(wordWidth / 1000f * currentFontSize > width && width > font.getAverageFontWidth() / 1000f * currentFontSize) { - // you need to check if you have already something in your line - boolean alreadyTextInLine = false; + // If there's already content in the current line, flush it first + // before starting character-by-character splitting. + // This prevents mixing text from different wrap point segments + // on the same line (e.g. when a custom WrappingFunction is used). if(textInLine.trimmedWidth()>0){ - alreadyTextInLine = true; + textInLine.push(sinceLastWrapPoint); + textInLineMaxFontHeight = Math.max(textInLineMaxFontHeight, sinceLastWrapPointMaxFontHeight); + textInLineMaxFontSize = Math.max(textInLineMaxFontSize, sinceLastWrapPointMaxFontSize); + sinceLastWrapPointMaxFontHeight = 0f; + sinceLastWrapPointMaxFontSize = 0f; + result.add(textInLine.trimmedText()); + lineWidths.put(lineCounter, textInLine.trimmedWidth()); + mapLineTokens.put(lineCounter, textInLine.tokens()); + lineHeights.put(lineCounter, textInLineMaxFontHeight == 0f + ? FontUtils.getHeight(font, fontSize) + : textInLineMaxFontHeight); + lineFontSizes.put(lineCounter, textInLineMaxFontSize == 0f ? fontSize : textInLineMaxFontSize); + maxLineWidth = Math.max(maxLineWidth, textInLine.trimmedWidth()); + textInLine.reset(); + textInLineMaxFontHeight = 0f; + textInLineMaxFontSize = 0f; + lineCounter++; } while (wordWidth / 1000f * currentFontSize > width) { float width = 0; @@ -597,15 +615,6 @@ public List getLines() { } catch (IOException e) { e.printStackTrace(); } - if(alreadyTextInLine){ - if (width < this.width - textInLine.trimmedWidth()) { - firstPartOfWord.append(c); - firstPartWordWidth = Math.max(width, firstPartWordWidth); - } else { - restOfTheWord.append(c); - restOfTheWordWidth = Math.max(width, restOfTheWordWidth); - } - } else { if (width < this.width) { firstPartOfWord.append(c); firstPartWordWidth = Math.max(width, firstPartWordWidth); @@ -622,10 +631,7 @@ public List getLines() { } } - } } - // reset - alreadyTextInLine = false; sinceLastWrapPoint.push(currentFont, currentFontSize, Token.text(TokenType.TEXT, firstPartOfWord.toString())); sinceLastWrapPointMaxFontHeight = Math.max(sinceLastWrapPointMaxFontHeight, diff --git a/src/main/java/be/quodlibet/boxable/text/Tokenizer.java b/src/main/java/be/quodlibet/boxable/text/Tokenizer.java index dc4136c7..eac8bc3b 100644 --- a/src/main/java/be/quodlibet/boxable/text/Tokenizer.java +++ b/src/main/java/be/quodlibet/boxable/text/Tokenizer.java @@ -80,14 +80,47 @@ private static Stack findWrapPoints(String text) { private static Stack findWrapPointsWithFunction(String text, WrappingFunction wrappingFunction) { final String[] split = wrappingFunction.getLines(text); - int textIndex = text.length(); final Stack possibleWrapPoints = new Stack<>(); - possibleWrapPoints.push(textIndex); - for (int i = split.length - 1; i > 0; i--) { - final int splitLength = split[i].length(); - possibleWrapPoints.push(textIndex - splitLength); - textIndex -= splitLength; + possibleWrapPoints.push(text.length()); + + if (split.length == 0) { + return possibleWrapPoints; } + + // Find the actual position of each segment in the original text + // Wrap points should be placed AFTER any delimiter characters between segments + final List wrapPointsList = new ArrayList<>(); + int searchStartIndex = 0; + for (int i = 0; i < split.length - 1; i++) { + final String segment = split[i]; + // Search for this segment starting from where the previous segment ended + // This handles cases where segments might contain repeated substrings + final int segmentIndex = text.indexOf(segment, searchStartIndex); + if (segmentIndex >= 0) { + // The wrap point is at the start of the next segment + // (any characters between this segment and the next are delimiters) + final int endOfSegment = segmentIndex + segment.length(); + // Find the next segment to determine where delimiters end + final String nextSegment = split[i + 1]; + // Search for next segment starting after this segment ends + final int nextSegmentIndex = text.indexOf(nextSegment, endOfSegment); + if (nextSegmentIndex >= 0) { + // Wrap point is at the start of the next segment + // This means delimiters between segments will be included in the previous TEXT token + wrapPointsList.add(nextSegmentIndex); + searchStartIndex = nextSegmentIndex; + } else { + // Couldn't find next segment, move past current segment + searchStartIndex = endOfSegment; + } + } + } + + // Push wrap points in reverse order onto the stack (required by the tokenizer) + for (int i = wrapPointsList.size() - 1; i >= 0; i--) { + possibleWrapPoints.push(wrapPointsList.get(i)); + } + return possibleWrapPoints; } diff --git a/src/test/java/be/quodlibet/boxable/text/TokenizerTest.java b/src/test/java/be/quodlibet/boxable/text/TokenizerTest.java index 9fe9b75d..6ee72915 100644 --- a/src/test/java/be/quodlibet/boxable/text/TokenizerTest.java +++ b/src/test/java/be/quodlibet/boxable/text/TokenizerTest.java @@ -1,12 +1,28 @@ package be.quodlibet.boxable.text; +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.font.PDFont; +import org.apache.pdfbox.pdmodel.font.PDType0Font; +import org.apache.pdfbox.pdmodel.font.PDType1Font; +import org.apache.pdfbox.pdmodel.font.Standard14Fonts; import org.junit.Assert; import org.junit.Test; +import be.quodlibet.boxable.BaseTable; +import be.quodlibet.boxable.Cell; +import be.quodlibet.boxable.HorizontalAlignment; +import be.quodlibet.boxable.Row; + public class TokenizerTest { private WrappingFunction wrappingFunction = null; @@ -184,4 +200,232 @@ public void testEmptyString() throws Exception { } } + + /** + * Regression test for issue #298: setWrappingFunction not working. + * Tests that a custom WrappingFunction that splits on '#' is respected, + * and the default wrapping behavior is NOT applied. + * Produces a PDF to visually verify the custom wrapping behavior. + */ + @Test + public void testCustomWrappingFunctionWithHashDelimiter() throws Exception { + // Create a custom wrapping function that splits AFTER '#' characters + // The regex (?<=#) is a positive lookbehind that splits immediately after '#' + // This keeps '#' at the end of each segment (matching default wrapping behavior + // where delimiters like spaces are kept in segments) + final WrappingFunction customWrappingFunction = new WrappingFunction() { + @Override + public String[] getLines(String text) { + if (text == null) { + return new String[0]; + } + // Use positive lookbehind to split after '#' but keep '#' in segments + return text.split("(?<=#)"); + } + }; + + // Test text with many '/' characters and '#' separators + // If the custom function works correctly, it should only split on '#', not on '/' + final String text = "path/to/file/one#path/to/file/two#path/to/file/three"; + final List tokens = Tokenizer.tokenize(text, customWrappingFunction); + + // Count TEXT tokens (should be 3 segments split by '#') + int textTokenCount = 0; + for (Token token : tokens) { + if (TokenType.TEXT.equals(token.getType())) { + textTokenCount++; + } + } + + // Should have exactly 3 TEXT tokens (one for each segment between '#') + Assert.assertEquals("Custom wrapping function should split text into 3 segments", 3, textTokenCount); + + // Verify that the TEXT segments contain '/' characters (i.e., they were NOT split on '/') + boolean foundSlashInTextToken = false; + for (Token token : tokens) { + if (TokenType.TEXT.equals(token.getType()) && token.getData().contains("/")) { + foundSlashInTextToken = true; + break; + } + } + Assert.assertTrue("TEXT tokens should contain '/' characters (not split on '/')", foundSlashInTextToken); + + // Verify the actual content of the TEXT tokens + final List textSegments = new ArrayList<>(); + for (Token token : tokens) { + if (TokenType.TEXT.equals(token.getType())) { + textSegments.add(token.getData()); + } + } + + // Expected segments after splitting on '#' (with '#' included in segments) + Assert.assertEquals("First segment should be 'path/to/file/one#'", "path/to/file/one#", textSegments.get(0)); + Assert.assertEquals("Second segment should be 'path/to/file/two#'", "path/to/file/two#", textSegments.get(1)); + Assert.assertEquals("Third segment should be 'path/to/file/three'", "path/to/file/three", textSegments.get(2)); + + // --- Produce a PDF to visually verify custom wrapping --- + PDDocument doc = new PDDocument(); + PDPage page = new PDPage(PDRectangle.A4); + doc.addPage(page); + + float margin = 50; + float yStart = page.getMediaBox().getHeight() - margin; + float tableWidth = page.getMediaBox().getWidth() - (2 * margin); + float yStartNewPage = page.getMediaBox().getHeight() - margin; + float bottomMargin = 70; + + BaseTable table = new BaseTable(yStart, yStartNewPage, bottomMargin, tableWidth, margin, doc, page, true, true); + + // Load DejaVuSansCondensed if available, otherwise fall back to Helvetica + File fontFile = new File("src/test/resources/fonts/DejaVuSansCondensed.ttf"); + PDFont font; + PDFont fontBold; + if (fontFile.exists()) { + font = PDType0Font.load(doc, fontFile); + fontBold = font; // use same font for bold (no bold variant available) + } else { + font = new PDType1Font(Standard14Fonts.FontName.HELVETICA); + fontBold = new PDType1Font(Standard14Fonts.FontName.HELVETICA_BOLD); + } + + // Title row + Row titleRow = table.createRow(20f); + Cell titleCell = titleRow.createCell(100, "Issue #298: Custom WrappingFunction with '#' Delimiter"); + titleCell.setFont(fontBold); + titleCell.setFontSize(12f); + titleCell.setFillColor(new Color(41, 128, 185)); + titleCell.setTextColor(Color.WHITE); + titleCell.setAlign(HorizontalAlignment.CENTER); + + // Description row explaining what the user should see + Row descRow = table.createRow(30f); + Cell descCell = descRow.createCell(100, + "Expected: The custom wrapping function splits text on '#' only. " + + "The '/' characters should NOT cause line breaks. " + + "Each row below wraps at '#' boundaries, never at '/' boundaries."); + descCell.setFont(font); + descCell.setFillColor(new Color(236, 240, 241)); + descCell.setFontSize(8f); + + // Header row + Row headerRow = table.createRow(15f); + Cell h1 = headerRow.createCell(25, "Scenario"); + h1.setFont(fontBold); + h1.setFillColor(new Color(52, 73, 94)); + h1.setTextColor(Color.WHITE); + h1.setFontSize(9f); + + Cell h2 = headerRow.createCell(50, "Cell Content (with custom '#' wrapping)"); + h2.setFont(fontBold); + h2.setFillColor(new Color(52, 73, 94)); + h2.setTextColor(Color.WHITE); + h2.setFontSize(9f); + + Cell h3 = headerRow.createCell(25, "Expected Wrapping"); + h3.setFont(fontBold); + h3.setFillColor(new Color(52, 73, 94)); + h3.setTextColor(Color.WHITE); + h3.setFontSize(9f); + + table.addHeaderRow(headerRow); + + // --- Row 1: Basic '#' delimited paths in a narrow cell --- + Row row1 = table.createRow(40f); + Cell r1c1 = row1.createCell(25, "Paths with '#' separator"); + r1c1.setFont(font); + r1c1.setFontSize(8f); + Cell r1c2 = row1.createCell(50, text); + r1c2.setFont(font); + r1c2.setFontSize(8f); + r1c2.setWrappingFunction(customWrappingFunction); + Cell r1c3 = row1.createCell(25, "Wraps after each '#', slashes stay together on same line"); + r1c3.setFont(font); + r1c3.setFontSize(7f); + r1c3.setFillColor(new Color(234, 250, 241)); + + // --- Row 2: Same text WITHOUT custom wrapping (default behavior) --- + Row row2 = table.createRow(40f); + Cell r2c1 = row2.createCell(25, "Same text, DEFAULT wrapping (no custom function)"); + r2c1.setFont(font); + r2c1.setFontSize(8f); + r2c1.setFillColor(new Color(253, 237, 236)); + Cell r2c2 = row2.createCell(50, text); + r2c2.setFont(font); + r2c2.setFontSize(8f); + r2c2.setFillColor(new Color(253, 237, 236)); + // No custom wrapping function - uses default behavior + Cell r2c3 = row2.createCell(25, "May wrap at spaces or other default points; compare with row above"); + r2c3.setFont(font); + r2c3.setFontSize(7f); + r2c3.setFillColor(new Color(253, 237, 236)); + + // --- Row 3: Longer text with more '#' segments --- + String longerText = "com/example/pkg/ClassA#com/example/pkg/ClassB#com/example/pkg/ClassC#com/example/pkg/ClassD"; + Row row3 = table.createRow(50f); + Cell r3c1 = row3.createCell(25, "Longer paths with '#' separator"); + r3c1.setFont(font); + r3c1.setFontSize(8f); + Cell r3c2 = row3.createCell(50, longerText); + r3c2.setFont(font); + r3c2.setFontSize(8f); + r3c2.setWrappingFunction(customWrappingFunction); + Cell r3c3 = row3.createCell(25, "4 segments, each wrapping only at '#'. Slashes within each segment stay on the same line"); + r3c3.setFont(font); + r3c3.setFontSize(7f); + r3c3.setFillColor(new Color(234, 250, 241)); + + // --- Row 4: Text without any '#' (should remain on one line) --- + String noHashText = "path/to/some/deeply/nested/file/without/hash"; + Row row4 = table.createRow(30f); + Cell r4c1 = row4.createCell(25, "No '#' in text"); + r4c1.setFont(font); + r4c1.setFontSize(8f); + Cell r4c2 = row4.createCell(50, noHashText); + r4c2.setFont(font); + r4c2.setFontSize(8f); + r4c2.setWrappingFunction(customWrappingFunction); + Cell r4c3 = row4.createCell(25, "No '#' means no custom wrap points; text treated as single segment"); + r4c3.setFont(font); + r4c3.setFontSize(7f); + r4c3.setFillColor(new Color(234, 250, 241)); + + // --- Row 5: Heavy slash text with '#' delimiters (custom wrapping) --- + String heavySlashText = "/////////////////////////aaa//////////////////////////#/////////////////////////aaa//////////////////////////#/////////////////////////aaa//////////////////////////#/////////////////////////aaa////////////////////////// /////////////////////////aaa//////////////////////////"; + Row row5 = table.createRow(80f); + Cell r5c1 = row5.createCell(25, "Heavy slashes with '#' (custom wrapping)"); + r5c1.setFont(font); + r5c1.setFontSize(8f); + Cell r5c2 = row5.createCell(50, heavySlashText); + r5c2.setFont(font); + r5c2.setFontSize(8f); + r5c2.setWrappingFunction(customWrappingFunction); + Cell r5c3 = row5.createCell(25, "Wraps only at '#'. Each long slash segment stays together on one line"); + r5c3.setFont(font); + r5c3.setFontSize(7f); + r5c3.setFillColor(new Color(234, 250, 241)); + + // --- Row 6: Same heavy slash text with DEFAULT wrapping --- + Row row6 = table.createRow(80f); + Cell r6c1 = row6.createCell(25, "Heavy slashes, DEFAULT wrapping (no custom function)"); + r6c1.setFont(font); + r6c1.setFontSize(8f); + r6c1.setFillColor(new Color(253, 237, 236)); + Cell r6c2 = row6.createCell(50, heavySlashText); + r6c2.setFont(font); + r6c2.setFontSize(8f); + r6c2.setFillColor(new Color(253, 237, 236)); + // No custom wrapping function - uses default behavior + Cell r6c3 = row6.createCell(25, "Default wrapping may break at different points; compare with row above"); + r6c3.setFont(font); + r6c3.setFontSize(7f); + r6c3.setFillColor(new Color(253, 237, 236)); + + table.draw(); + + File file = new File("target/CustomWrappingFunctionHashDelimiter.pdf"); + System.out.println("Sample file saved at : " + file.getAbsolutePath()); + file.getParentFile().mkdirs(); + doc.save(file); + doc.close(); + } }