Changeset 764

Show
Ignore:
Timestamp:
01/13/08 19:00:12 (6 months ago)
Author:
astrange
Message:

Fix misaligned SSA multi-line toptitles. Closes #280 for now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/perian-1.1/Subtitles/SubATSUIRenderer.m

    r762 r764  
    541541} 
    542542 
    543 static void GetTypographicRectangleForLayout(ATSUTextLayout layout, UniCharArrayOffset *breaks, ItemCount breakCount, Fixed *lX, Fixed *lY, Fixed *height, Fixed *width) 
     543static void GetTypographicRectangleForLayout(ATSUTextLayout layout, UniCharArrayOffset *breaks, ItemCount breakCount, Fixed extraHeight, Fixed *lX, Fixed *lY, Fixed *height, Fixed *width) 
    544544{ 
    545545        ATSTrapezoid trap = {0}; 
     
    555555                ATSUGetGlyphBounds(layout, 0, baseY, breaks[i], end-breaks[i], kATSUseDeviceOrigins, 1, &trap, &trapCount); 
    556556 
    557                 baseY += GetLineHeight(layout, breaks[i])
     557                baseY += GetLineHeight(layout, breaks[i]) + extraHeight
    558558                 
    559559                rect.bottom = MAX(trap.lowerLeft.y, trap.lowerRight.y); 
     
    575575        *width = largeRect.right - largeRect.left; 
    576576} 
     577 
     578#if 0 
     579static void GetImageBoundingBoxForLayout(ATSUTextLayout layout, UniCharArrayOffset *breaks, ItemCount breakCount, Fixed extraHeight, Fixed *lX, Fixed *lY, Fixed *height, Fixed *width) 
     580{ 
     581        Rect largeRect = {0}; 
     582        ATSUTextMeasurement baseY = 0; 
     583        int i; 
     584         
     585        for (i = breakCount; i >= 0; i--) { 
     586                UniCharArrayOffset end = breaks[i+1]; 
     587                Rect rect; 
     588                 
     589                ATSUMeasureTextImage(layout, breaks[i], end-breaks[i], 0, baseY, &rect); 
     590                 
     591                baseY += GetLineHeight(layout, breaks[i]) + extraHeight; 
     592                 
     593                if (i == breakCount) largeRect = rect; 
     594                 
     595                largeRect.bottom = MAX(largeRect.bottom, rect.bottom); 
     596                largeRect.left = MIN(largeRect.left, rect.left); 
     597                largeRect.top = MIN(largeRect.top, rect.top); 
     598                largeRect.right = MAX(largeRect.right, rect.right); 
     599                        } 
     600         
     601         
     602        if (lX) *lX = IntToFixed(largeRect.left); 
     603        if (lY) *lY = IntToFixed(largeRect.bottom); 
     604        *height = IntToFixed(largeRect.bottom - largeRect.top); 
     605        *width = IntToFixed(largeRect.right - largeRect.left); 
     606} 
     607#endif 
    577608 
    578609enum {fillc, strokec}; 
     
    806837                ATSUTextMeasurement lineWidth, lineHeight, lineX, lineY; 
    807838                UniCharArrayOffset breaks[2] = {thisBreak, thisBreak + lineLen}; 
    808                 GetTypographicRectangleForLayout(layout, breaks, 0, &lineX, &lineY, &lineHeight, &lineWidth); 
     839                GetTypographicRectangleForLayout(layout, breaks, 0, FloatToFixed(spanEx->outlineRadius), &lineX, &lineY, &lineHeight, &lineWidth); 
    809840                 
    810841                CGRect borderRect = CGRectMake(FixedToFloat(lineX + penX), FixedToFloat(penY - lineY), FixedToFloat(lineWidth), FixedToFloat(lineHeight)); 
     
    954985                ATSUTextMeasurement imageWidth, imageHeight; 
    955986 
    956                 if (div->posX != -1 || div->alignV == kSubAlignmentMiddle) GetTypographicRectangleForLayout(layout, breaks, breakCount, NULL, NULL, &imageHeight, &imageWidth); 
     987                if (div->posX != -1 || div->alignV == kSubAlignmentMiddle) GetTypographicRectangleForLayout(layout, breaks, breakCount, FloatToFixed(div->styleLine->outlineRadius), NULL, NULL, &imageHeight, &imageWidth); 
    957988 
    958989                if (div->posX == -1) { 
     
    9941025                        } 
    9951026                         
     1027                        ATSUGetLineControl(layout, kATSUFromTextBeginning, kATSULineDescentTag, sizeof(ATSUTextMeasurement), &descent, NULL); 
     1028 
    9961029                        switch (div->alignV) { 
    9971030                                case kSubAlignmentMiddle: penY -= imageHeight / 2; break; 
    998                                 case kSubAlignmentTop: penY -= imageHeight; 
    999                         } 
    1000                          
    1001                         ATSUGetLineControl(layout, kATSUFromTextBeginning, kATSULineDescentTag, sizeof(ATSUTextMeasurement), &descent, NULL); 
     1031                                case kSubAlignmentTop: penY -= imageHeight; break; 
     1032                        } 
    10021033                         
    10031034                        penY += descent; 
    1004                                                  
     1035 
    10051036                        SetLayoutPositioning(layout, imageWidth, div->alignH); 
    10061037                        storePen = NULL; breakc.lStart = breakCount; breakc.lEnd = -1; breakc.direction = 1;