Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

Re: Can we assign html tags color/size/face to textFrame.contents of inDesign ?

$
0
0
  • Reg Expression couldn't able to handle the number of proboblity's were the TextFormat string contains , and i was doing some xml parsing has below ,

        Please let  me know if i can do better than this .

 

 

 

var xmlConvertedText:XMLList = XMLList(""+cellInstructionText+"");

for(var i1:int=0;i1<xmlConvertedText.children().length();i1++)

     {

    var _rowOfXmlConvText:XML = xmlConvertedText.children()[i1];

    if(_rowOfXmlConvText != null)

       {

          for(var j1:int=0;j1<_rowOfXmlConvText.children().length();j1++)

              {

            var _dataOfRow:XML = _rowOfXmlConvText.children()[j1];

            applyStyles(_dataOfRow,layerText);

              }

          }

    }

 

public function applyStyles(_fontData:XML,textLayer:TextFrame):void{       

                trace("NAME: "+_fontData.name());               

                for each (var att:XML in _fontData) {

                    trace("Attribute: "+att.name()+" = "+att);

                    trace(_fontData.text());

                    if(_fontData != null && _fontData.nodeKind() != 'text'){

                        var face:String  = _fontData.@FACE;                                           

                        var size:String  = _fontData.@SIZE;                                           

                        var strColor:String = _fontData.@COLOR;                                           

                        var content:String = _fontData.text();                           

                        //apply content

                        if(content!=""){                                       

                            textLayer.parentStory.insertionPoints.item(-1).texts.item(0).contents = content+" ";                   

                            //Clear the find/change text preferences.

                            app.findTextPreferences = NothingEnum.nothing as FindTextPreference;

                            app.changeTextPreferences = NothingEnum.nothing as ChangeTextPreference;

                            //Search the document for the string "Text".

                            app.findTextPreferences.findWhat = content;                                           

                            var mFound:Object = app.activeDocument.findText();                                            

                            var len:Object = mFound.length;

                            if(size!=""){

                                mFound[0].pointSize = size;//     ">0" in case of nothing found

                            }

                            if(face!=""){

                                mFound[0].appliedFont = app.fonts.item(face);

                            }

                            if(strColor!=""){

                                mFound[0].fillColor = myDocument.colors.add({space:ColorSpace.RGB,colorValue:[parseInt(strC olor.substr(1,2),16), parseInt(strColor.substr(3,2),16), parseInt(strColor.substr(5,2),16)]});

                            }                                       

                            app.findTextPreferences = NothingEnum.nothing as FindTextPreference;

                            app.changeTextPreferences = NothingEnum.nothing as ChangeTextPreference;

                        }                                   

 

                    }

                }               

                if (_fontData.children()==_fontData) {

                    trace("VALUE: "+_fontData.children());

                    trace("-----------------");

                } else {

                    trace("This node has children:");

                    for each (var item:XML in _fontData.children()) {

                        applyStyles(item,textLayer);

                    }

                }   

 

 

        }


Viewing all articles
Browse latest Browse all 37788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>