I am trying to update the font of a range of text in a Google Docs document using the API. I am trying to change just the font and not the font size or style attributes like bold or italic. So if for example I have a document with just the text below as the content:
Hello world
I want to change just the font for the word Hello but leave it the same size and still bold and italic.
I tried to accomplish this with the following code documents.batchUpdate request
{
"requests": [
{
"updateTextStyle": {
"range": {
"startIndex": 1,
"endIndex": 6
},
"textStyle": {
"weightedFontFamily": {
"fontFamily": "Times New Roman"
}
},
"fields": "weightedFontFamily"
}
}
]
}
The result is a successful response from the server but when I check the document I see it changed the font keeping the size and italic attribute, but it didn't keep the bold attribute. I have also tried this using the Google API Explorer and can reproduce the same results.
My question is how do I change the font without loosing the bold? It seems like it should be possible as it kept the italic attribute in tact. Why is bold different? Is it a bug?
My goal is to just change the font leaving the other attributes as is so I do not want to set bold or other attributes explicitly. I also don't want to have to determine the attributes before hand and reset them. That is more work and will be slower and shouldn't be necessary if italic is maintained.
I am able to do something very similar without issue in Google Sheets using a repeatCell.cell.userEnteredFormat.textFormat.fontFamily request and it maintains the bold and italic.
Thanks in advance for any insight or help.
How do I change the font without loosing the bold?
Answer
You have to first save the font weight and bold settings for the range of text you want to modify. There may be more then one font setting for the range. To get the font weight and bold settings for the range you must first check textRun.textStyle. If not defined there you must lookup the paragraphs namedStyleType and check it for the weight and bold settings. If not defined there you must check the NORMAL_TEXT namedStyleType. If not defined there you must use the Google Docs editor default value which for weight is 400 and bold is false.
Once you have the font info for the range you make make a requests for each different font. The request would be like the one in the original question but would set the weightedFontFamily.weight and the bold attributes based on the saved font info.
{
"requests": [
{
"updateTextStyle": {
"range": {
"startIndex": 1,
"endIndex": 6
},
"textStyle": {
"weightedFontFamily": {
"fontFamily": "Times New Roman"
"weight": savedWeight
},
"bold": savedBold
},
"fields": "weightedFontFamily"
}
}
]
}
Why is bold different?
Answer
The Google Docs API uses weightedFontFamily where the weight sub-attribute defaults to 400 and not the current font weight. The bold setting just increases the weight, so bold and weight are linked. There is no current way in the API to set just the font leaving weight/bold alone.
Is it a bug?
Answer
Based on a reply from #Tanaike I have reported the issue to Google via the Google Issue Tracker (https://issuetracker.google.com/165029692). They informed me it was working as intended.
Related
I have a file that is used to store all my colour choice, I bring the colour choices that I need into a part file using the Subcomponents (Supersedings)
{
"internalId": "externalCubbyCoverColourRack",
"componentId": "racksystems_test:sub_mfccolours",
"numberInPartList": "0",
"active": "version=='Rack'",
"supersedings": [
{
"type": "parameter",
"key": "cubbyCoverColourRack"
}
]
}, {
"internalId": "externalCubbyColourRack",
"componentId": "racksystems_test:sub_mfccolours",
"numberInPartList": "0",
"active": "version=='Rack'",
"supersedings": [
{
"type": "parameter",
"key": "cubbyColourRack"
}
]
},
I have 2 colours that I bring in that are a Main Colour and a Cover Colour, when the main colour is selected it changes the Main Colour and I want it to change the Cover Colour too but if you change the Cover Colour only the cover colour changes. Is this possible to do with a KEY that's used from Subcomponents?
Normally, it is recommended to use parameter onValueChange script. However, this is intended to work in a scope of a single component.
From your code, I think it should be possible to supersede both of them from a single subComponent instance. Then you can link the two parameters somehow in the sub_mfccolours itself, using parameter onValueChange script.
It is important to know, that every subComponent instance is its own component with its own internal data. If you have a reason to have two subComponents like this, it might help to add assignment "cubbyColourRack": "cubbyColourRack" to the externalCubbyCoverColourRack subComponent.
For example,
"node.Person": {
"color": "#FF756E",
"border-color": "#E06760",
"text-color-internal": "#FFFFFF",
"caption": "{name}"
}
I want the "Person" to be displayed as the label of the node, and "name" and "age" to be displayed as the attributes of the node. Currently, only 'name' is displayed as the caption.
How to change the code above?
EDITED:
Neo4j people, how did you generate the graphs in the book? Thank you. This is one example below.
You can do it by editing the styles. Do this by typing ":style" to the neo browser UI, copy-paste the styles to text editor and just add the fields to the caption in curly brackets e.g.
"node.Person": {
"defaultCaption": "<id>",
"diameter": "50px",
"color": "#A5ABB6",
"border-color": "#9AA1AC",
"text-color-internal": "#FFFFFF",
"caption": "{name} {age}"
}
Would result in showing Person entities with name and age on them.
As I said in the comments of my answer its not possible. My anwser is as close as you can get. "node.MESSAGE": { "caption":"Message name:{NAME}" }. You can only write directly onto the node. I recommend to use different colours for different labels
The question might seem stupid. but i really can't find what i should type on the "Add spacing under element" text box to achieve the spacing from the CMS and not hard-coded.
In an element properties you can see this window:
Umbraco version 7.2.5 assembly: 1.0.5610.18894
Free License for now but planning to get one this week.
Okay I got your point. You are using Grid Layout.
By default Umbraco Grid layout datatype have setting class and styling background image as below
This can be found in Developer -> Datatypes - > datatype you have created with "Grid Layout", You can find data type name in Setting->Document types -> Name of home doc type -> generic properties
You can change settings and styles by clicking edit, it contains json data as below. This is default value
For setting
[
{
"label": "Class",
"description": "Set a css class",
"key": "class",
"view": "textstring"
}
]
For Style
[
{
"label": "Set a background image",
"description": "Set a row background",
"key": "background-image",
"view": "imagepicker",
"modifier": "url({0})"
}
]
Get full details on link
Now your scenario.
I think according to description, you have used this to add padding-bottom or margin-bottom style on the element. So you must use values like "20px" or "10px". Try only numbers like "10" if this don't work
I would like to set some sort of title for the exported data on the PDFs.
I have looked through http://ui-grid.info/docs/#/api/ui.grid.exporter but there does not seem to be a setting for it.
Right now when you export data as pdf, you get a grid with some red column headers, but nothing to indicate what the report is supposed to be.
Try this
exporterPdfHeader: { text: "My Header", style: 'headerStyle' },
http://ui-grid.info/docs/#/tutorial/206_exporting_data
When exporting chart in Highchart, all my characters are displayed well, except Chinese colon.
Do I need to set something specical?
Even in the highchart exporting example from its site, there is still the problem
Please see an example in http://jsfiddle.net/warmwind/Prah7/2
When setting title as below, it cannot be export correctly
title: {
text: 'Exporting it:colon in between'
}
Something is wrong with the defautlt font on the export-server for this chinese character. Please, specify a font-family for your title. Like this,
title: {
text: 'Exporting it:colon in between',
style: {
"font-family":'verdana'
},
},
There´s reported an issue for this, see https://github.com/highslide-software/highcharts.com/issues/2120