Skip to main content
Participant
January 13, 2013
Question

How to set multi fonts in one textItem?

  • January 13, 2013
  • 3 replies
  • 1986 views

I have a textItem with Chinese & English. I want to set Chinese and English in different fonts, but the script can only set one font. So, when I set the textItem in western fonts, the Chinese can't display correctly (display block). When I set it to Chinese fonts, the English letters display in Chinese font.

Is there anyway to fix this problem?

I use the Photoshop's original tools to set Chinese font first and set western font again, the font of English letters in textItem will change to the western font and the Chinese text will keep the Chinese font I set first time. I wonder is there the same way to set font with script?

Thx guys.

This topic has been closed for replies.

3 replies

c.pfaffenbichler
Community Expert
Community Expert
January 21, 2013

So was the code I posted useful to you or not?

Participant
January 22, 2013

Hi   Thank you so much for posting the code. I tried it and It's amazing .

But I just a beginner of script, it's a little hard to understand the code, I'll study more. And my work is too busy these days, I will tell you when I spend more time on it and get progress.

Thx again~~

c.pfaffenbichler
Community Expert
Community Expert
January 22, 2013

One could edit the Script to allow for using more parameters than text, font and size, but creating or editing Type Layers with complex content is not very convenient with Scripting.

c.pfaffenbichler
Community Expert
Community Expert
January 13, 2013

This might serve as an example:

// create a type layer with more than one font;

// 2013, use at your own risk;

#target photoshop

if (app.documents.length > 0) {

var theText = [

["this is a text", 12, "Helvetica"],

["this is another font", 15, "Times-Roman"]

];

// create;

createPointTextMoreCompl (theText, 50, 50);

};

////// create point text layer //////

function createPointTextMoreCompl (theArray, theX, theY) {

if (theArray[0].length > 0) {

// join the texts;

var theText =  new String;

for (var m = 0; m < theArray.length; m++) {

theText = theText + " " + theArray[0]

};

// =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc4 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idTxLr = charIDToTypeID( "TxLr" );

        ref2.putClass( idTxLr );

    desc4.putReference( idnull, ref2 );

    var idUsng = charIDToTypeID( "Usng" );

        var desc5 = new ActionDescriptor();

        var idTxt = charIDToTypeID( "Txt " );

// text;

        desc5.putString( idTxt, theText );

        var idwarp = stringIDToTypeID( "warp" );

            var desc6 = new ActionDescriptor();

            var idwarpStyle = stringIDToTypeID( "warpStyle" );

            var idwarpStyle = stringIDToTypeID( "warpStyle" );

            var idwarpNone = stringIDToTypeID( "warpNone" );

            desc6.putEnumerated( idwarpStyle, idwarpStyle, idwarpNone );

            var idwarpValue = stringIDToTypeID( "warpValue" );

            desc6.putDouble( idwarpValue, 0.000000 );

            var idwarpPerspective = stringIDToTypeID( "warpPerspective" );

            desc6.putDouble( idwarpPerspective, 0.000000 );

            var idwarpPerspectiveOther = stringIDToTypeID( "warpPerspectiveOther" );

            desc6.putDouble( idwarpPerspectiveOther, 0.000000 );

            var idwarpRotate = stringIDToTypeID( "warpRotate" );

            var idOrnt = charIDToTypeID( "Ornt" );

            var idHrzn = charIDToTypeID( "Hrzn" );

            desc6.putEnumerated( idwarpRotate, idOrnt, idHrzn );

        var idwarp = stringIDToTypeID( "warp" );

        desc5.putObject( idwarp, idwarp, desc6 );

// position;

        var idTxtC = charIDToTypeID( "TxtC" );

            var desc7 = new ActionDescriptor();

            var idHrzn = charIDToTypeID( "Hrzn" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc7.putUnitDouble( idHrzn, idPrc, theX );

            var idVrtc = charIDToTypeID( "Vrtc" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc7.putUnitDouble( idVrtc, idPrc, theY );

        var idPnt = charIDToTypeID( "Pnt " );

        desc5.putObject( idTxtC, idPnt, desc7 );

        var idtextGridding = stringIDToTypeID( "textGridding" );

        var idtextGridding = stringIDToTypeID( "textGridding" );

        var idNone = charIDToTypeID( "None" );

        desc5.putEnumerated( idtextGridding, idtextGridding, idNone );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idHrzn = charIDToTypeID( "Hrzn" );

        desc5.putEnumerated( idOrnt, idOrnt, idHrzn );

        var idAntA = charIDToTypeID( "AntA" );

        var idAnnt = charIDToTypeID( "Annt" );

        var idantiAliasSharp = stringIDToTypeID( "antiAliasSharp" );

        desc5.putEnumerated( idAntA, idAnnt, idantiAliasSharp );

        var idtextShape = stringIDToTypeID( "textShape" );

            var list1 = new ActionList();

                var desc8 = new ActionDescriptor();

                var idTEXT = charIDToTypeID( "TEXT" );

                var idTEXT = charIDToTypeID( "TEXT" );

                var idPnt = charIDToTypeID( "Pnt " );

                desc8.putEnumerated( idTEXT, idTEXT, idPnt );

                var idOrnt = charIDToTypeID( "Ornt" );

                var idOrnt = charIDToTypeID( "Ornt" );

                var idHrzn = charIDToTypeID( "Hrzn" );

                desc8.putEnumerated( idOrnt, idOrnt, idHrzn );

                var idTrnf = charIDToTypeID( "Trnf" );

                    var desc9 = new ActionDescriptor();

                    var idxx = stringIDToTypeID( "xx" );

                    desc9.putDouble( idxx, 1.000000 );

                    var idxy = stringIDToTypeID( "xy" );

                    desc9.putDouble( idxy, 0.000000 );

                    var idyx = stringIDToTypeID( "yx" );

                    desc9.putDouble( idyx, 0.000000 );

                    var idyy = stringIDToTypeID( "yy" );

                    desc9.putDouble( idyy, 1.000000 );

                    var idtx = stringIDToTypeID( "tx" );

                    desc9.putDouble( idtx, 0.000000 );

                    var idty = stringIDToTypeID( "ty" );

                    desc9.putDouble( idty, 0.000000 );

                var idTrnf = charIDToTypeID( "Trnf" );

                desc8.putObject( idTrnf, idTrnf, desc9 );

                var idrowCount = stringIDToTypeID( "rowCount" );

                desc8.putInteger( idrowCount, 1 );

                var idcolumnCount = stringIDToTypeID( "columnCount" );

                desc8.putInteger( idcolumnCount, 1 );

                var idrowMajorOrder = stringIDToTypeID( "rowMajorOrder" );

                desc8.putBoolean( idrowMajorOrder, true );

                var idrowGutter = stringIDToTypeID( "rowGutter" );

                var idPnt = charIDToTypeID( "#Pnt" );

                desc8.putUnitDouble( idrowGutter, idPnt, 0.000000 );

                var idcolumnGutter = stringIDToTypeID( "columnGutter" );

                var idPnt = charIDToTypeID( "#Pnt" );

                desc8.putUnitDouble( idcolumnGutter, idPnt, 0.000000 );

                var idSpcn = charIDToTypeID( "Spcn" );

                var idPnt = charIDToTypeID( "#Pnt" );

                desc8.putUnitDouble( idSpcn, idPnt, 0.000000 );

                var idframeBaselineAlignment = stringIDToTypeID( "frameBaselineAlignment" );

                var idframeBaselineAlignment = stringIDToTypeID( "frameBaselineAlignment" );

                var idalignByAscent = stringIDToTypeID( "alignByAscent" );

                desc8.putEnumerated( idframeBaselineAlignment, idframeBaselineAlignment, idalignByAscent );

                var idfirstBaselineMinimum = stringIDToTypeID( "firstBaselineMinimum" );

                var idPnt = charIDToTypeID( "#Pnt" );

                desc8.putUnitDouble( idfirstBaselineMinimum, idPnt, 0.000000 );

                var idbase = stringIDToTypeID( "base" );

                    var desc10 = new ActionDescriptor();

                    var idHrzn = charIDToTypeID( "Hrzn" );

                    desc10.putDouble( idHrzn, 0.000000 );

                    var idVrtc = charIDToTypeID( "Vrtc" );

                    desc10.putDouble( idVrtc, 0.000000 );

                var idPnt = charIDToTypeID( "Pnt " );

                desc8.putObject( idbase, idPnt, desc10 );

            var idtextShape = stringIDToTypeID( "textShape" );

            list1.putObject( idtextShape, desc8 );

        desc5.putList( idtextShape, list1 );

        var idTxtt = charIDToTypeID( "Txtt" );

            var list2 = new ActionList();

                var desc11 = new ActionDescriptor();

                var idFrom = charIDToTypeID( "From" );

// from;

                desc11.putInteger( idFrom, 0 );

                var idT = charIDToTypeID( "T   " );

// to;

                desc11.putInteger( idT, theArray[0][0].length + 1);

                var idTxtS = charIDToTypeID( "TxtS" );

                    var desc12 = new ActionDescriptor();

                    var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );

                    desc12.putBoolean( idstyleSheetHasParent, true );

                    var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );

// font;

                    desc12.putString( idfontPostScriptName, theArray[0][2] );

/*                    var idFntN = charIDToTypeID( "FntN" );

                    desc12.putString( idFntN, """Arial""" );

                    var idFntS = charIDToTypeID( "FntS" );

                    desc12.putString( idFntS, """Regular""" );*/

                    var idScrp = charIDToTypeID( "Scrp" );

                    desc12.putInteger( idScrp, 0 );

                    var idFntT = charIDToTypeID( "FntT" );

                    desc12.putInteger( idFntT, 1 );

                    var idSz = charIDToTypeID( "Sz  " );

                    var idPnt = charIDToTypeID( "#Pnt" );

// size;

//                    desc12.putUnitDouble( idSz, idPnt, theArray[0][1] * (Math.random() * 0.4 + 0.8) );

                    desc12.putUnitDouble( idSz, idPnt, theArray[0][1] );

                    var idTrck = charIDToTypeID( "Trck" );

                    desc12.putInteger( idTrck, 15 );

                    var iddigitSet = stringIDToTypeID( "digitSet" );

                    var iddigitSet = stringIDToTypeID( "digitSet" );

                    var iddefaultDigits = stringIDToTypeID( "defaultDigits" );

                    desc12.putEnumerated( iddigitSet, iddigitSet, iddefaultDigits );

                    var idmarkYDistFromBaseline = stringIDToTypeID( "markYDistFromBaseline" );

                    var idPnt = charIDToTypeID( "#Pnt" );

                    desc12.putUnitDouble( idmarkYDistFromBaseline, idPnt, 5.760000 );

                    var idtextLanguage = stringIDToTypeID( "textLanguage" );

                    var idtextLanguage = stringIDToTypeID( "textLanguage" );

                    var idgermanLanguageReformedonenineninesix = stringIDToTypeID( "germanLanguageReformed1996" );

                    desc12.putEnumerated( idtextLanguage, idtextLanguage, idgermanLanguageReformedonenineninesix );

                    var idClr = charIDToTypeID( "Clr " );

                        var desc13 = new ActionDescriptor();

                        var idRd = charIDToTypeID( "Rd  " );

                        desc13.putDouble( idRd, 0 );

                        var idGrn = charIDToTypeID( "Grn " );

                        desc13.putDouble( idGrn, 0 );

                        var idBl = charIDToTypeID( "Bl  " );

                        desc13.putDouble( idBl, 0 );

                    var idRGBC = charIDToTypeID( "RGBC" );

                    desc12.putObject( idClr, idRGBC, desc13 );

                var idTxtS = charIDToTypeID( "TxtS" );

                desc11.putObject( idTxtS, idTxtS, desc12 );

            var idTxtt = charIDToTypeID( "Txtt" );

            list2.putObject( idTxtt, desc11 );

// if more than one array;

// add the string’s lengths;

var theCounter = theArray[0][0].length + 1;

for (var n = 1; n < theArray.length; n++) {

                var desc14 = new ActionDescriptor();

                var idFrom = charIDToTypeID( "From" );

// from;

                desc14.putInteger( idFrom, theCounter );

                var idT = charIDToTypeID( "T   " );

theCounter = theCounter + 1 + theArray[0].length;

// to;

                desc14.putInteger( idT, theCounter );

                var idTxtS = charIDToTypeID( "TxtS" );

                    var desc15 = new ActionDescriptor();

                    var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );

                    desc15.putBoolean( idstyleSheetHasParent, true );

                    var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );

// font;

                    desc15.putString( idfontPostScriptName, theArray[2] );

                    var idScrp = charIDToTypeID( "Scrp" );

                    desc15.putInteger( idScrp, 0 );

                    var idFntT = charIDToTypeID( "FntT" );

                    desc15.putInteger( idFntT, 0 );

                    var idSz = charIDToTypeID( "Sz  " );

                    var idPnt = charIDToTypeID( "#Pnt" );

// size;

                    desc15.putUnitDouble( idSz, idPnt, theArray[1] );

                    var idTrck = charIDToTypeID( "Trck" );

                    desc15.putInteger( idTrck, 15 );

                    var iddigitSet = stringIDToTypeID( "digitSet" );

                    var iddigitSet = stringIDToTypeID( "digitSet" );

                    var iddefaultDigits = stringIDToTypeID( "defaultDigits" );

                    desc15.putEnumerated( iddigitSet, iddigitSet, iddefaultDigits );

                    var idmarkYDistFromBaseline = stringIDToTypeID( "markYDistFromBaseline" );

                    var idPnt = charIDToTypeID( "#Pnt" );

                    desc15.putUnitDouble( idmarkYDistFromBaseline, idPnt, 5.760000 );

                    var idtextLanguage = stringIDToTypeID( "textLanguage" );

                    var idtextLanguage = stringIDToTypeID( "textLanguage" );

                    var idgermanLanguageReformedonenineninesix = stringIDToTypeID( "germanLanguageReformed1996" );

                    desc15.putEnumerated( idtextLanguage, idtextLanguage, idgermanLanguageReformedonenineninesix );

                    var idClr = charIDToTypeID( "Clr " );

                        var desc16 = new ActionDescriptor();

                        var idRd = charIDToTypeID( "Rd  " );

                        desc16.putDouble( idRd, 0 );

                        var idGrn = charIDToTypeID( "Grn " );

                        desc16.putDouble( idGrn, 0 );

                        var idBl = charIDToTypeID( "Bl  " );

                        desc16.putDouble( idBl, 0 );

                    var idRGBC = charIDToTypeID( "RGBC" );

                    desc15.putObject( idClr, idRGBC, desc16 );

                var idTxtS = charIDToTypeID( "TxtS" );

                desc14.putObject( idTxtS, idTxtS, desc15 );

            var idTxtt = charIDToTypeID( "Txtt" );

            list2.putObject( idTxtt, desc14 );

          };

        desc5.putList( idTxtt, list2 );

////////////////////////////////////

        var idparagraphStyleRange = stringIDToTypeID( "paragraphStyleRange" );

            var list3 = new ActionList();

                var desc17 = new ActionDescriptor();

                var idFrom = charIDToTypeID( "From" );

                desc17.putInteger( idFrom, 0 );

                var idT = charIDToTypeID( "T   " );

// to;

                desc17.putInteger( idT, theText.length*2);

                var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );

                    var desc18 = new ActionDescriptor();

                    var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );

                    desc18.putBoolean( idstyleSheetHasParent, true );

                    var idAlgn = charIDToTypeID( "Algn" );

                    var idAlg = charIDToTypeID( "Alg " );

                    var idCntr = charIDToTypeID( "Cntr" );

                    desc18.putEnumerated( idAlgn, idAlg, idCntr );

                    var idhyphenate = stringIDToTypeID( "hyphenate" );

                    desc18.putBoolean( idhyphenate, true );

                    var idhyphenateWordSize = stringIDToTypeID( "hyphenateWordSize" );

                    desc18.putInteger( idhyphenateWordSize, 8 );

                    var idhyphenatePreLength = stringIDToTypeID( "hyphenatePreLength" );

                    desc18.putInteger( idhyphenatePreLength, 3 );

                    var idhyphenatePostLength = stringIDToTypeID( "hyphenatePostLength" );

                    desc18.putInteger( idhyphenatePostLength, 3 );

                    var idhyphenateLimit = stringIDToTypeID( "hyphenateLimit" );

                    desc18.putInteger( idhyphenateLimit, 2 );

                    var idhyphenationZone = stringIDToTypeID( "hyphenationZone" );

                    desc18.putDouble( idhyphenationZone, 36.000000 );

                    var idhyphenateCapitalized = stringIDToTypeID( "hyphenateCapitalized" );

                    desc18.putBoolean( idhyphenateCapitalized, true );

                    var idburasagari = stringIDToTypeID( "burasagari" );

                    var idburasagari = stringIDToTypeID( "burasagari" );

                    var idburasagariStandard = stringIDToTypeID( "burasagariStandard" );

                    desc18.putEnumerated( idburasagari, idburasagari, idburasagariStandard );

                    var idtextEveryLineComposer = stringIDToTypeID( "textEveryLineComposer" );

                    desc18.putBoolean( idtextEveryLineComposer, true );

                var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );

                desc17.putObject( idparagraphStyle, idparagraphStyle, desc18 );

            var idparagraphStyleRange = stringIDToTypeID( "paragraphStyleRange" );

            list3.putObject( idparagraphStyleRange, desc17 );

        desc5.putList( idparagraphStyleRange, list3 );

        var idkerningRange = stringIDToTypeID( "kerningRange" );

            var list4 = new ActionList();

        desc5.putList( idkerningRange, list4 );

    var idTxLr = charIDToTypeID( "TxLr" );

    desc4.putObject( idUsng, idTxLr, desc5 );

executeAction( idMk, desc4, DialogModes.NO );

}

};

c.pfaffenbichler
Community Expert
Community Expert
January 13, 2013

I have a textItem with Chinese & English. I want to set Chinese and English in different fonts, but the script can only set one font.

You might be mistaking DOM Scripting for the totality of Scripting in Photoshop.

Action Manager code (as recorded by ScriptingListener.plugin) can be used to create type layers with different text properties like font for different letters.

So while it may be difficult to figure it out I think what you are trying to do is Script-able.