This is a beta for a some code that I wrote to set multiple fonts (size and color, too) in a TextItem.
The script contains a 'tsrDemo' function that creates some style ranges and replaces the contents of a layer and uses the new style ranges.
It's best to run the script with no other documents open. It will create a new doc with a text layer, set some initial contents along with a few other attributes, then set the style ranges.
There are probably a whole bunch of ways to make this fail. Do some testing and let me know what you find. And let me know what additional or modified functionality you'd like to see.
ciao,
-X
TextRange.jsx
TextRange.jsx
Here's an update with a sample document. Open the document and run the script.
I cleaned up the code a bit. I also having using the defaults from the existing textitem instead of hardwired defaults. It should also work now whether its a Paragraph kind or not.
ciao,
-X
I cleaned up the code a bit. I also having using the defaults from the existing textitem instead of hardwired defaults. It should also work now whether its a Paragraph kind or not.
ciao,
-X
TextRange.jsx
Xbytor,
This is great.
It may be because I've been putting in too many hours at work latley, but I can't figure out what the options for 'TextStyle' are.
I tried to call it just setting just the font, size and color so I could set one line of text all one font, size and color. It seems that it needs the range. Can any of the other textItem options be set by 'TextStyle" like pointtext or position?
I know that the main reason you wrote this is to be able to change the color and size of just part of the textItem content, but I think that I would use it mostly for making all the settings at once so it only takes up one history state.
If it sould be clear what settings 'TextStyle' sets, just ingore this and I will have another look after Christmas when I had some rest and can think clearer.
Mike
This is great.
It may be because I've been putting in too many hours at work latley, but I can't figure out what the options for 'TextStyle' are.
I tried to call it just setting just the font, size and color so I could set one line of text all one font, size and color. It seems that it needs the range. Can any of the other textItem options be set by 'TextStyle" like pointtext or position?
I know that the main reason you wrote this is to be able to change the color and size of just part of the textItem content, but I think that I would use it mostly for making all the settings at once so it only takes up one history state.
If it sould be clear what settings 'TextStyle' sets, just ingore this and I will have another look after Christmas when I had some rest and can think clearer.
Mike
TextRange.jsx
Code: Select allTextStyle = function(font, size, color)
All you can set on TextStyle is the font, size, and color (for now).
The font can either be the postscript name or an actual TextFont.
Size is a float or int.
Color is either a SolidColor or an RGBColor.
Code: Select allTextStyleRange = function(from, to, textStyle)
TextStyleRange is where you specify the extent that a specific TextStyle will be applied. One TextStyle can be specified in more than one TextStyleRange.
Download the update as well and read through tsrDemo closely. The update also has a sample psd file so that it's should be obvious how the defaulting mechanism works. It also supports pointtext now if it's set in the textItem ahead of time.
If you want more options in TextStyle, let me know what they are. I picked font, color, and size since that's what I've seen the most requests for on different forums.
I may also end up writing a Text (or TextOptions) class to support additional options (like height, width, and postion) and possibly ParagraphStyle/Range(s). It'll keep me busy for a few days.
ciao,
-X
All you can set on TextStyle is the font, size, and color (for now).
The font can either be the postscript name or an actual TextFont.
Size is a float or int.
Color is either a SolidColor or an RGBColor.
Code: Select allTextStyleRange = function(from, to, textStyle)
TextStyleRange is where you specify the extent that a specific TextStyle will be applied. One TextStyle can be specified in more than one TextStyleRange.
Download the update as well and read through tsrDemo closely. The update also has a sample psd file so that it's should be obvious how the defaulting mechanism works. It also supports pointtext now if it's set in the textItem ahead of time.
If you want more options in TextStyle, let me know what they are. I picked font, color, and size since that's what I've seen the most requests for on different forums.
I may also end up writing a Text (or TextOptions) class to support additional options (like height, width, and postion) and possibly ParagraphStyle/Range(s). It'll keep me busy for a few days.
ciao,
-X
TextRange.jsx
Code: Select alllayer.textItem.justification = Justification.RIGHTJUSTIFIED
will work in JS as the default justification for all paragraphs in a text item. To fully support this in my code would mean adding support for ParagraphStyles. I'm not all that motivated to do that at the moment. I may add rudimentary support in a follow on release.
will work in JS as the default justification for all paragraphs in a text item. To fully support this in my code would mean adding support for ParagraphStyles. I'm not all that motivated to do that at the moment. I may add rudimentary support in a follow on release.
Re: TextRange.jsx
where is the code ,please help me
Re: TextRange.jsx
Not tested, but here is the original script...
- Attachments
-
- TextRange.zip
- (33.08 KiB) Downloaded 185 times