Skip to main content
Community Expert
April 4, 2024
Question

Create custom font filter

  • April 4, 2024
  • 3 replies
  • 2099 views

So the requirement is to display only some fonts in the various font dropdowns to restrict the user to use only those and prevent the clutter of all the other fonts. I thought maybe a filter could help in trying to do this but I did not find anything in the C++ SDK regarding the font filter or any other way where we could restrict the fonts displayed. Is this possible? Any other ideas

-Manan

This topic has been closed for replies.

3 replies

Legend
April 8, 2024

Sounds like a very useful PlugIn. I searched the SDK, I didn't see anything obvious. I wonder if the way document fonts are handled, might be a clue.

 

P.

Community Expert
April 4, 2024

The best I could come up with is to give a dropdown list of fonts allowed - select the text frame - run the script - and select the font.

It's jsx - but not really sure how else to go about it - just an idea.

 

// Define an array of allowed font names
var allowedFonts = ["Arial", "Helvetica", "Times New Roman", "Verdana"];

// Function to create and display a dialog box with dropdowns for font selection
function showDialog() {
    // Create a new dialog box
    var dialog = app.dialogs.add({ name: "Font Selector" });
    
    // Create a dialog column
    var dialogColumn = dialog.dialogColumns.add();
    
    // Create a dropdown control for font selection
    var fontDropdown = dialogColumn.dropdowns.add({
        stringList: allowedFonts
    });
    
    // Display the dialog box
    var result = dialog.show();
    
    // Check if the user clicked OK
    if (result == true) {
        // Get the selected font from the dropdown
        var selectedFont = fontDropdown.stringList[fontDropdown.selectedIndex];
        
        // Apply the selected font to the text
        applyFont(selectedFont);
    }
    
    // Close the dialog box
    dialog.destroy();
}

// Function to apply the selected font to a text frame
function applyFont(fontName) {
    // Check if there is a text frame selected
    if (app.selection.length > 0 && app.selection[0] instanceof TextFrame) {
        // Apply the font to the text frame
        app.selection[0].texts[0].appliedFont = app.fonts.itemByName(fontName);
    } else {
        // If no text frame is selected, display an error message
        alert("Please select a text frame before applying the font.");
    }
}

// Call the function to display the dialog box
showDialog();

 

Community Expert
April 4, 2024

Thanks @Eugene Tyson I am looking for more deeper integration so that the user is given only these fonts as choice if possible at different places where we can make font selection in the InDesign UI. Scripting won't be able to make changes in the native UI

-Manan

-Manan
Community Expert
April 4, 2024

Yeh there's so many places you can choose a font from - I can't think of a way other than invoking a panel instead of allowing a user to click a button in the ui.

 

I will keep trying to explore this - but I don't have high hopes, I mean if you can't find a way I doubt I will. But it's an interesting one for me too.

Robert at ID-Tasker
Legend
April 4, 2024

You mean built in UI dropdowns?

 

If you are building your own tool - why not create your own dropdown with a "restricted" list of fonts.

 

Community Expert
April 4, 2024

I am building my own solution. But if I go ahead with creating my own list in my own dialog then how would I provide the user with the capabiltiy to use only the short list of fonts in different places of InDesign UI like styles panel etc. This would need a deeper integration using InDesign SDK if that is even possible

-Manan

-Manan
Robert at ID-Tasker
Legend
April 8, 2024

Thanks @Robert at ID-Tasker for sharing your outlook. Yeah that is one benefit but then you lose out on platform comaptibility. Your solution would lack support for MAC. I would prefer to use JS because that one code works both on MAC and WIN and for things that you get for "running outside" we can use VB and Applescript repectively. By the way MAC supports JS automations as well.

Also "less hassle than plugins" is right but limited in firepower as well. Scripting can't match the capabilities/speed of C++ plugins at all. So different tools can't be compared as such in my opinion

-Manan


 

@Manan Joshi 

 

Mac support - directly - no - indirectly - a dedicted PC connected to Mac network - yes.

 

"running outside" - but your VB / AS solution will still be run "from inside" so you won't be able to achieve low-level system integration.

 

"less hassle than plugins" - I'm only limited in terms of speed - when processing a single INDD file (*) - and if you want to add some "native" new objects - otherwise, I can easily add a new functionality.

 

I can do real multithreading - (*) modify multiple INDD files - at the same time - using the same installation of InDesign...