How can I programmatically get text selection in Adobe After Effects with ExtendScripts - adobe

I have object TextLayer with white text color string. Then I animate text color selection (second character changes color white -> blue).
How can I get this selection and color programmatically?

Seems like you can't reach the selection start and end values by scripting. But you can add expression controller effect and get the values from that one.
The code below asumes you have one comp in your project with an text layer called "my text layer".
Add an expression controller for color to that layer. Add the expression text.animator("Animator 1").property.fillColor to that effect.
You can do the same thing with the values from your selection.
var preExpression = true;
var currentTime = 5; // in seconds
// get the sourceText? works!
var val = app.project.item(1).layer("my text layer").property("ADBE Text Properties").property("ADBE Text Document").valueAtTime(currentTime, preExpression);
// get the Text Percent Start? Wont work!
var sel = app.project.item(1).layer("my text layer").property("ADBE Text Properties").property("ADBE Text Animators").property("ADBE Text Animator").property("ADBE Text Selectors").property("ADBE Text Selector").property("ADBE Text Percent Start").valueAtTime(currentTime, preExpression);
// add an expression controller for color and get the color from that one? works!
var col = app.project.item(1).layer("my text layer").property("ADBE Effect Parade").property("ADBE Color Control").property("ADBE Color Control-0001").valueAtTime(currentTime, false);
$.writeln(val);
$.writeln(sel);
$.writeln(col);
Take a look into the After Effects Scripting Guide. Use redefinery's rd_GimmePropPath script to get the match names of properties.

Related

How to convert rgba value into human readable text

Need to find the button color into human-readable format below code is returning rgba value
Here is my code:
WebElement findbuttonColor = driver.findElement(By.id("color"));
String color = findbuttonColor.getCssValue("background-color");
System.out.println("Button color is :"+color);
I am not sure what human-readable format mean, there are millions of colors which is possible to set for the element. Far not all of them have the names like green, blue, red, etc.
You get the value in rgba because the designer set up the value in rgba. The thing you could do is to define a structure that would map some well-known color codes to rgb (even not considering alpha channel) so that you could pich the "human-readable" format from that map.
Here is the example that might give a clue: Convert RGB values to color name
You can get the element color(Background color of element) by:
element.getCssValue("background-color");
You can get the element text/caption color by:
element.getCssValue("color");
For example if you want to get the background and text color of "Sign in" button for LinkedIn, the code is as follows:
driver.get("https://www.amazon.com/");
String buttonColor = driver.findElement(By.id("searchDropdownBox")).getCssValue("background-color");
String buttonTextColor = driver.findElement(By.id("searchDropdownBox")).getCssValue("color");
System.out.println("Button color: " + buttonColor);
System.out.println("Text color " + buttonTextColor);
When you do getCssValue(), it return rgb value. You can convert it into hex by using below
backgroundColor = element.getCssValue("background-color");
Color.fromString(backgroundColor).asHex();
this returns hex code, something like "#def3ff". You can later compare it with your availbale hexcode in yous css.
Assert.assertEquals(def3ff, ExpectedHexCode);
Note:
You can get hex code of your element by inspecting it > Styles. Refer below screenshot for details
how to get Hexcodefrom
Thank You,

How to place underline under a paragraph in itextsharp

I am using iTextSharp in my current project. I have created a table with some underlined data but my requirement is shown in this image:
http://postimg.org/image/402ap3acf/
How can I build this type of table.
I need the below structure.
A/C Some text TAT Some text
----------------- -----------------
The doted lines are underline.
The underline is controlled via the Font object and if you only want to set part of a Paragraph to be underlined you'll want to use a Chunk.
Here's a quick helper method for generating a font with different styles. You can change the actual font to whatever font you want to use.
Private Shared Function CreateFont(size As Integer, Optional style As Integer = iTextSharp.text.Font.NORMAL) As iTextSharp.text.Font
Return New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, size, style)
End Function
The style parameter takes integers from this list that you OR together:
iTextSharp.text.Font.NORMAL
iTextSharp.text.Font.BOLD
iTextSharp.text.Font.ITALIC
iTextSharp.text.Font.UNDERLINE
iTextSharp.text.Font.STRIKETHRU
So normal underlined text would be:
iTextSharp.text.Font.NORMAL Or iTextSharp.text.Font.UNDERLINE
You can use the above like this:
Dim P As New Paragraph()
P.Add(New Chunk("A/C ", CreateFont(12, iTextSharp.text.Font.NORMAL)))
P.Add(New Chunk("Some text", CreateFont(12, iTextSharp.text.Font.NORMAL Or iTextSharp.text.Font.UNDERLINE)))
EDIT
From iTextSharp's perspective, "underline" means "a line drawn underneath text". If there's no text there won't be an underline. A space, however, counts as text so you can just add extra spaces if you want like to continue the underline:
Dim P As New Paragraph()
P.Add(New Chunk("A/C ", CreateFont(12, iTextSharp.text.Font.NORMAL)))
P.Add(New Chunk("Some text ", CreateFont(12, iTextSharp.text.Font.NORMAL Or iTextSharp.text.Font.UNDERLINE)))

Flex 3 Multicolored Text in DataGrid Cell

I am having an issue with styling individual cells in a DataGrid. I want to go through the text in a DataGrid cell and only color a specific portion of the text.
When a User uses a search filter, we want to color and bold the text in the cell that matches the search phrase. For example, the User filters a column of job titles with the search phrase "Adjust" and one of the cell values is "Claim Adjusters", we want "Claim " and "ers" at the end to be black font color and the "Adjust" to be another color (let's say red).
I noticed that if the String passed to the DataGrid was of the form:
value.substring(0,start) + "(b)" + value.substring(start,finish) + "(/b)" + value.substring(finish);
With "<>" rather than "()", the text between the bold tags gets displayed with a bold font, but it does not work with (font color=\"red\") ... (/font).
Any suggestions on how I can get the search text to color here as well as bold?
Only hexadecimal color (#FFFFFF) values are supported.
A simple alternative with lots of flexibility is to make your itemRendrer support html formatting:
public class HtmlItemRenderer extends DataGridItemRenderer {
override public function validateProperties():void {
super.validateProperties();
if (text.indexOf('<') > -1) {
htmlText = text;
}
}
}
The conditional doesn't need to be very strict, it will still save some cycles for most cells that contain no markup.

calculating Spark TextArea width

I am treating a spark TextArea as text input(by setting heightInLines="1"). The TextArea is part of an mxml component and I want to resize the component when the text is changed.
I haven't been able to use textArea.measureaText(textArea.text) to get line metrics and use it. I get this error "Parameter antiAliasType must be non-null."
Is there any way to get the width of a TextArea which it is going to consume at runtime for a particular string or a particular TextFlow?
A little ugly but works for me:
var uiText:UItextField = new UITextField();
// if you have custom text style on the TextArea then set it the same of this uitextfield
uiText.setTextFormat("bla bla bla");
uiText.text = "This is the text that I want the size for";
var textW:Number = uiText.textWidth;
var textH:Number = uiText.textHeight;
// then we need to consider also the border of the text area and the paddings
// try read the padding values and border sizes using getStyle(...)
myTextArea.width = textW+2*borderW+paddingL+paddingR;
myTextArea.height = textH+2*borderH+paddingT+paddingB;
That should be all

In actionscript 3 how can I edit a textArea after applying a styleSheet?

Here is a portion of my code:
var styles:String = ".keyword{color: #ff0000;} .comment{color: #00ff00;}";
var myStyleSheet:StyleSheet = new StyleSheet();
myStyleSheet.parseCSS(styles);
myTextArea.htmlText = '<span class = "keyword"> red </span> uncolored <span class = "comment"> green text</span>';
Everything is fine till this point, i can edit my text, of course everything is showed in black, and the html-tags are ignored. But when I put this code in myTextArea.styleSheet = myStyleSheet;
my text will be colored as i want it to be, but the textArea will become uneditable (no blinking pointer, no reaction on keyboard press).
After each keyboard-press (or if the time between two key-presses is bigger than x milliseconds ) i will re-render the textArea.text and append the <span class = "keyword"> where needed </span> tags and put it into the textArea.htmlText, but can't seem to figure it out how to do it when style is applied.
Sadly enough css and text input are incompatible. The only workaround is to use TextFormat instead. Sorry for being disappointing...

Resources