Highlighted

Help with finding fonts in struct

New Here ,
Nov 30, 2018

Copy link to clipboard

Copied

Hi everyone - this is silly, I know, but...

I'm a designer who can code a bit, and I have issues with font management on my system (I have about 2,000-odd fonts).

so, Cleverdix here decides to quickly write his own ColdFusion font manager, easy peasy.  Import all the font families into a database, add my own delimiters (such as "oh yeah" and "Crap" and  'handwritten") so that when I look for a font, I can run a query, and find the fonts I'm looking for.  Heaven!  Got the database set up, works like a charm.

Except, of course, it does not, because coldfusion doe snot want to render the fonts.

Do a bit of digging, and I find this gem:

<cfset adminObj = createObject("Component", "cfide.adminapi.administrator")>

<cfset adminObj.login("password", "user")>

<cfset rtService = createObject("component", "cfide.adminapi.runtime")>

<cfset fonts = rtService.getFonts()>

Ta-dah! absolutely brilliant - I now have a struct with all my fonts...  within a struct residing in a struct residing in a struct...  4 nested structs, and now I'm as lost as a Polar Bear in Australia.

fontstruct.jpg

Questions:

How do I get the "second key" and the third key, etc, so that I can loop over them and insert them into my database?

with my limited knowledge, I can get the 1st struct key, which returns me "systemfonts" and "userfonts" - as useless as a snooker table on a canie.  I know what the hell that second key is, and the third one, so that I can list all the variables in a way that makes sense to me.

Basic desired outcome is a database that looks sort-of like this:

rowid | font family | font-face | postscript name | path

When I can import the family, face and postscript into my database, I'll be happy as an ant at a picnic.

thank you - thank you - I'll email you a sixpack for your effort.

Views

166

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Help with finding fonts in struct

New Here ,
Nov 30, 2018

Copy link to clipboard

Copied

Hi everyone - this is silly, I know, but...

I'm a designer who can code a bit, and I have issues with font management on my system (I have about 2,000-odd fonts).

so, Cleverdix here decides to quickly write his own ColdFusion font manager, easy peasy.  Import all the font families into a database, add my own delimiters (such as "oh yeah" and "Crap" and  'handwritten") so that when I look for a font, I can run a query, and find the fonts I'm looking for.  Heaven!  Got the database set up, works like a charm.

Except, of course, it does not, because coldfusion doe snot want to render the fonts.

Do a bit of digging, and I find this gem:

<cfset adminObj = createObject("Component", "cfide.adminapi.administrator")>

<cfset adminObj.login("password", "user")>

<cfset rtService = createObject("component", "cfide.adminapi.runtime")>

<cfset fonts = rtService.getFonts()>

Ta-dah! absolutely brilliant - I now have a struct with all my fonts...  within a struct residing in a struct residing in a struct...  4 nested structs, and now I'm as lost as a Polar Bear in Australia.

fontstruct.jpg

Questions:

How do I get the "second key" and the third key, etc, so that I can loop over them and insert them into my database?

with my limited knowledge, I can get the 1st struct key, which returns me "systemfonts" and "userfonts" - as useless as a snooker table on a canie.  I know what the hell that second key is, and the third one, so that I can list all the variables in a way that makes sense to me.

Basic desired outcome is a database that looks sort-of like this:

rowid | font family | font-face | postscript name | path

When I can import the family, face and postscript into my database, I'll be happy as an ant at a picnic.

thank you - thank you - I'll email you a sixpack for your effort.

Views

167

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 30, 2018 0
Adobe Community Professional ,
Dec 01, 2018

Copy link to clipboard

Copied

Hi Jellyhead​,

Here's an idea:

<cfscript>

adminObj = createObject("Component", "cfide.adminapi.administrator");

adminObj.login("password", "user");

rtService = createObject("component", "cfide.adminapi.runtime");

fonts = rtService.getFonts();

/*writedump(fonts);*/

/* In the database, create a table named 'fonts', using SQL similar to the following (MySQL)*/

/*

DROP TABLE IF EXISTS 'fonts';

CREATE TABLE 'fonts' (

  'id' int(11) NOT NULL AUTO_INCREMENT,

  'isSystemFont' tinyint(1) DEFAULT NULL,

  'familyName' varchar(100) DEFAULT NULL,

  'fontName' varchar(100) DEFAULT NULL,

  'description' varchar(100) DEFAULT NULL,

  'fontType' varchar(30) DEFAULT NULL,

  'location' varchar(100) DEFAULT NULL,

  'psname' varchar(100) DEFAULT NULL,

  PRIMARY KEY ('id')

)

*/

/* Create an array corresponding to each column in the database table */

isSystemFont=[];

familyname=[];

fontname=[];

description=[];

fontType=[];

location=[];

psname=[];

rowNumber=1;

for (group in fonts) {

    for (famName in fonts[group]) {

        for (font in fonts[group][famName]) {

            for (fontProperty in fonts[group][famName][font]) {

                switch(fontProperty) {

                    case "description":

                    description[rowNumber]=fonts[group][famName][font][fontProperty];

                    break;

                    case "fonttype":

                    fonttype[rowNumber]=fonts[group][famName][font][fontProperty];

                    break;

                    case "location":

                    location[rowNumber]=fonts[group][famName][font][fontProperty];

                    break;

                    case "psname":

                    psname[rowNumber]=fonts[group][famName][font][fontProperty];

                    break;

                }

            }

            if (group is "SYSTEMFONTS") {

                isSystemFont[rowNumber]=1;

            } else {

                isSystemFont[rowNumber]=0;

            }

            fontname[rowNumber]=font;

            familyname[rowNumber]=famName;

            rowNumber++;

        }

    }

}

/* Create the INSERT SQL string */

sql="insert into fonts (isSystemFont,

                        familyname,

                        fontname,

                        description,

                        fontType,

                        location,

                        psname) values ";

for (i=1; i <= arrayLen(description); i++) {

    if (i > 1) {

        sql=sql & ",";

    }

    /* Replace \ with /, as / is an escape character for some database brands */

    location=replace(location,"\","/","all");

    sql=sql & "          (#isSystemFont#,'#familyname#','#fontname#','#description#','#fontType#','#location#','#psname#')";

}

/* Insert the data into the database table */

sqlParams={};

queryExecute(sql, sqlParams, {datasource="myDSN"});

</cfscript>              

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 01, 2018 2
New Here ,
Dec 02, 2018

Copy link to clipboard

Copied

I've not had time to test it yet, but yes - this is exactly it - thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 02, 2018 0
BKBK LATEST
Adobe Community Professional ,
Dec 04, 2018

Copy link to clipboard

Copied

BKBK wrote:

/* Replace \ with /, as / is an escape character for some database brands */

Please read instead:

/* Replace \ with /, as \ is an escape character for some database brands */

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 04, 2018 0