The Signwriter module allows you to use TrueType fonts to replace text in headings, blocks, menus and filtered text. It does this by replacing text with an image generated from a TrueType font file which you provide. Note: Signwriter requires the GD library to function.

Signwriter has a number of features:

  • Multiple profiles allow you to have different settings for different headings.
  • Profiles can provide input filters to replace text matching a regular expression.
  • Images generated can be transparent or opaque.
  • Text can be positioned within a background image.
  • Text can be left, right, or center aligned.
  • Font size can be automatically reduced to fit the text within a specified maximum width.
  • Images are cached to improve performance under high load.
  • Generated images can be gif, png, jpeg, or bmp.
  • Themes can use profiles configured by a user, or create their own.
  • To fit text within a maximum width you can select to display multiple lines instead of reducing font size.
  • Drop shadows can be added to the text.

Font File Names

Please note that font file names, including the file name extension (.ttf) should all be in lowercase when using Signwriter. Otherwise Signwriter will not detect the file. See http://drupal.org/node/342280

The GD Image Library

Signwriter uses the GD Image library. GD comes installed by default in PHP >= 4.3, but can be enabled at compile time in earlier versions. If your PHP installation is on Windows, try uncommenting the line which reads 'extension=php_gd2.dll' in your php.ini.

Usage

You can use Signwriter to:

  1. Create a input filter to replace headings or custom tags in node text
  2. To generate headings in a theme
  3. To create menu heading and items
  4. To create block headings

You can create Signwriter profiles or create an on-the-fly profile and display the output in your template file or PHP.

Creating Profiles Under Drupal

A Signwriter profile is a collection of settings which can be used to create an image. To manage your profiles, go to admin>>settings>>signwriter. From here you can add, delete, or edit profiles. If you add or edit a profile, you will be taken to a profile settings page. On each profile settings page there are a number of options which may be set, each of which is explained on that page.

Using Filters

If a Signwriter profile has a pattern defined then it will be available as an input filter under admin>>input formats. After enabling the filter, any text matched by the pattern will be replaced with a Signwriter image.

Example: Replacing h2 headings in nodes

  1. Create a profile under admin>>settings>>signwriter called 'H2 Filter', making sure to enter /<h2>.*?<\/h2>/ under 'Pattern to Match When Used as a Filter'. There are some example patterns on the page.
  2. Go to admin>>input formats and edit your input format of choice. There should be an option to enable 'H2 Filter'.
  3. After enabling the filter, create a new page using your input format of choice. Make sure you put in at least one h2 heading: <h2>Signwriter filter test</h2>.
  4. Your headings should be replaced by Signwriter images in the submitted page.

Theme Development

To use Signwriter in a theme you have two options to configure it. You can enable the module in Drupal and configure it on the admin>>settings>>signwriter page by adding one or more profiles, or you can create profiles yourself using PHP.

Creating and Loading Profiles in php

If you are administering your profiles under Drupal, then in your theme code you will want to load one like this:
$profile = Signwriter_load_profile('Example Profile');
Note that you can pass a profile name or id to signwriter_load_profile().
As a PHP object, a Signwriter profile has the following fields, most of which correspond to a setting on the edit profile form:

$profile->text //The text to display. Can contain html entities.
                //For example, &amp; will be displayed as &
$profile->fontfile
$profile->fontsize
$profile->foreground
$profile->background
$profile->width
$profile->height
$profile->maxwidth
$profile->imagetype
$profile->cachedir // defaults to <Drupaldir>/signwriter-cache
$profile->textalign
$profile->transparent
$profile->bgimage
$profile->xoffset
$profile->yoffset

Any of these fields can be overridden in the theme after loading the profile.

If you want to create a profile from scratch then you will at least need to define $profile->fontfile all other settings will revert to defaults if not set. An advantage to creating the profile from scratch is that the module doesn't need to be enabled, and meddlesome users can't ruin your nice headings.

After you have loaded or created a profile you can use signwriter_title_convert or signwriter_text_convert to replace, for example, your $title in page.tpl.php (if you're using phptemplate).

Example 1: Replacing the page title in your theme

Note: This example is deprecated now and here for reference only. Signwriter 6.x now has an settings option can now be set to replace all page titles.

  1. Create a Signwriter profile in Drupal called 'Theme Heading', and assign the other settings to your liking.
  2. In your phptemplate theme add the following code to your page.tpl.php where you want to print the page title:
    if ($title != '') {
        $profile = signwriter_load_profile('Theme Heading');
        // at this point you could override any settings. for example:
        // $profile->fontsize = 43; // override the font size
        print signwriter_title_convert($title, $profile);
    }
    
  3. Refresh the page in Drupal and your title should appear in your custom font.

Example 2: Using Signwriter without configuring it in Drupal

  1. Add your custom font to your theme directory. In this example we'll use Arial.ttf.
  2. In your phptemplate theme add the following code to your page.tpl.php:
    if ($title != '') {
        $profile->fontfile = 'Arial';
        $profile->fontsize = 15;
        $profile->foreground = 'ff0000'; // red
        $profile->background = 'ffffff'; // white. If your text is jagged then change this to your page background colour
        $profile->maxwidth = 600;
        $profile->transparent = true;
        print signwriter_title_convert($title, $profile);
    }
    
  3. Refresh the page in Drupal and your title should appear in red Arial size 15 text.

Example 3: Using Signwriter for block titles

Note: This example is deprecated now and here for reference only. Signwriter 6.x now has an settings option can now be set to replace all block titles.

  1. Create a Signwriter profile called 'Block title'
  2. In your block.tpl.php, replace the code that prints your block subject with the following:
    $signwriter = signwriter_load_profile('Block title');
    $signwriter->text = $block->subject;
    $url = signwriter_url($signwriter);
    print '<img src="'. $url .'" alt="'. $block->subject .'" />';
    
  3. All block titles should now use your new Signwriter profile.

Thanks to momper for this example.

Example 4: How to change the colour of the output depending on taxonomy values on a node.

From #335767: How to alter the processing of signwriter_filter depending on a template variable ?

  1. Create a Signwriter profile in Drupal called 'Taxonomy' (or whatever name makes sense to you).
  2. Assign the profile settings as you require.
  3. Create a Vocabulary and some associated Taxonomy Terms
  4. In your phptemplate theme add the following code to your node.tpl.php where you want to print the page title (or other variable):
        $profile = signwriter_load_profile('Taxonomy');
    //Insert your own taxonomy logic here - this is just an example
    //This will locate term id 3 and alter the foreground colour
    if (array_key_exists(3, $node->taxonomy)) {
       $profile->foreground = 'ff0000';
    } else {
       $profile->foreground = '01e41a';
    }
    //Replace the $title value with whatever you want to output
        print signwriter_title_convert($title, $profile);
    
  5. Refresh the page in Drupal and your title should appear with a different colour based on the taxonomy term selected.

Example5: Signwriter for views nodes title

Here's how to get the node's titles within a view to work with signwriter. You'll have to make a tpl file for it in the end...kind of a drag but here we go:

1. The titles cannot be used as part of a global text. It has to be the just node title field straight up.

2. Make a file views-view-field--products-grid-display--title.tpl.php where "products-grid-display" was my view, and producttitles was my signwriter profile name.

3. Content of said file:

<?php 
$signwriter = signwriter_load_profile('producttitles');
$data = $row->{$field->field_alias};
$output = theme_signwriter_text($data, $signwriter);
print $output; 
?>

Comments

teejaydub’s picture

Don't know if this is useful to others, but it's something I needed. I added this to my (zen-based) theme's template.php file:

function lightning_menu_item_link($link) {  // theme name is 'lightning'
  if ($link['menu_name'] == 'primary-links') {
    if (empty($link['localized_options'])) {
      $link['localized_options'] = array();
    }
    
    $profile = signwriter_load_profile('Big Links');  // Or whatever your profile name is.
    $link['localized_options']['html'] = TRUE;  // Because we'll be sending HTML into the l() call.
    return l(theme_signwriter_text($link['title'], $profile), $link['href'], $link['localized_options']);
  } else
    return zen_menu_item_link($link);  // Use the inherited behavior for everything else.
}

--tjw

eeeb’s picture

I just wanted to note for any future users banging their head on this issue that I was able to get the primary links to finally work with Signwriter when I added the primary links into a block and displayed the block in a particular section on my page, and then commented out the primary links being called in the page.tlp.php file.

adraskoy’s picture

I had no luck with the signwriter_url function given in the above examples, as it didn't seem to be defined. I got it working using theme_signwriter_text() and simply called it from my theme's template.php file.

This example is for:
1) a zen subtheme called "zensubtheme"
2) a CCK field called "field_tag_line"
3) a view called "myview" sorted by another CCK field called "field_day_number"
4) a signwriter profile named "Headers"

You might want to try and see what the possible fields are by returning print_r($row, true) instead of the function content given here.

function zensubtheme_views_view_field__myview__field_tag_line_value($view, $field, $row) {
  $signwriter = signwriter_load_profile('Headers');
  $text = $row->node_data_field_day_number_field_tag_line_value;
  $html = theme_signwriter_text($text, $signwriter);
  return $html;
}
adamarthurryan’s picture

The signwriter_url function didn't work for me either - it doesn't seem to exist in signwriter anymore. I used signwriter_image($text, $profile) instead to get an image URL. Is there any problem with that?

Davinia’s picture

Can anyone help me out here?
What do I have to do to get signwriter to give my secondary links a custom font?

The function seems to be there in the settings, but it does not give options to activate: http://www.davinia.nl/temp/problem.jpg

P2790’s picture

Cannot get example 5 to work. I created a file:

views-view-field--frontpage--title.tpl

With exactly the content shown, nothing else:

<?php
$signwriter = signwriter_load_profile('producttitles');
$data = $row->{$field->field_alias};
$output = theme_signwriter_text($data, $signwriter);
print $output;
?>

Nothing happened, I feel like I'm doing something wrong. I just want to have the titles of nodes in my front page to be consistent with the rest of my site. I need signwriter to be able change these node titles, can it do this?

Thanks

g76’s picture

I have a frontpage panel page with a views testimonial slideshow block(sorted by nodequeue order) using skinr styles. I just need the node title of the testimonials changed. I am not a coder so I could really use some help. I will primarily be using signwriter for cck fields in views.

UPDATE: SOLUTION

This is probably not the #1 solution, but I found a workaround. I used the Views Custom Field module (http://drupal.org/project/views_customfield) and added a markup field with a custom input format(for signwriter profile input filter for h1 headers) selected. Then I selected "rewrite the output of this field" and entered <h1>[title]</h1>. You must have token to reference the node title in the replacement pattern. Also, in your title field select "exclude from display" and reorder your fields with the markup field in the same ordering as your title.

vthirteen’s picture

the example #5 does work for me (Signwriter 6.x-2.0-beta2)

@g76
i was trying to do the same (without Views Custom Field): i defined a custom input filter in signwriter /<h5.*>.*?<\/h5>/
then rewrite the output of the field, wrapping a views field tokenized as [title] in some html tag (h5 in my case): <h5>[title]</h5>

but it doesn't work. the h5 tag is output correctly as html but no signwriter image is created.

EDIT: flushing the cache did it.

vthirteen’s picture

the expected behavior of Signwriter is that the h5 tag (as any other headings tag) only works within a node.

ed523’s picture

tried adding the above to my zen based tpl.php but still no signwriter primary menu, as well as using the primary menu block. any other ideas?