Jump to content

Insert multiple graphics from one field


chutchinson

Recommended Posts

I am trying to figure out how I can pull multiple different symbol graphics into a document from one field. The field will be populated with something similar to below

 

Cleaning Codes (field name)

DC W30 CI DNB DNTD (data)

 

So here I would have 5 different graphics. There could be up to 15 unique symbols but a max of 7 displayed at anytime.

 

I do have a font for the symbols but what I'm not sure based on my reading that I can swap say the 'DC' out for a different glyph in a different font.

 

Could FP create extra fields on the fly and populate using a grep function?

Link to comment
Share on other sites

Some kind of mock-up of the output you're trying to make might be worth a thousand words here, but I think I get it.

 

You're talking about what we call inline graphics, which flow with text. Though, based on your comment about having a font with symbols, I don't think you need actual graphics at all. You can definitely replace any of those designations in the field with characters in that font.

 

Without having your font, I have to do some guesswork, but you can do something like this:

var symbols = 
{
   DC: 'g',
   W30: 'w',
   CI: 'c',
   DNB: 'd',
   DNTD: 'n',
   // add any other mappings you want here
};

function GetSymbol(incode)
{
   return symbols[incode] || incode;
}

var codestring = Field("Cleaning Codes");
var codes = codestring.split(/\s/);
return '<f name="Your Font Name">' + codes.map(GetSymbol).join(' ');

Link to comment
Share on other sites

Dan, I was messing around with this rule today and came to the realization that my symbol fonts like "Zapf Dingbats" don't work anymore since upgrading to the new FusionPro version for the Mac. This even applies to saying yes when asked to insert a variable for the font.

 

Correction: It composes correctly with the font but does not preview in the text editor. Message says Bold style not loaded.

Edited by Fellsway
Link to comment
Share on other sites

Dan, I was messing around with this rule today and came to the realization that my symbol fonts like "Zapf Dingbats" don't work anymore since upgrading to the new FusionPro version for the Mac. This even applies to saying yes when asked to insert a variable for the font.

This is a separate issue, which should probably have its own thread. But there were changes to the Text Editor for FP 11 on Mac. As you noted, sometimes the font can't be applied to the selected text, in which case that box will pop up. But that still doesn't guarantee that whatever text you select can be represented in that font.

Correction: It composes correctly with the font but does not preview in the text editor.

Sorry, I don't know what you mean by "preview in the text editor." The editor doesn't do Preview. It will try to show static text and any inserted variable names, but not all characters can be rendered in all fonts. So you need to compose, or Preview (using the Preview Record Selector palette), to see the output.

Message says Bold style not loaded.

That's likely a separate issue as well, probably referring to a different font, but I don't have your job to look at.

Link to comment
Share on other sites

Hi Dan, thanks for your time. I have since found out why the customer uses graphics rather than the font. They have two areas where symbols need to be added from one field but the second source doesn't have a font associated. They also found some characters needed to have a baseline shift for their preference (see attached 1.pdf). With their current system they moved away from fonts.

 

I was able to get the fonts to display with your script but I wasn't able find certain characters 'P' (see first character in 2.pdf). I tried to insert using <unicode gid=true>****</unicode> but nothing came back so not sure I was inserting this correctly.

 

Can the code you have to pull out the Field markers ie 'DC' etc be applied to insert images which would then also be modified and used to pull the images for the second group of icons under 'usage' (see 2.pdf)?

Link to comment
Share on other sites

They also found some characters needed to have a baseline shift for their preference (see attached 1.pdf).

Sorry, I don't see any attachment. Baseline shift is tricky, but you can usually accomplish it with a <superscript> or <subscript> tag. Once you get the images generally working, we can tweak that stuff.

With their current system they moved away from fonts.

Okay, we can use inline graphics instead (see below).

I was able to get the fonts to display with your script but I wasn't able find certain characters 'P' (see first character in 2.pdf). I tried to insert using <unicode gid=true>****</unicode> but nothing came back so not sure I was inserting this correctly.

This is tricky, because you have to know the glyph ID, which is different than the Unicode character code. You would need an application like Font Forge or something else that can display each glyph and its ID to determine what number to put there. And that glyph ID would be specific to that font.

 

But I don't think you need to do any of that, since there's probably a Unicode character code you can use, so that you don't need "gid=true". Also, you should be able to just paste the character into the Rule Editor, in a literal string (in quotes), which is even easier.

Can the code you have to pull out the Field markers ie 'DC' etc be applied to insert images which would then also be modified and used to pull the images for the second group of icons under 'usage' (see 2.pdf)?

Sure, you just insert <graphic> tags to denote inline graphics. These are described in both the User Guide and the Tags Reference (search for "inline"). The first part of the rule would look something like this:

var symbols = 
{
   W30: 'w',
   DC: '<graphic file="pic7.jpg" height=2400>',
   DNB: '<graphic file="pic3.jpg">',
   DNTD: '<graphic file="pic12.jpg" width=1200>',
   // etc.
};

You may need to tweak the width and/or height of each graphic. You can also mix and match regular text for symbols and graphics; it all just gets typeset on the line.

Link to comment
Share on other sites

  • 2 months later...

Hi Dan. The below code you wrote works really well for bringing in each graphic element. The only thing I haven't been able to figure out is the spacing between each object.

 

var symbols =

{

DC: 'g',

W30: 'w',

CI: 'c',

DNB: 'd',

DNTD: 'n',

// add any other mappings you want here

};

 

function GetSymbol(incode)

{

return symbols[incode] || incode;

}

 

var codestring = Field("Cleaning Codes");

var codes = codestring.split(/\s/);

return '<f name="Your Font Name">' + codes.map(GetSymbol).join(' ');

 

With the .join(' '); at the end there is no space between regardless of how many spaces are put in. If you insert a character .join(','); it will put that character in between. I thought I might be able to insert a tab character but no luck. Is there a way to control the spacing with this script?

 

https://owncloud.ricoh.co.nz/index.php/s/c7g89v7tLF5SBto

 

https://owncloud.ricoh.co.nz/index.php/s/6RjdhkT7fZFDGUv

Link to comment
Share on other sites

Your rule has the "Treat returned strings as tagged text" box checked, so that it knows to handle the markup like <f name="Futura"> as typesetting instructions rather than outputting those tags literally. And in tagged markup mode, whitespace like spaces between tags is thrown out.

 

So, you need to specify the spacing as tagged markup as well. For a space you can do this:

return codes.map(GetSymbol).join('&[size="4"]#[/size]32;');

Or, if you don't want to have to figure out the markup:

return codes.map(GetSymbol).join(TaggedTextFromRaw(' '));

And for a tab, just use a <t> tag:

return codes.map(GetSymbol).join('<t>');

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...