Consistent baseline position for text

Matthew Davidson - January 23, 2008 - 07:26
Project:Signwriter
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Could there be a way of specifying that the baseline of the text is at a particular number of pixels from the top of the image? Here's what I'm trying to do:

<?php

if (!empty($title)) {
 
$profile = signwriter_load_profile('Page Title');
 
$title_words = explode(' ',$title);
  foreach (
$title_words as $word) {
   
$title_images[] = signwriter_title_convert($word,$profile);
  }
 
$signwriter_title = implode(' ',$title_images);
}
?>

The purpose of this is to be able to sit the images inline and have them wrap like real text.

This is fine as long as either all or none of the words have an upper-case letter. The images generated by signwriter have the text positioned at the top of the image, regardless of the maximum possible height of a character. You can't get around this by positioning the image elements using HTML/CSS (lining up the bottoms of the images) without running into the same problem with 'p's and 'q's.

#1

Matthew Davidson - January 30, 2008 - 02:28
Version:5.x-1.1» 5.x-1.x-dev
Status:active» needs review

Here's a patch to add this feature. Because you might think of this as creating larger than necessary images under certain circumstances (I don't - I think you need the extra space below the baseline to maintain a consistent line-height), you might want to make this optional.

I also added the necessary x offset to the imagettftext() function call to account for images where the bottom left of the image would be to the left of the leftmost point at the baseline, for instance an image starting with a lowercase letter 'y' in an italic font.

AttachmentSize
signwriter-multi_image_baseline_and_x_offset_for_italics.patch 1.21 KB

#2

Matthew Davidson - May 17, 2008 - 23:43

Updated to accommodate accented capital letters, thanks to lucoweb.

AttachmentSize
signwriter-multi_image_baseline_and_x_offset_for_italics-2.patch 1.26 KB

#3

solaas - May 23, 2008 - 21:36

I recently posted a patch with a different approach to this problem. Instead of generating multiple images, it processes the text and renders it in as many lines as necessary within the given width in a single image.

You can take a look at #260469: Multiline support

#4

rooby - September 2, 2008 - 13:03
Status:needs review» fixed

Hi Matthew,

Thanks for the patch.

Solaas' patch for multiline images has now been rolled into the 5.x-1.2 release so that should give you the functionality you are looking for.

Reuben.

#5

Matthew Davidson - September 2, 2008 - 20:37

Actually the multiline images patch is only of benefit if you know the width of the element in pixels in advance; it doesn't solve the problem for fluid layouts. The benefit of my approach is you get real word wrapping. Is there any chance you'd be willing to contemplate incorporating both mechanisms as options? I can come up with a way to do it (might take a while before I get to it, though).

#6

Justin W Freeman - September 5, 2008 - 01:19

5.x-1.3 is now available and has this patch applied. At this stage it is not an option, the code is always used because it doesn't seem to have any negative affect on anything.

#7

Anonymous (not verified) - September 19, 2008 - 01:22
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.