A veces es preferible que las líneas de un objeto mantengan su anchura original, independientemente de la transformación aplicada. Por ejemplo, usted dibuja una línea en un mapa que muestra la posición de un usuario y un destino. Cuando el usuario se acerca al mapa, usted quiere ampliar el mapa pero que la línea mantenga su anchura.
En el estándar SVG, el atributo «non-scaling-stroke» indica que el ancho del trazo no depende del zoom o del escalado. En otras palabras, las líneas de un objeto no se ven afectadas por las transformaciones y el zoom.
He aquí un ejemplo de dos rectángulos con el mismo grosor de trazo. El rectángulo de la izquierda utiliza el atributo «trazo sin escala», mientras que el rectángulo de la derecha no utiliza este atributo:
Eche un vistazo al archivo SVG:
<svg viewBox="0 0 90 45" xmlns="http://www.w3.org/2000/svg"> <rect x="1" y="1" width="40" height="40" fill="white" stroke="blue" stroke-width="1px" vector-effect="non-scaling-stroke"/> <rect x="45" y="1" width="40" height="40" fill="white" stroke="green" stroke-width="1px" /> </svg>
También hemos añadido nuevos comandos al tema «4D SVG». Se puede definir el atributo «non-scaling-stroke» a los objetos de dibujo con el método SVG_SET_STROKE_VECTOR_EFFECT método.
// Create view box
.
$svgRef:=SVG_New (90;45)
// First rectangle with the non-scaling-stroke attribute
$rect1 :=SVG_New_rect ($svgRef;1;1;40;40;0;0; "azul"; "blanco";1)
SVG_SET_STROKE_VECTOR_EFFECT ($rect1; "non-scaling-stroke")
// Second rectangle
$rect2 :=SVG_New_rect ($svgRef;45;1;40;40;0;0; "verde"; "blanco";1)
// Save image on disk
File ("/RESOURCES/Images/rectangle.svg").create()
SVG_SAVE_AS_TEXT ($svgRef; File("/RESOURCES/Images/rectangle.svg")platformPath)
// Clear reference
SVG_CLEAR (
$svgRef)