Estaba usando Sketch para hacer una foto de portada y contiene muchas palabras. Tengo que convertir cada texto en línea, así que tengo que abrir carpetas de capas y seleccionar cada texto por mí mismo.
¿Hay alguna forma más rápida de convertir todos los textos en un solo paso?
Aquí está mi enfoque. Encontré el complemento de boceto que convierte la capa de texto en contornos, pero convierte solo la capa de texto seleccionada. Lo modifiqué para que convierta todas las capas de texto en la página actual. Aquí hay instrucciones, por ejemplo, tenemos una foto con varias capas de texto en:
Vaya al menú, seleccione Complementos > Complemento personalizado... Aparecerá el área de texto, copie y pegue este código:
(function(){
function convertToOutlines(layer) {
if(!layer.isKindOfClass(MSTextLayer)) return;
var path=layer.bezierPathWithTransforms(); // Get text layers' outline as NSBezierPath.
var parent=layer.parentGroup();
var shape=MSShapeGroup.shapeWithBezierPath(path); // Create a vector shape with the outline.
// Set the style previously used in text layer.
shape.style = layer.style();
// If text layer doesn't have a fill style, we create it with the color used for the text.
var style=shape.style();
if(!style.fill()) {
var fill=style.fills().addNewStylePart();
fill.color = MSColor.colorWithNSColor(layer.style().textStyle().attributes().NSColor);
}
// Copy name and selection status.
var isSelected=layer.isSelected();
shape.name = layer.name();
shape.setIsSelected(isSelected);
// Remove text layer.
parent.removeLayer(layer);
// Add a newly created shape to the text layers' parent group.
parent.addLayers([shape]);
return shape;
}
var doc = context.document;
var page = [doc currentPage];
var layers = page.children();
for (var i = 0; i < layers.count(); i++) {
var layer = layers.objectAtIndex(i);
if(layer) {
var vectorizedTextLayer=convertToOutlines(layer);
print(vectorizedTextLayer);
}
}
})();
Debería verse así, allí puedes guardarlo y ejecutarlo:
Después de ejecutar el script, todas las capas de texto se perfilan:
Repositorio Github del complemento: https://github.com/zholdas/Texts-to-Outlines
Complemento de boceto inicial, el mío se basa en https://github.com/turbobabr/Sketch-Plugins-Cookbook/blob/master/Samples/Convert%20Text%20Layer%20to%20Outlines.sketchplugin
La respuesta anterior no funciona para el boceto 3.8 y superior. Da fills().addNewStylePart
un error indefinido en la línea 17 mientras se ejecuta como script personalizado. Mientras buscaba en Internet, descubrí que las cosas se han cambiado para addNewStylePart
. En el pasado, si deseaba agregar un nuevo relleno, borde o sombra a una capa, lo hacía:
layer.style().fills().addNewStylePart()
Comenzando con Sketch 3.8, la forma de hacerlo ahora es:
layer.style().addStylePartOfType(0) // To add a new fill
Para más detalles ver esta fuente
El script de trabajo final se ve así:
(function(){
function convertToOutlines(layer) {
if(!layer.isKindOfClass(MSTextLayer)) return;
var path=layer.bezierPathWithTransforms(); // Get text layers' outline as NSBezierPath.
var parent=layer.parentGroup();
var shape=MSShapeGroup.shapeWithBezierPath(path); // Create a vector shape with the outline.
// Set the style previously used in text layer.
shape.style = layer.style();
// If text layer doesn't have a fill style, we create it with the color used for the text.
var style=shape.style();
if(!style.fill()) {
var fill=style.addStylePartOfType(0);
fill.color = MSColor.colorWithNSColor(layer.style().textStyle().attributes().NSColor);
}
// Copy name and selection status.
var isSelected=layer.isSelected();
shape.name = layer.name();
shape.setIsSelected(isSelected);
// Remove text layer.
parent.removeLayer(layer);
// Add a newly created shape to the text layers' parent group.
parent.addLayers([shape]);
return shape;
}
var doc = context.document;
var page = [doc currentPage];
var layers = page.children();
for (var i = 0; i < layers.count(); i++) {
var layer = layers.objectAtIndex(i);
if(layer) {
var vectorizedTextLayer=convertToOutlines(layer);
print(vectorizedTextLayer);
}
}
})();
Encontré una manera de hacer esto que es
Esto es lo que haces:
chenghuayang