Changeset 1013
- Timestamp:
- 01/17/09 16:07:06 (1 year ago)
- Files:
-
- trunk/Subtitles/SubATSUIRenderer.h (modified) (1 diff)
- trunk/Subtitles/SubATSUIRenderer.m (modified) (16 diffs)
- trunk/Subtitles/SubParsing.m.rl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Subtitles/SubATSUIRenderer.h
r887 r1013 19 19 SubContext *context; 20 20 unichar *ubuffer; 21 UniCharArrayOffset *breakbuffer; 21 22 ATSUTextLayout layout; 22 23 float screenScaleX, screenScaleY, videoWidth, videoHeight; trunk/Subtitles/SubATSUIRenderer.m
r940 r1013 216 216 ATSUCreateTextLayout(&layout); 217 217 ubuffer = malloc(sizeof(unichar) * 128); 218 breakbuffer = malloc(sizeof(UniCharArrayOffset) * 2); 219 218 220 srgbCSpace = GetSRGBColorSpace(); 219 221 … … 243 245 244 246 ubuffer = malloc(sizeof(unichar) * 128); 247 breakbuffer = malloc(sizeof(UniCharArrayOffset) * 2); 245 248 246 249 videoWidth = width; … … 260 263 { 261 264 [context release]; 265 free(breakbuffer); 262 266 free(ubuffer); 263 267 CGColorSpaceRelease(srgbCSpace); … … 269 273 -(void)finalize 270 274 { 275 free(breakbuffer); 271 276 free(ubuffer); 272 277 UCDisposeTextBreakLocator(&breakLocator); … … 315 320 ATSUFontID font; 316 321 322 // should be kFontMicrosoftPlatform for the platform code 323 // but isn't for bug workarounds 317 324 ATSUFindFontFromName(uname, nlen * sizeof(unichar), kFontFamilyName, kFontNoPlatformCode, kFontNoScript, kFontNoLanguage, &font); 318 325 … … 381 388 SetATSUStyleOther(style, kATSUFontMatrixTag, sizeof(CGAffineTransform), &mat); 382 389 } 383 390 384 391 const ATSUFontFeatureType ftypes[] = {kLigaturesType, kTypographicExtrasType, kTypographicExtrasType, kTypographicExtrasType}; 385 392 const ATSUFontFeatureSelector fsels[] = {kCommonLigaturesOnSelector, kSmartQuotesOnSelector, kPeriodsToEllipsisOnSelector, kHyphenToEnDashOnSelector}; 386 393 387 394 ATSUSetFontFeatures(style, sizeof(ftypes) / sizeof(ATSUFontFeatureType), ftypes, fsels); 388 395 389 396 return style; 390 397 } … … 785 792 } 786 793 787 static UniCharArrayOffset *FindLineBreaks(ATSUTextLayout layout, SubRenderDiv *div, TextBreakLocatorRef breakLocator, ItemCount *nbreaks, Fixed breakingWidth, unichar *utext, unsigned textLen) 788 { 789 UniCharArrayOffset *breaks; 794 static UniCharArrayOffset *FindLineBreaks(ATSUTextLayout layout, SubRenderDiv *div, TextBreakLocatorRef breakLocator, UniCharArrayOffset *breaks, ItemCount *nbreaks, Fixed breakingWidth, unichar *utext, unsigned textLen) 795 { 790 796 ItemCount breakCount=0; 791 797 … … 807 813 } 808 814 809 breaks = malloc(sizeof(UniCharArrayOffset) * (breakCount+2));815 breaks = realloc(breaks, sizeof(UniCharArrayOffset) * (breakCount+2)); 810 816 ATSUGetSoftLineBreaks(layout, kATSUFromTextBeginning, kATSUToTextEnd, breakCount, &breaks[1], NULL); 811 817 812 818 breaks[0] = 0; 813 819 breaks[breakCount+1] = textLen; 814 820 815 821 *nbreaks = breakCount; 816 822 return breaks; … … 878 884 879 885 static void RenderActualLine(ATSUTextLayout layout, UniCharArrayOffset thisBreak, UniCharArrayOffset lineLen, Fixed penX, Fixed penY, CGContextRef c, SubRenderDiv *div, SubATSUISpanEx *spanEx, int textType) 880 { 886 { 887 //ATS bug(?) with some fonts: 888 //drawing \n draws some random other character, so skip them 889 //XXX maybe don't store newlines in div->text at all 890 if ([div->text characterAtIndex:thisBreak+lineLen-1] == '\n') { 891 lineLen--; 892 if (!lineLen) return; 893 } 894 881 895 if (textType == kTextLayerOutline && div->styleLine->borderStyle == kSubBorderStyleBox) { 882 896 ATSUTextMeasurement lineWidth, lineHeight, lineX, lineY; … … 917 931 } else { 918 932 int j, spans = [div->spans count]; 933 934 //linear search for the next span to draw 919 935 for (j = 0; j < spans; j++) { 920 936 SubRenderSpan *span = [div->spans objectAtIndex:j]; … … 928 944 929 945 if (spanLen == 0) continue; 930 if ((span->offset + spanLen) < thisBreak) continue; 931 if (span->offset >= nextBreak) break; 946 if ((span->offset + spanLen) < thisBreak) continue; // too early 947 if (span->offset >= nextBreak) break; // too far ahead 932 948 933 if (span->offset < thisBreak) { 949 if (span->offset < thisBreak) { // text spans a newline 934 950 drawStart = thisBreak; 935 951 drawLen = spanLen - (thisBreak - span->offset); … … 938 954 drawLen = spanLen; 939 955 } 940 956 941 957 endLayer = SetupCGForSpan(c, spanEx, lastSpanEx, div, textType, endLayer); 942 958 RenderActualLine(layout, drawStart, drawLen, (textType == kTextLayerShadow) ? (penX + FloatToFixed(spanEx->shadowDist)) : penX, … … 1005 1021 unsigned textLen = [div->text length]; 1006 1022 BOOL resetPens = NO; 1007 if (!textLen ) continue;1008 1023 if (!textLen || ![div->spans count]) continue; 1024 1009 1025 if (div->layer != lastLayer) { 1010 1026 resetPens = YES; … … 1019 1035 marginRect.size.height *= screenScaleY; 1020 1036 1021 Fixed penY, penX, breakingWidth = FloatToFixed(marginRect.size.width); BreakContext breakc = {0}; 1037 Fixed penY, penX, breakingWidth = FloatToFixed(marginRect.size.width); 1038 BreakContext breakc = {0}; ItemCount breakCount; 1022 1039 1023 1040 [div->text getCharacters:ubuffer]; … … 1029 1046 SetStyleSpanRuns(layout, div); 1030 1047 1031 ItemCount breakCount;1032 UniCharArrayOffset *breaks = FindLineBreaks(layout, div, breakLocator, &breakCount, breakingWidth, ubuffer, textLen); 1048 breakbuffer = FindLineBreaks(layout, div, breakLocator, breakbuffer, &breakCount, breakingWidth, ubuffer, textLen); 1049 1033 1050 ATSUTextMeasurement imageWidth, imageHeight; 1034 1035 if (div->positioned || div->alignV == kSubAlignmentMiddle) GetTypographicRectangleForLayout(layout, breaks, breakCount, FloatToFixed(div->styleLine->outlineRadius), NULL, NULL, &imageHeight, &imageWidth); 1051 UniCharArrayOffset *breaks = breakbuffer; 1052 1053 if (div->positioned || div->alignV == kSubAlignmentMiddle) 1054 GetTypographicRectangleForLayout(layout, breaks, breakCount, FloatToFixed(div->styleLine->outlineRadius), NULL, NULL, &imageHeight, &imageWidth); 1036 1055 1037 1056 if (!div->positioned) { … … 1099 1118 1100 1119 if (storePen) *storePen = penY; 1101 1102 free(breaks);1103 1120 } 1104 1121 trunk/Subtitles/SubParsing.m.rl
r988 r1013 397 397 398 398 action backslash_handler { 399 [div->text appendString:send()]; 399 p--; 400 [div->text appendString:send()]; 400 401 unichar c = *(p+1), o=c; 401 402 … … 408 409 o = 0xA0; //non-breaking space 409 410 break; 410 default:411 o = c;412 411 } 413 }414 415 [div->text appendFormat:@"%C",o];412 413 [div->text appendFormat:@"%C",o]; 414 } 416 415 417 416 chars_deleted++; 418 417 419 outputbegin = p+2; 418 p++; 419 outputbegin = p+1; 420 420 } 421 421 … … 449 449 } 450 450 451 special = ("\\" any) >backslash_handler | tag >enter_tag @exit_tag;451 special = ("\\" :> any) @backslash_handler | tag >enter_tag @exit_tag; 452 452 sub_text_char = [^\\{]; 453 453 sub_text = sub_text_char*;
