DropDownList of all system font !!

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Kukurykus, Tom, xbytor

wasfiwasfi
Posts: 45
Joined: Fri Nov 04, 2016 8:29 am

DropDownList of all system font !!

Post by wasfiwasfi »

Hi Guys !!
in scripting UI, is there a way to create a dropDownList that load all system's fonts !!?
this is meant to let me select a font to use later when the script is processing and creating text layers....
Thank you for your help

User avatar
Dormeur74
Posts: 32
Joined: Mon Oct 03, 2016 4:56 am

Re: DropDownList of all system font !!

Post by Dormeur74 »

Hi wasfiwasfi,

Excuse my poor English, I shall try to be as clear as possible.

There is a way to create a font dropdownlist, but there are three problems :
1) DropDownList UI object did not exist before CS2. If the function

Code: Select all

var PhotoshopVersion = parseInt (app.version);
returns a value < 9, you can alert the user that the script will not work.
2) Every font has its own width and height. That's the reason why you cannot use font names. You need to know their family names, then their postscript names. There is a property that returns the postscript names of fonts detected by Photoshop.
3) When you load font names in a DropDownList, there are doublons. You must kill them.

If you need a script that gives you weight and height of a postscript font, I can write one next Thursday.

wasfiwasfi
Posts: 45
Joined: Fri Nov 04, 2016 8:29 am

Re: DropDownList of all system font !!

Post by wasfiwasfi »

Hi Dormeur74

Thank you so much for you quick reply !

Much appreciated :-)

its ok if this is something easy to do, otherwise i don't want to bother you too much :roll:

ps: it is meant to work on PS CS6.

User avatar
Dormeur74
Posts: 32
Joined: Mon Oct 03, 2016 4:56 am

Re: DropDownList of all system font !!

Post by Dormeur74 »

You are lucky, I found my script on the computer I had last year 8-)

Code: Select all


/******************************************************************************************************************************              Author : Michel Rohan (Annecy) - 2015 May 25th - http://www.planete-Blue.net 
********************************************************************************************************************************
DESCRIPTION
********************************************************************************************************************************
This script doesn't work with older versions than CS2 because of dropdown lists that did not exist before.

It lets you choose a Photoshop font family, style and returns its postScript name:

As it is free (open source), you can give it or modify it without any special authorization.
********************************************************************************************************************************/

// enable double clicking from the Macintosh Finder or Windows Explorer
#target photoshop
// in case the user double clicks the script link
app.bringToFront();

// Saves unit preferences of the user to restore them on exit
var unitsRuler = app.preferences.rulerUnits;
var unitsType = app.preferences.typeUnits;

// This script cannot work with Photoshop versions older than CS2 because of the dropdown list object that did not exist before.
var PhotoshopVersion = parseInt (app.version);
if (PhotoshopVersion < 9) {
alert ("Sorry, this script doesn't work with your Photoshop version.");
app.preferences.rulerUnits = unitsRuler;
app.preferences.typeUnits = unitsType;
}
else
{
var dlgBox = new Window('dialog', 'PostScript name Extraction', {x:0, y:0, width:600, height:650});
// It is easier to work in points to avoid resolution conversions
app.preferences.rulerUnits = Units.POINTS;
app.preferences.typeUnits = TypeUnits.POINTS;
main();
}

function main(){
// BEGIN Postscript Police Extraction
var familyListTemp = new Array(); // Temp array to delete doublons
var familyList = new Array(); // Final array without doublons
var styleList = new Array(); // Font styles array

// Loads families list
for(var i=0; i<app.fonts.length; i++) {
familyListTemp[i] = app.fonts[i].family;
}

// Deletes doublons
var k = 0;
for (var i=0;i<familyListTemp.length;i++) {
var doublon = false;
for (var j=i+1;j<familyListTemp.length;j++){
if (familyListTemp[i]==familyListTemp[j]) {
doublon=true;
j=familyListTemp.length-1;
}
}
if (doublon==false) {
familyList[k] = familyListTemp[i];
k+=1;
}
}

familyList.sort(); // Sorts families in the alphanumeric order
fontFamilyList = dlgBox.add("dropdownlist", {x:150, y:14, width:200, height:21}, familyList);
fontFamilyList.helpTip = "Select a family";
sFontFamily = dlgBox.add('statictext',{x:16, y:14, width:130, height:13},"Font family : ");
fontStyleList = dlgBox.add("dropdownlist", {x:150, y:44, width:200, height:21}, styleList);
fontStyleList.helpTip = "Select a style";
sFontStyle = dlgBox.add('statictext',{x:16, y:44, width:130, height:13},"Font style : ");
sPostscript = dlgBox.add('statictext',{x:16, y:76, width:130, height:13},"Postscript name : ");
sPostscript.helpTip = "PostScript name";

postscriptName="Postscript font name";
fontSelected = dlgBox.add ('edittext', {x:150, y:76, width:300, height:21}, postscriptName, { readonly: true });

// Loads types list for the selected family
fontFamilyList.onChange = function()
{
var selectedFamily = fontFamilyList.selection.text;
var styleList = new Array(); // The user can select another font
var m=0;
fontSelected.text = fontSelected.text="Postscript font name";;
for (var i=0; i<app.fonts.length; i++)
{
var style = app.fonts[i].name;
if (app.fonts[i].family==selectedFamily)
{
styleList[m]=app.fonts[i].name;
m++;
}
}
fontStyleList.removeAll();
for (var i=0; i<styleList.length; i++)
{
fontStyleList.add("item",styleList[i]);
}

fontStyleList.onChange = function()
{
var fontSelection = fontStyleList.selection.text;
for (i=0;i<app.fonts.length; i++)
{
if (app.fonts[i].name==fontSelection)
{
postscriptName=app.fonts[i].postScriptName;
}
}
// Displays the postscript name of the selected font
fontSelected.text = postscriptName;
}
}

// END Postscript Police extraction
dlgBox.center();
dlgBox.show();

app.preferences.rulerUnits = unitsRuler;
app.preferences.typeUnits = unitsType;
}

wasfiwasfi
Posts: 45
Joined: Fri Nov 04, 2016 8:29 am

Re: DropDownList of all system font !!

Post by wasfiwasfi »

WOW !!!
Cool
Thank you so much Bro.