#21 Long Text Strings With No Spaces - Weird Behavior

closed-fixed
None
5
2011-11-30
2011-10-12
Brian
No

If you have a long string that has no spaces in it, and render it using the block composer, it will not render properly (if at all).

Example:

This works fine:

var page = new Page(document);
document.Pages.Add(page);
SizeF pageSize = page.Size;
var composer = new PrimitiveComposer(page);
var blockComposer = new BlockComposer(composer);
RectangleF frame = new RectangleF(
Margin_X,
Margin_Y,
(float)pageSize.Width - Margin_X * 2,
(float)pageSize.Height - Margin_Y * 2
);
blockComposer.Begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Top);
org.pdfclown.documents.contents.fonts.Font decorativeFont = new StandardType1Font(document,StandardType1Font.FamilyEnum.Helvetica,false,false);

composer.SetFont(decorativeFont,9);
blockComposer.ShowText("this is long text with plenty of spaces. The wrapping behavior works exactly like one would expect it to work.");
blockComposer.End();
composer.Flush();

As stated, that works fine. This code, not so much:

var page = new Page(document);
document.Pages.Add(page);
SizeF pageSize = page.Size;
var composer = new PrimitiveComposer(page);
var blockComposer = new BlockComposer(composer);
RectangleF frame = new RectangleF(
Margin_X,
Margin_Y,
(float)pageSize.Width - Margin_X * 2,
(float)pageSize.Height - Margin_Y * 2
);
blockComposer.Begin(frame,AlignmentXEnum.Justify,AlignmentYEnum.Top);
org.pdfclown.documents.contents.fonts.Font decorativeFont = new StandardType1Font(document,StandardType1Font.FamilyEnum.Helvetica,false,false);

composer.SetFont(decorativeFont,9);
blockComposer.ShowText("thisislongtextwithplentyofspaces.Thewrappingbehaviorworksexactlylikeonewouldexpectittowork.");
blockComposer.End();
composer.Flush();

When using a long text string with no spaces. All of the text is gone. Please explain.

Discussion

  • Stefano Chizzolini

    Brian,

    yours is a fringe case I didn't manage.

    As 0.1.1 feature set has already been frozen for upcoming release, I'll support your case in the following 0.1.2 release and 0.1.1-Fix branch.

    I'll implement this rule: if the first word in a line cannot fit it because of its length, split it into the largest possible chunk and move the trailing part to the next line.

    Thank you
    Stefano

     
  • Stefano Chizzolini

    • assigned_to: nobody --> stechio
     
  • Anonymous - 2011-11-16

    For anyone looking for solution, fix is quite simple:

    Check that is before calling Hyphanate method should be removed (&& wordEndIndex > 0)
    In Hyphenate method:
    font.GetKerning(text[wordEndIndex - 1], textChar) should be replaced by (wordEndIndex > 0 ? font.GetKerning(text[wordEndIndex - 1], textChar) : 0)

     
  • Stefano Chizzolini

    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks