Specific character changing to Small Caps - javascript

I am writing a code to automate making around 100 graphics. I am trying to write it so I do not have to do any fine tuning after running the script. I do not know how to handle adjusting single characters in a text layer though. Here is an example of what I am trying to accomplish. It is for having a last name on the back of a football jersey.
One if statement I want to make is if the last name starts with "Mc" to change the "c" to small caps. I figured the code should start like this, but not sure how to call on just the second character to make that small caps:
if (variable.startsWith("Mc"){
This would be for instance if the name is "McDonald" to have the "c" as small caps.
Thanks. Sorry I am fairly new to photoshop scripting and have been doing just the simple things. This is by far the most advanced I have done. Let me know if I need to provide anything else.

Related

how to match continuous string input to passage in javascript, while showing mistakes?

Hey guys I am working on an application and so far its going well but while working on a recent features i am a little stuck.
Here is my problem:
using java script I am getting continuous user speech input and transcribing it. While I am getting this speech input i want to be able to identify and highlight the text on the screen that is being read. I want to highlight mistakes (words spoken that don't match) and I want to highlight all the content that is going correct.
I am not asking for someone to code this for me, i just want to be pointed in the right direction.
A similar implementation you have probably seen is in online typing games. where you try to type parts of a passage as fast as possible and it highlights the ones you are getting right and the ones that you are getting wrong.
Any help is appreciates, libraries, algorithms, methods, or terms I should search. Thank you !
Are you indexing the text at all? Do you know the text in advance? If you created an in memory graph database using each word in the text, you could search edges to find 'weighted' hits. It's ambitious, but there's an article here:
https://graphaware.com/neo4j/2016/07/07/mining-and-searching-text-with-graph-databases.html
If you want to go dirt simple and follow your typing game analogy:
In the typing game an event is fired each input (keypress).
The key pressed is compared to the expected one.
If it is not correct it is flagged as wrong.
There is usually no way to go back and correct the mistakes.
The user has to type the next expected letter correctly to
get things rolling correctly again.
You could do the same thing.
Underline the next expected word.
Each word (whitespace) is an event.
Match the text to speech word to the expected word.
If it is not right, flag it as wrong, strike it out.
The user has to say the next underlined word correctly to start things going smoothly again.
You could allow the user to back space the expected word so he/she could start over where they wanted to.
This will have some hiccups, as all things speech to text do, but it will work like your typing game and be simple to implement.

text string / word cloud ignore line break symbol

I have an implementation of the popular d3 word cloud. It has been working great for documents that are very lengthy, but I have been having an issue when I tried to re-purpose the word cloud to visualize a very simple txt file of the following format:
interesting. interesting. interesting.
boring. boring.
amazing. amazing. amazing.
stupid. stupid. stupid.
average. average.
disappointing.
(ect...)
It's basically just a txt file that has around 20 words. Each word repeats anywhere from 1 to 5 times. I would like this information to govern the sizing of the font (repeated 5 times = big font, 1 time = small font). When I put all the words on the same line, the resulting word cloud strangely makes all words the same font size. So I started to play around with it and tried a few different things. The closest I got to the desired effect was with the above txt format, having a line break after each new word.
This did result in the correct font sizing, but it also created a new problem. When I passed word_count object to the console log, I got something like this:
"⏎boring":1,
"boring":1,
"⏎stupid":1,
"stupid":2,
This means that the word cloud has repeated words in the visual (for example, the word "stupid" in large font size and also "stupid" in small font size). To make things more confusing, this behavior was isolated to a few words. Some words did not have the line break sign in front of them (even though I still hit enter in notepad when I made the txt in the same exact was as the ones that did wind up with the ⏎ sign.)
My next stab at fixing this was to add the "⏎" sign to the list of ignored words, hoping that would make the word cloud library treat them as if they were the same. Unfortunately for me, the problem persisted.
That sums it up pretty well; it's also really easy to reproduce, just need notepad and copy and paste my above words to see what I'm talking about.
Let me know if anyone has ideas for troubleshooting further.
Minimalist Block:
https://bl.ocks.org/diggetybo/cd644316f52465495f39c8fc27f04de8
(refreshing page will randomize the layout)

Word Cloud for Other Languages

I using JasonDavies's Word Cloud for my project, but there is a problem that I using Persian[Farsi] Strings and my problem here that words have overlapping in Svg.
This is my project's output:
What happened to the Farsi words?
As explained on the About page for the project, the generator needs to retrieve the shape of a glyph to be able to compute where it is "safe" to put other words. The about page explains the process in much more detail, but here's what we care for:
Glyphs are rendered individually to a hidden <canvas> element.
Pixel data is retrieved
Bounding boxes are derived
The word cloud is generated.
Now, the critical insight is that in Western (and many other) scripts, glyphs don't change shape based on context often. Yes, there are such things as ligatures, but they are generally rare, and definitely not necessary for the script.
In Persian, however, the glyph shape will change based on context. For non-Persian readers, look at ی and س which, when combined, become یس. Yes, that last one is two glyphs!
The algorithm actually has no problem dealing with Persian characters, as you can see by hacking the demo on the about page, putting a breakpoint just after the d.code is generated, to be able to modify it:
Replacing it with 1740, which is the charCode for the first Persian glyph above, and letting the algorithm run, shows beautiful and perfectly correct bounding boxes around the glyph:
The issue is that when the word cloud is actually rendered, the glyph is placed in context and... changes shape. The generator doesn't know this, though, and continues to use the old bounding data to place other words, thus creating the overlapping you witnessed. In addition, there is probably also an issue around right-to-left handling of text, which certainly would not help.
I would encourage you to take this up the author of the generator directly. The project has a GitHub page: https://github.com/jasondavies/d3-cloud so opening an issue there (and maybe referring back to this answer) would help!

bidirectional text - visual to logical

I'm drawing texts on the screen letter by letter.
In English it is very simple, because the text is LTR so the letters are saved in the String in the same order they're shown.
When drawing RTL text than I need to switch the direction of the printing. but when there are letters and numbers and English and some RTL language.. than the mess starts.
For Ex.
ex.1: שלום לכם
ש- is the first letter in the string - but as we can see that it shown the last
ex.2: שלום to all
ש- is the first letter in the string- but as we can see that it is shown in the middle, before the English starts.
It is getting more complicated when numbers and math signs are getting into the picture, and special characters like '(', ')' that needed to be flipped...
Found many Bidi algorithm online that changes the logical order of the letters in the string to visual one. So when i run from left to right on the converted string i'm sure that the string will print properly.
BUT,
They are never perfect. There are cases that they are not working properly.
None of them considering the direction of the text as well (means when we press the right Ctrl+Shift on the keyboard than the visualization is changed again)
My questions are
does anybody know some bulletproof Bidi algorithm i can use to change the string from what it saved in the memory to visual order?
Is there a simpler way to solve my problem ? maybe somehow get the browser algorithm for it..
After searching for long time,
I've found that DOJO (and luckily it is the tool kit that i'm using),
has has a BIDI engine for drawing it's own UI controls, that gets few layout parameters to handle some cases of RTL, LRT, and contextual directions as well.
If this is helping someone -
http://bill.dojotoolkit.org/api/1.9/dojox/string/BidiEngine
Found another link that might help to a none DOJO developers -https://github.com/ibm-js/dbidi, but I have not check it yet

Syntax Highlighter Numbering off and Closing List<Object> "tags"

This is kind of weird. I'm trying to get my code up on my website using Syntax Highlighter. I've come up against two weird problems.
1 - Code lines are off, in some cases worse than others
2 - Syntax Highlighter wants to close what it thinks are xml / html tags. If you go to the following link and look at the numbers and the bottom of the screen, you'll know what I mean.
http://kentcdodds.com/projectsamples/BankGUI/GUI.html
I'm not sure what's wrong. But I also just noticed it changed my capital S on String to a lower case s. I'm developing a program in Java to add all the html necessary before and after each of my .java files for my school projects this last year so I can put the code up for the world to see and hopefully help. So if I could get some help from someone with this Syntax Highlighter problem, that would be great.
It seems as though there is no real solution using this technology. So the best I can do is say hard-code changes for when String goes to lowercase and don't use line numbers. I'm sorry if this isn't helpful for people in the future. You might try one of these alternatives.

Categories

Resources