Change font for particular text via script in Photoshop - text

Looking for a script or action for changing font face for a particular word or text in a paragraph.
I have multiple .psd files (80+) where I need to change font for a specific text say "Hello" from Arial to Tahoma and also make it bold.
Really appreciate a help!

You could try "jam" framework. There is class for manipulating with text. http://www.tonton-pixel.com/JSON%20Action%20Manager/jsDoc/symbols/jamText.html
You are looking for textStyleRange.
var text = "Bonjour !";
var layerText =
{
"layerText":
{
"textKey": text,
"textClickPoint": { "horizontal": 50, "vertical": 95 },
"antiAlias": "antiAliasCrisp",
"textShape":
[
{ "textType": "point", "orientation": "horizontal" }
],
"textStyleRange":
[
{
"from": 0,
"to": text.length,
"textStyle":
{
"fontPostScriptName": "Myriad-Italic",
"size": 288,
"color": { "red": 144, "green": 0, "blue": 255 }
}
}
],
"paragraphStyleRange":
[
{
"from": 0,
"to": text.length,
"paragraphStyle": { "alignment": "center" }
}
]
},
"typeUnit": "pixelsUnit"
};
jamText.setLayerText (layerText);
You need:
- create loop which checks all layers
- read one text layer
- find on which character index substring starts, where is end
- apply jamText.setLayerText
- read next layer
It goes also without framework. The structure is analogous. The code will be uglier.

Related

Using user-defined color in VS Code own Color Theme

In documentation of VS Code Extensions, it is mentioned that you can define your own color: https://code.visualstudio.com/api/references/contribution-points#contributes.colors
How can I use this color in the Color Theme I create?
For example, I have the following in package.json
"contributes": {
"themes": [
{
"label": "My Color Theme",
"uiTheme": "vs-dark",
"path": "./themes/my-color-theme.json"
}
],
"colors": [
{
"id": "color.gold",
"description": "Gold",
"defaults": {
"dark": "#FFB71B",
"light": "#FFB71B",
"highContrast": "#FFB71B"
}
}
]
}
And the following in my-color-theme.json (I would like to use "gold" for one of the item but it does not work):
{
"name": "My Color Theme",
"type": "dark",
"colors": {
"editor.background": "#000000",
"editor.foreground": "#FFFFFF",
"sideBarTitle.foreground": "color.gold",
},
...
}
Thanks
Color entries can only contain color values of the form #RGB, #RGBA, #RRGGBB or #RRGGBBAA, nothing else. No other color format (hsl etc.) or named color is supported. Hence "sideBarTitle.foreground": "color.gold" is an invalid entry.

Working example to custom-format a column title/header?

I have a formatter that works for column data, using column parameter formatter. Using the same formatter with column parameter titleformatter, I get the error noted below. Also, I don't understand why HTML in title parameter text seems not to work for <b> ... </b> but does work for other things (e.g., <i> ... </i>. A working custom formatter example would help. (I don't see this in Tabulator documentation.) See this montage combining a column header and row header screenshot with common cell text---'bold' in the row looks bolder to me.
Cell text comparison screenshot montage
I've tried emulating some posted sample code, but I get the same error as reported by #dagroj in his comment to #Oli Folkerd's answer (to the question) about titleformatter --- viz. tabulator.min.js:2 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. (Mentioning that here because I don't yet have the reputation to comment there.)
Here is a rendering of my CPT, without the titleformatter.
Corresponding table constructor:
"columnVertAlign": "bottom",
"height": "100%",
"layout": "fitColumns",
"columns": [
{
"title": "<i> absolute_T<--T (noisyAnd)</i>",
"columns": [
{
"title": "<b> NotCorrAnd_EffectiveHyp</b>",
"field": "label",
"align": "right",
"headerSort": false
}
]
},
{
"title": "NotB_EffectiveHyp",
"columns": [
{
"title": "<b>T</B>",
"field": "true",
"align": "center",
"headerSort": false
},
{
"title": "<i>F</i>",
"field": "false",
"align": "center",
"headerSort": false
}
]
},
{
"title": "<b> Belief </b>",
"columns": [
{
"title": "odds",
"field": "odds",
"align": "center",
"headerSort": false
},
{
"title": "log<sub>2</sub> odds",
"field": "log2odds",
"align": "center",
"headerSort": false
}
]
}
]
}
Formatter:
function truthFormatter(cell, formatterParams, onRendered) {
var cellValue = cell.getValue();
var cellElement = cell.getElement();
if (cellValue == "T") {
cellElement.style.backgroundColor = "#0000B3";
cellElement.style.color = "#FFFFFF";
cellElement.style.textAlign = "center";
cellElement.style.fontWeight = "bold";
}
else if (cellValue == "F") {
cellElement.style.backgroundColor = "#B30000";
cellElement.style.color = "#FFFFFF";
cellElement.style.textAlign = "center";
cellElement.style.fontWeight = "bold";
}
else cellElement.style.color = "#000000";
return cell.getValue();
}
Column headers are by default styled to be bold, so adding a bold or strong tag will not make them any bolder. On a side not you are using a mix of lowercase and uppercase "b" in your tags
If you are getting that error it means that your formatter is not returning a valid value, it must either be a string/number or a DOM element of type Node.

Creating wordclouds with Altair

How do I create a wordcloud with Altair?
Vega and vega-lite provide wordcloud functionality which I have used succesfully in the past.
Therefore it should be possible to access it from Altair if I understand correctly and
I would prefer to prefer to express the visualizations in Python rather than embedded JSON.
All the examples for Altair I have seen involve standard chart types like
scatter plots and bar graphs.
I have not seen any involving wordclouds, networks, treemaps, etc.
More specifically how would I express or at least approximate the following Vega visualization in Altair?
def wc(pages, width=2**10.5, height=2**9.5):
return {
"$schema": "https://vega.github.io/schema/vega/v3.json",
"name": "wordcloud",
"width": width,
"height": height,
"padding": 0,
"data" : [
{
'name' : 'table',
'values' : [{'text': pg.title, 'definition': pg.defn, 'count': pg.count} for pg in pages)]
}
],
"scales": [
{
"name": "color",
"type": "ordinal",
"range": ["#d5a928", "#652c90", "#939597"]
}
],
"marks": [
{
"type": "text",
"from": {"data": "table"},
"encode": {
"enter": {
"text": {"field": "text"},
"align": {"value": "center"},
"baseline": {"value": "alphabetic"},
"fill": {"scale": "color", "field": "text"},
"tooltip": {"field": "definition", "type": "nominal", 'fontSize': 32}
},
"update": {
"fillOpacity": {"value": 1}
},
},
"transform": [
{
"type": "wordcloud",
"size": [width, height],
"text": {"field": "text"},
#"rotate": {"field": "datum.angle"},
"font": "Helvetica Neue, Arial",
"fontSize": {"field": "datum.count"},
#"fontWeight": {"field": "datum.weight"},
"fontSizeRange": [2**4, 2**6],
"padding": 2**4
}
]
}
],
}
Vega(wc(pages))
Altair's API is built on the Vega-Lite grammar, which includes only a subset of the plot types available in Vega. Word clouds cannot be created in Vega-Lite, so they cannot be created in Altair.
With mad respect to #jakevdp, you can construct a word cloud (or something word cloud-like) in altair by recognizing that the elements of a word cloud chart involve:
a dataset of words and their respective quantities
text_marks encoded with each word, and optionally size and or color based on quantity
"randomly" distributing the text_marks in 2d space.
One simple option to distribute marks is to add an additional 'x' and 'y' column to data, each element being a random sample from the range of your chosen x and y domain:
import random
def shuffled_range(n): return random.sample(range(n), k=n)
n = len(words_and_counts) # words_and_counts: a pandas data frame
x = shuffled_range(n)
y = shuffled_range(n)
data = words_and_counts.assign(x=x, y=y)
This isn't perfect as it doesn't explicitly prevent word overlap, but you can play with n and do a few runs of random number generation until you find a layout that's pleasing.
Having thus prepared your data you may specify the word cloud elements like so:
base = alt.Chart(data).encode(
x=alt.X('x:O', axis=None),
y=alt.Y('y:O', axis=None)
).configure_view(strokeWidth=0) # remove border
word_cloud = base.mark_text(baseline='middle').encode(
text='word:N',
color=alt.Color('count:Q', scale=alt.Scale(scheme='goldred')),
size=alt.Size('count:Q', legend=None)
)
Here's the result applied to the same dataset used in the Vega docs:

Is it possible to change background color of some code in Sublime Text 3?

I want change background color of calls __$sa__login and gtag, so I can quickly find all the 'analytic' code in a .js file.
this.__$sa__login(user.id)._____
....
gtag( { 'Country': user.zoneId } )
Something like this:
I found a solution with this great Sublime Text plugin HighlightWords
Here is my config:
{
// The colors to highlight texts are specified by a list of theme scope names,
// and HighlightWords uses this list in circular order.
"colors_by_scope": [
"string",
"entity.name.class",
"variable.parameter",
"invalid.deprecated",
"invalid",
"support.function"
],
"whole_word": false,
"use_regex": true,
"ignore_case": false,
// Keywords to be always highlighted, clear the list to disable it.
// "keyword" are literally matched, and "color" refers to theme scope names.
// "flag": 0 - regex, 1 - literal (default), 2 - regex and ignore case, 3 - literal and ignore case
// Note that json has some special characters like '\' should be escaped.
"permanent_highlight_keyword_color_mappings": [
{"keyword": "TODO", "color": "support.function"},
{"keyword": "FIXIT .*", "color": "support.function", "flag": 2},
{
"flag": 0,
"keyword": "this\\.__\\$sa__\\w+\\(.*?\\)\\._+",
"color": "text.html.vue source.js.embedded.html meta.export.js meta.object-literal.js meta.object-literal.js meta.block.js meta.function-call.method.js meta.group.js string.quoted.single.js"
},
{
"flag": 0,
"keyword": "gtag\\(.*?\\)",
"color": "text.html.vue source.js.embedded.html meta.export.js meta.object-literal.js meta.object-literal.js meta.block.js meta.function-call.method.js meta.group.js string.quoted.single.js"
}
]
}

Zingchart how to add custom legend item

I have a bar chart with 3 kinds of bar: FOO, BAR and BAZ.
Horizontal axis are quarters.
BAR and BAZ use the same series. BAR (blue) becoming BAZ (orange) after Q1-17.
"rules": [{
"rule": "%kv > 1",
"background-color":"orange"
}]
How can I add BAZ (orange) to the legend?
zingchart.THEME = "classic";
var myConfig = {
"graphset": [{
"type": "bar",
"background-color": "white",
"plotarea": {
"margin": "80 60 100 60",
"y": "125px"
},
"legend": {
"layout": "x3",
"y": "13%",
"x": "34.5%",
"overflow": "page",
"toggle-action": "remove",
},
"scale-x": {
"labels": [
"Q4-16",
"Q1-17",
"Q2-17",
"Q3-17"
],
"markers": [{
"value-range": true,
"range": [1.5],
"line-color": "red",
"line-width": 1,
"line-style": "solid",
"type": "line"
}]
},
"series": [{
"values": [
37.47,
57.59,
45.65,
37.43
],
"background-color": "#8993c7",
"text": "FOO"
},
{
"values": [
13.4,
14.11,
14.89,
16.86
],
"background-color": "blue",
"text": "BAR",
"rules": [{
"rule": "%kv > 1",
"background-color": "orange"
}]
}
]
}]
};
zingchart.render({
id: 'myChart',
data: myConfig,
height: 500,
width: 725
});
.zc-ref {
display: none;
}
<html>
<head>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
<script>
zingchart.MODULESDIR = "https://cdn.zingchart.com/modules/";
ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9", "ee6b7db5b51705a13dc2339db3edaf6d"];
</script>
</head>
<body>
<div id='myChart'><a class="zc-ref" href="https://www.zingchart.com/">Charts by ZingChart</a></div>
</body>
</html>
So one way to do it is split up your data. The easiest way to explain this is to make another series for "BAZ" and in the first two quarters have null values.
demo here
The main reason for doing it this way is maintaining the built in legend toggling functionality. This way when you click it wont turn off the whole series (blue and orange bars.) Which I assume is the intended functionality.
If you don't mind turning off blue and orange bars at the same time you can do the following to add another legend item. Add the text and color inside the series object. Essentially, create a blank series object.
...{
"text":"BAZ",
"background-color":"orange"
}...
non interactive legend demo here
If you are looking for something in between these two demos it will take some custom Javascript using the ZingChart API.

Resources