No need to expand CSS 'font' shorthand property, since we're now iterating all style properties.

This commit is contained in:
Jürg Lehni 2013-03-01 10:21:19 -08:00
parent 01026c0896
commit afeb8cbe70
2 changed files with 16 additions and 25 deletions

View file

@ -9,13 +9,13 @@
project.importSvg(document.getElementById('svg')); project.importSvg(document.getElementById('svg'));
</script> </script>
<style type="text/css"> <style type="text/css">
.Border { fill:none; stroke:blue; stroke-width:1 } .Border { fill:none; stroke:blue; stroke-width:1; }
.Connect { fill:none; stroke:#888888; stroke-width:2 } .Connect { fill:none; stroke:#888888; stroke-width:2; }
.SamplePath { fill:none; stroke:red; stroke-width:5 } .SamplePath { fill:none; stroke:red; stroke-width:5; }
.EndPoint { fill:none; stroke:#888888; stroke-width:2 } .EndPoint { fill:none; stroke:#888888; stroke-width:2; }
.CtlPoint { fill:#888888; stroke:none } .CtlPoint { fill:#888888; stroke:none; }
.AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 } .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4; }
.Label { font-size:22; font-family:Verdana } .Label { font-size:22px; font-family: Verdana; }
</style> </style>
</head> </head>
<body> <body>

View file

@ -286,15 +286,6 @@ new function() {
function applyTextAttribute(item, value, name, node) { function applyTextAttribute(item, value, name, node) {
if (item instanceof TextItem) { if (item instanceof TextItem) {
switch (name) { switch (name) {
case 'font':
// TODO: Verify if there is not another way?
var text = document.createElement('span');
text.style.font = value;
for (var i = 0; i < text.style.length; i++) {
var name = text.style[i];
item = applyAttribute(item, text.style[name], name, node);
}
break;
case 'font-family': case 'font-family':
item.setFont(value.split(',')[0].replace(/^\s+|\s+$/g, '')); item.setFont(value.split(',')[0].replace(/^\s+|\s+$/g, ''));
break; break;
@ -349,7 +340,6 @@ new function() {
'fill-opacity': applyOpacity, 'fill-opacity': applyOpacity,
'stroke-opacity': applyOpacity, 'stroke-opacity': applyOpacity,
font: applyTextAttribute,
'font-family': applyTextAttribute, 'font-family': applyTextAttribute,
'font-size': applyTextAttribute, 'font-size': applyTextAttribute,
'text-anchor': applyTextAttribute, 'text-anchor': applyTextAttribute,
@ -431,20 +421,21 @@ new function() {
parentStyles = DomElement.getStyles(node.parentNode); parentStyles = DomElement.getStyles(node.parentNode);
Base.each(attributes, function(apply, key) { Base.each(attributes, function(apply, key) {
// First see if the given attribute is defined. // First see if the given attribute is defined.
var attr = node.attributes[key]; var attr = node.attributes[key],
if (attr) { value = attr && attr.value;
item = applyAttribute(item, attr.value, attr.name, node); if (!value) {
} else {
// Fallback to using styles. See if there is a style, either set // Fallback to using styles. See if there is a style, either set
// directly on the object or applied to it through CSS rules. // directly on the object or applied to it through CSS rules.
// We also need to filter out inheritance from their parents. // We also need to filter out inheritance from their parents.
var name = Base.camelize(key), var name = Base.camelize(key);
value = node.style[name]; value = node.style[name];
if (!value && styles[name] !== parentStyles[name]) if (!value && styles[name] !== parentStyles[name])
value = styles[name]; value = styles[name];
if (value && value != 'none') if (value === 'none')
item = applyAttribute(item, value, key, node); value = null;
} }
if (value)
item = applyAttribute(item, value, key, node);
}); });
return item; return item;
} }