Comments (5)
tts_textOutline_black_2px_0px.ttml.txt
This is not a valid IMSC1 file since IMSC1 forbids blur radius.
tts_textOutline_blue_5pct.ttml.txt
tts_textOutline_black_2px.ttml.txt
A slight outline is displayed in both cases. It is easier to see against a dark background -- see tts_textOutline_black_2px-pal.ttml.txt.
Since CSS does not support text outline, imscJS instead uses text shadow with a fixed 1px blur radius as a fallback.
Alternatives include using the webkit-specific -webkit-text-stroke
and/or the simulation trick at https://css-tricks.com/adding-stroke-to-web-text/.
Thoughts?
from imscjs.
Ok, I see that it is there, just smaller than expected. I think at least setting the CSS shadow to the intended outline thickness will give a closer approximation, although still not perfect as you mentioned.
I tried another example with white background and tts:textOutline="black 10%". Given that the font size is being computed to 22.5px and the outline is 10% in this example, I would expect the outline thickness to be computed at 2.25px. If I manually change the CSS shadow size from 1px to 2.25px then it looks closer to what I'd expect and closer what the example screenshot from the TTML spec shows. Take a look at this screenshot and zoom in on the line "How cheerfully..."
What do you think?
from imscjs.
What do you think?
Ok. Will do.
from imscjs.
-webkit-text-stroke can only do a center aligned stroke, which looks terrible for larger stroke widths, so that is not a useful alternative IMHO. The hack with multiple shadows looks ok at 1px (better than a single shadow at least) but looks worse at > 1 px. That's unfortunate...
from imscjs.
Hi Pierre,
I notice textOutline is currently ignored by current imscJS?
thoughts on the below?
ref textOutline, I map
tts:textOutline="black 0.05em 0.05em"
to (roughly):
text-shadow:
black 0.05em 0.05em 0.05em,
black -0.05em -0.05em 0.05em,
black -0.05em 0.05em 0.05em,
black 0.05em -0.05em 0.05em,
black 0 0.04em 0.05em,
black 0 -0.04em 0.05em,
black -0.04em 0 0.05em,
black 0.04em 0em 0.05em;
in my (old) imsc.js, I have added:
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling textOutline",
function (context, dom_element, isd_element, attr) {
if (attr === "none") {
dom_element.style.textShadow = "";
} else {
let color = "rgba(" +
attr.color[0].toString() + "," +
attr.color[1].toString() + "," +
attr.color[2].toString() + "," +
(attr.color[3] / 255).toString() +
") ";
let xyval = (attr.thickness * context.h) + "px ";
let diagval = ((attr.thickness*0.75) * context.h) + "px ";
let blur = (attr.blur * context.h) + "px ";
textshadow = '';
textshadow += color+xyval+'0px '+blur+', ';
textshadow += color+'-'+xyval+'0px '+blur+', ';
textshadow += color+'0px '+xyval+blur+', ';
textshadow += color+'0px -'+xyval+blur+', ';
textshadow += color+diagval+diagval+blur+', ';
textshadow += color+'-'+diagval+diagval+blur+', ';
textshadow += color+'-'+diagval+'-'+diagval+blur+', ';
textshadow += color+diagval+'-'+diagval+blur;
dom_element.style.textShadow = textshadow;
}
}
),
and
new StylingAttributeDefinition(
imscNames.ns_tts,
"textOutline",
"none",
['span'],
true,
true,
function (str) {
/*
* returns {c: <color>?, thichness: <length>} | "none"
*
*/
if (str === "none") {
return str;
} else {
var r = {};
var s = str.split(" ");
if (s.length === 0 || s.length > 3) return null;
var c = imscUtils.parseColor(s[0]);
r.color = c;
if (c !== null) s.shift();
//if (s.length !== 1) return null;
var l = imscUtils.parseLength(s[0]);
if (!l) return null;
r.thickness = l;
r.blur = '0%';
if (s.length > 1){
s.shift();
l = imscUtils.parseLength(s[0]);
r.blur = l;
}
return r;
}
},
function (doc, parent, element, attr) {
/*
* returns {color: <color>, thickness: <norm length>}
*
*/
if (attr === "none") return attr;
var rslt = {};
if (attr.color === null) {
rslt.color = element.styleAttrs[imscStyles.byName.color.qname];
} else {
rslt.color = attr.color;
}
if (attr.thickness.unit === "%") {
rslt.thickness = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.thickness.value / 100;
} else if (attr.thickness.unit === "em") {
rslt.thickness = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.thickness.value;
} else if (attr.thickness.unit === "c") {
rslt.thickness = attr.thickness.value / doc.cellResolution.h;
} else if (attr.thickness.unit === "px") {
rslt.thickness = attr.thickness.value / doc.pxDimensions.h;
} else {
return null;
}
if (attr.blur.unit === "%") {
rslt.blur = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.blur.value / 100;
} else if (attr.blur.unit === "em") {
rslt.blur = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.blur.value;
} else if (attr.blur.unit === "c") {
rslt.blur = attr.blur.value / doc.cellResolution.h;
} else if (attr.blur.unit === "px") {
rslt.blur = attr.blur.value / doc.pxDimensions.h;
} else {
return null;
}
return rslt;
}
),
from imscjs.
Related Issues (20)
- semi-opaque backgroundColor and fillLineGap don't play nicely HOT 2
- actual line height is greater than specified lineHeight HOT 1
- Add back support for fontShear HOT 6
- For .. in loops not protected from iterating prototype properties HOT 14
- Upgrade to use es6 language features? HOT 1
- `Set()` has a name clash with the ES6 `Set` object HOT 1
- Multiple referenced generic font family names can result in duplicate font-family values
- Error parsing fontSize with two lengths HOT 2
- Improve performance with a large number of regions and ISDs
- Unable to specify rgba color values for tts:textShadow HOT 1
- elementBoundingRect needs to be declared a `var`
- Update timeBase attribute to accept full list of values HOT 6
- adjacent tts:textCombine spans are combined into a single span HOT 3
- HTML rb, rtc and rbc elements are deprecated HOT 2
- if a line starts/ends with a ruby definition, line padding is not applied
- SMPTE timecode parsed incorrectly (23.976 FPS) HOT 1
- Resolve images source while generating ISD HOT 18
- Replace the XML SAX parser with a DOM parser HOT 6
- Spaces in `tts:fontFamily` list not handled in HTMLStylingMapDefinition code HOT 1
- Firefox bug with negative margins HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imscjs.