How can I use other font weights (such as Book 300 for Open Sans) in my documents?
Adding Open Sans only allows me to use Normal 400, for example.
It appears that Google docs has very limited functionality for google web fonts right now. For each font you use, you only have the option of the bold weight or normal weight that was set for the web font you selected.
Now that Google Apps Script is implemented in Google Documents, it is possible to create font weights:
// global
var app = DocumentApp.getUi();
function onOpen() {
app.createMenu('Font').addItem('Set font size', 'fontSize')
.addToUi();
}
function fontSize() {
// selected text
var selection = DocumentApp.getActiveDocument().getSelection();
// create input box
var fontSize = app.prompt('Add Font Size','Input Integer (> 0)'
,app.ButtonSet.OK).getResponseText();
// check if value exists
if(!fontSize || fontSize == 0) {
app.alert("Error","No input present", app.ButtonSet.OK);
return;
}
// https://developers.google.com/apps-script/reference/document/selection
var elements = selection.getSelectedElements();
for (var i=0, iLen=elements.length; i<iLen; i++) {
var element = elements[i];
// Only modify elements that can be edited as text;
// skip images and other non-text elements.
if (element.getElement().editAsText) {
var text = element.getElement().editAsText();
// Bold the selected part of the element,
// or the full element if it's completely selected.
if (element.isPartial()) {
text.setFontSize(element.getStartOffset(),
element.getEndOffsetInclusive(), parseInt(fontSize));
} else {
text.setFontSize(parseInt(fontSize));
}
}
}
}
I've created an example file for you to play around with: Font Size
See the following answer for instructions on how to implement the script (works the same as in a Google Spreadsheet): Font Size in Google Spreadsheets
setBold
and not setFontWeight
, so no chance
Commented
May 21, 2015 at 12:19