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
Community Expert
April 4, 2024
quote

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


By @Manan Joshi

 

You want to modify InDesign's underbelly - but without going DEEP into SDK - you can't.

 

You won't be able to do in JavaScript what I've done with my tool - use InDesign as a "rendering engine" - but maybe partially you could do something similar?

 

Create your own set of pallets?

 


I am willing to go as deep the SDK allows. I am not averse to using the C++ SDK infact that has been my main go to tool as I started developing for InDesign using the C++. But for this problem I am not able to find any solution in the SDK that I could figure out.

-Manan

-Manan