Changeset 213
- Timestamp:
- 12/28/06 03:10:10 (2 years ago)
- Files:
-
- trunk/TextSubCodec.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/TextSubCodec.c
r211 r213 14 14 // basically random numbers i picked, font size is a factor of the diagonal of the movie window, border is a factor of that 15 15 #define FontSizeRatio .04 16 #define BorderSizeRatio FontSizeRatio * .045 16 #define BorderSizeRatio FontSizeRatio * .09 17 // in pixels 18 #define ShadowDistance 2.8 17 19 18 20 // Constants … … 29 31 CGColorSpaceRef colorSpace; 30 32 31 ATSUStyle textStyle ;33 ATSUStyle textStyle, shadowStyle; 32 34 ATSUTextLayout textLayout; 33 35 //Ptr textBuffer; … … 278 280 TextSubDecompressRecord *myDrp = (TextSubDecompressRecord *)drp->userDecompressRecord; 279 281 float diagonalLength = sqrtf(myDrp->width*myDrp->width+myDrp->height*myDrp->height); 280 ATSUTextMeasurement lineWidth = Long2Fix(myDrp->width), lineHeight = Long2Fix(20) ;282 ATSUTextMeasurement lineWidth = Long2Fix(myDrp->width), lineHeight = Long2Fix(20), ShadowDistFix = FloatToFixed(ShadowDistance); 281 283 // char *dataPtr = (char *)drp->codecData; 282 284 // ICMDataProcRecordPtr dataProc = drp->dataProcRecord.dataProc ? &drp->dataProcRecord : NULL; … … 289 291 ATSUAttributeTag tags[] = {kATSUSizeTag, kATSURGBAlphaColorTag, kATSUStyleRenderingOptionsTag, kATSUFontTag}; 290 292 ByteCount sizes[] = {sizeof(Fixed), sizeof(ATSURGBAlphaColor), sizeof(ATSStyleRenderingOptions), sizeof(ATSUFontID)}; 291 Fixed size = X2Fix(diagonalLength * FontSizeRatio); ATSURGBAlphaColor white = {1,1,1,1} ;293 Fixed size = X2Fix(diagonalLength * FontSizeRatio); ATSURGBAlphaColor white = {1,1,1,1}, black = {0,0,0,1}; 292 294 Boolean trueval = TRUE; ATSUFontID fid; ATSStyleRenderingOptions rend = kATSStyleApplyAntiAliasing; 293 ATSUAttributeValuePtr vals[] = {&size, &white,&rend,&fid};295 ATSUAttributeValuePtr vals[] = {&size, &white, &rend,&fid}; 294 296 ATSUCreateStyle(&glob->textStyle); 295 297 ATSUFindFontFromName(SubFontName,strlen(SubFontName),kFontFullName,kFontNoPlatform,kFontNoScript,kFontNoLanguage,&fid); 296 298 ATSUSetAttributes(glob->textStyle,5, tags, sizes, vals); 299 300 ATSUAttributeTag btags[] = {kATSURGBAlphaColorTag}; 301 ByteCount bsizes[] = {sizeof(ATSURGBAlphaColor)}; 302 ATSUAttributeValuePtr bvals[] = {&black}; 303 304 ATSUCreateAndCopyStyle(glob->textStyle,&glob->shadowStyle); 305 ATSUSetAttributes(glob->shadowStyle,1, btags, bsizes, bvals); 297 306 } 298 307 … … 346 355 347 356 CGContextClearRect(c, CGRectMake(0, 0, myDrp->width, myDrp->height)); 348 CGContextSetRGBStrokeColor(c, 0,0,0,1);349 CGContextSetTextDrawingMode(c, kCGTextFillStroke);350 CGContextSetLineWidth(c, diagonalLength * BorderSizeRatio);351 357 352 358 for (i = breakCount; i >= 0; i--) { 353 359 int end = breaks[i+1]; 354 360 if (end == kATSUToTextEnd) end=sublen; 361 362 // we draw shadow, then stroke text, then fill text 363 // this has several problems relating to hinting and line height and etc. 364 // ideally we'd draw the shadow of every line first (rather than shadow, text, next shadow, next text) 365 // and do a combined outside-stroke-then-fill operation on every line afterwards 366 // but ATSUI only has fill-then-stroke :( 367 CGContextSetTextDrawingMode(c, kCGTextFill); 368 369 ATSUSetRunStyle(glob->textLayout,glob->shadowStyle,kATSUFromTextBeginning,kATSUToTextEnd); 370 371 ATSUDrawText(glob->textLayout, breaks[i], end-breaks[i], Long2Fix(0) + ShadowDistFix, lineHeight - ShadowDistFix); 372 373 ATSUSetRunStyle(glob->textLayout,glob->textStyle,kATSUFromTextBeginning,kATSUToTextEnd); 374 375 CGContextSetRGBStrokeColor(c, 0,0,0,1); 376 CGContextSetTextDrawingMode(c, kCGTextStroke); 377 CGContextSetLineWidth(c, diagonalLength * BorderSizeRatio); 378 355 379 ATSUDrawText(glob->textLayout, breaks[i], end-breaks[i], Long2Fix(0), lineHeight); 356 380 357 381 ATSUTextMeasurement ascent, descent; ByteCount unused; 358 382 ATSUGetLineControl(glob->textLayout, breaks[i], kATSULineAscentTag, sizeof(ATSUTextMeasurement), &ascent, &unused); 359 383 ATSUGetLineControl(glob->textLayout, breaks[i], kATSULineDescentTag, sizeof(ATSUTextMeasurement), &descent, &unused); 384 385 CGContextSetTextDrawingMode(c, kCGTextFill); 386 387 ATSUDrawText(glob->textLayout, breaks[i], end-breaks[i], Long2Fix(0), lineHeight); 388 389 // CGContextSetRGBFillColor(c, 0,0,0,1); 390 // CGContextSetTextDrawingMode(c, kCGTextFill); 391 360 392 lineHeight += ascent + descent; 361 393 }
