The word wrapper doesn't just split texts at spaces and punctuation like it should, but also in the middle of words. I haven't found a pattern in when it happens yet, but here's an example (the font is Conduit ITC Light Italic): http://imageload.dk/files/9d8d0e2963b1c2006968503166942aab.png (should have said "En visionær energipolitik")

Comments

Deciphered’s picture

Hi krasmussen,

I have just had a quick look at the latest version and you are correct, there are definitely issues with the line wrapping, will look into this and see what solution I can come up with.

How are you calling your textimage? If you are using CCK with a Textimage display you may be able to fix the issue temporarily by putting a line break in the string, however this is not really an acceptable fix so keep your eyes on this issue for a real fix.

Cheers,
Deciphered.

Deciphered’s picture

On second look, it may be related to the 'æ' symbol, which is no less of an issue.

Can you test the same string replacing the 'æ' with 'ae' which will make the string longer but may cause the wrapping to work correctly, then let me know if it is the case so I can come up with a solution for the issue.

Deciphered’s picture

Hi again,

Looks like it's a simple fix:

In textimage.module. find the 'textimage_wrap_text' function and change the following line:

      $text = drupal_substr($text, 0, $fit) ."\n". drupal_substr($text, $fit);

To:

      $text = substr($text, 0, $fit) ."\n". substr($text, $fit);

Please confirm that this fixes your issue, and pending some testing it should be committed.

wundo’s picture

Hi Deciphered,
We should stick with drupal_substr as much as possible, are you sure there is something wrong with drupal_substr?
Also this could mean that we are not properly dealing with unicode characters...

Deciphered’s picture

@wundo

I can certainly do some more testing on the issue, but from what I can tell drupal_strlen is getting the correct character count for the unicode string, but drupal_substr is cutting the text at an incorrect location, whereas the standard substr is cutting correctly.

Whether this is an issue with drupal_substr or an incorrect use of the drupal_ version of the command (and there are definitely cases not to use the drupal_ functions), I can not say at this stage.

Even if it is an issue with drupal_substr, this fix is fixing the issue and does not appear to be introducing any new issues.
Pending confirmation from krasmussen I think it should be safe enough to commit.

Cheers,
Deciphered.

Edit: After a bit more testing, I think I agree that it needs further work. While technically the fix posted above does fix the issue, I don't believe it is the correct cause of the problem. Will keep digging.

Deciphered’s picture

I now believe that the issue is related to the regular expressions/preg_match() handling of unicode characters, in searching for breakpoints it is (in this case) counting an extra character and therefore offsetting the cutting point.

Deciphered’s picture

Ok, I have a new fix, I'm not overly happy with it, but I think it is what needs to be done.

Essentially I've taken the code from http://php.nusa.net.id/manual/en/function.preg-match.php#71571 and wrapped it in code similar to that of http://api.drupal.org/api/function/drupal_strlen/6.

Probably something that should be pushed as a patch for D7.

Patch will be posted ASAP for testing.

krasmussen’s picture

I can confirm that using substr() instead of the Drupal function fixes the issue. Thanks for the very quick response.

Deciphered’s picture

Status: Active » Fixed

Committed a fix to HEAD, DRUPAL-6--2 and DRUPAL-5--2 using the code at #465638: drupal_preg_match().
Development builds should be out shortly.

Cheers,
Deciphered.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.