- if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||
- ( tag_close && sptr > 0 && !strcmp(stack[sptr-1].tag, tagname))) {
- int i, j, unknown = 0;
- in += len + tag_close;
- if (!tag_close)
- memset(stack+sptr, 0, sizeof(*stack));
- if (!strcmp(tagname, "font")) {
- if (tag_close) {
- for (i=PARAM_NUMBER-1; i>=0; i--)
- if (stack[sptr-1].param[i][0])
- for (j=sptr-2; j>=0; j--)
- if (stack[j].param[i][0]) {
- av_bprintf(dst, "%s", stack[j].param[i]);
- break;
- }
- } else {
- while (param) {
- if (!strncmp(param, "size=", 5)) {
- unsigned font_size;
- param += 5 + (param[5] == '"');
- if (sscanf(param, "%u", &font_size) == 1) {
- snprintf(stack[sptr].param[PARAM_SIZE],
- sizeof(stack[0].param[PARAM_SIZE]),
- "{\\fs%u}", font_size);
- }
- } else if (!strncmp(param, "color=", 6)) {
- param += 6 + (param[6] == '"');
- snprintf(stack[sptr].param[PARAM_COLOR],
- sizeof(stack[0].param[PARAM_COLOR]),
- "{\\c&H%X&}",
- html_color_parse(log_ctx, param));
- } else if (!strncmp(param, "face=", 5)) {
- param += 5 + (param[5] == '"');
- len = strcspn(param,
- param[-1] == '"' ? "\"" :" ");
- av_strlcpy(tmp, param,
- FFMIN(sizeof(tmp), len+1));
- param += len;
- snprintf(stack[sptr].param[PARAM_FACE],
- sizeof(stack[0].param[PARAM_FACE]),
- "{\\fn%s}", tmp);
+
+ /* Check if this is likely a tag */
+#define LIKELY_A_TAG_CHAR(x) (((x) >= '0' && (x) <= '9') || \
+ ((x) >= 'a' && (x) <= 'z') || \
+ ((x) >= 'A' && (x) <= 'Z') || \
+ (x) == '_' || (x) == '/')
+ for (i = 0; tagname[i]; i++) {
+ if (!LIKELY_A_TAG_CHAR(tagname[i])) {
+ likely_a_tag = 0;
+ break;
+ }
+ }
+
+ if (!av_strcasecmp(tagname, "font")) {
+ if (tag_close && sptr > 0) {
+ struct font_tag *cur_tag = &stack[sptr--];
+ struct font_tag *last_tag = &stack[sptr];
+
+ if (cur_tag->size) {
+ if (!last_tag->size)
+ av_bprintf(dst, "{\\fs}");
+ else if (last_tag->size != cur_tag->size)
+ av_bprintf(dst, "{\\fs%d}", last_tag->size);
+ }
+
+ if (cur_tag->color & 0xff000000) {
+ if (!(last_tag->color & 0xff000000))
+ av_bprintf(dst, "{\\c}");
+ else if (last_tag->color != cur_tag->color)
+ av_bprintf(dst, "{\\c&H%"PRIX32"&}", last_tag->color & 0xffffff);
+ }
+
+ if (cur_tag->face[0]) {
+ if (!last_tag->face[0])
+ av_bprintf(dst, "{\\fn}");
+ else if (strcmp(last_tag->face, cur_tag->face))
+ av_bprintf(dst, "{\\fn%s}", last_tag->face);
+ }
+ } else if (!tag_close && sptr < FF_ARRAY_ELEMS(stack) - 1) {
+ struct font_tag *new_tag = &stack[sptr + 1];
+
+ *new_tag = stack[sptr++];
+
+ while (param) {
+ if (!av_strncasecmp(param, "size=", 5)) {
+ param += 5 + (param[5] == '"');
+ if (sscanf(param, "%u", &new_tag->size) == 1)
+ av_bprintf(dst, "{\\fs%u}", new_tag->size);
+ } else if (!av_strncasecmp(param, "color=", 6)) {
+ int color;
+ param += 6 + (param[6] == '"');
+ color = html_color_parse(log_ctx, param);
+ if (color >= 0) {
+ new_tag->color = 0xff000000 | color;
+ av_bprintf(dst, "{\\c&H%"PRIX32"&}", new_tag->color & 0xffffff);