Changeset 134146 in webkit


Ignore:
Timestamp:
Nov 9, 2012, 7:34:19 PM (13 years ago)
Author:
mitz@apple.com
Message:

SimpleFontData::getCFStringAttributes sets some attributes to their default values, but shouldn’t
https://bugs.webkit.org/show_bug.cgi?id=101799

Reviewed by Alexey Proskuryakov.

In some configurations, setting kCTLigatureAttributeName to its default value of 1 yields
different behavior from not setting it at all. We can get the correct behavior and greatly
simplify the code by not setting attributes to their default values.

  • platform/graphics/mac/SimpleFontDataCoreText.cpp:

Removed redundant #import directives and changed the remaining ones to #include.
(WebCore::SimpleFontData::getCFStringAttributes): Changed to use a mutable dictionary and
only add attributes that have non-default values.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r134144 r134146  
     12012-11-09  Dan Bernstein  <mitz@apple.com>
     2
     3        SimpleFontData::getCFStringAttributes sets some attributes to their default values, but shouldn’t
     4        https://bugs.webkit.org/show_bug.cgi?id=101799
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        In some configurations, setting kCTLigatureAttributeName to its default value of 1 yields
     9        different behavior from not setting it at all. We can get the correct behavior and greatly
     10        simplify the code by not setting attributes to their default values.
     11
     12        * platform/graphics/mac/SimpleFontDataCoreText.cpp:
     13        Removed redundant #import directives and changed the remaining ones to #include.
     14        (WebCore::SimpleFontData::getCFStringAttributes): Changed to use a mutable dictionary and
     15        only add attributes that have non-default values.
     16
    1172012-11-09  Rick Byers  <rbyers@chromium.org>
    218
  • TabularUnified trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataCoreText.cpp

    r130612 r134146  
    11/*
    2  * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2005, 2006, 2012 Apple Inc. All rights reserved.
    33 * Copyright (C) 2006 Alexey Proskuryakov
    44 *
     
    66 * modification, are permitted provided that the following conditions
    77 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
    813 *
    9  * 1.  Redistributions of source code must retain the above copyright
    10  *     notice, this list of conditions and the following disclaimer.
    11  * 2.  Redistributions in binary form must reproduce the above copyright
    12  *     notice, this list of conditions and the following disclaimer in the
    13  *     documentation and/or other materials provided with the distribution.
    14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
    15  *     its contributors may be used to endorse or promote products derived
    16  *     from this software without specific prior written permission.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
    22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     24 * THE POSSIBILITY OF SUCH DAMAGE.
    2825 */
    2926
    30 #import "config.h"
    31 #import "SimpleFontData.h"
     27#include "config.h"
     28#include "SimpleFontData.h"
    3229
    33 #import "Font.h"
    34 #import "FontCache.h"
    35 #import "FontDescription.h"
    36 #import <ApplicationServices/ApplicationServices.h>
    37 
    38 using namespace std;
     30#include <CoreText/CoreText.h>
    3931
    4032namespace WebCore {
     
    4739    if (!addResult.isNewEntry)
    4840        return attributesDictionary.get();
    49    
    50     bool treatLineAsVertical = orientation == Vertical;
    5141
    52     bool allowLigatures = (!treatLineAsVertical && platformData().allowsLigatures()) || (typesettingFeatures & Ligatures);
     42    attributesDictionary.adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
     43    CFMutableDictionaryRef mutableAttributes = (CFMutableDictionaryRef)attributesDictionary.get();
    5344
    54     static const int ligaturesNotAllowedValue = 0;
    55     static CFNumberRef ligaturesNotAllowed = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &ligaturesNotAllowedValue);
    56 
    57     static const int ligaturesAllowedValue = 1;
    58     static CFNumberRef ligaturesAllowed = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &ligaturesAllowedValue);
     45    CFDictionarySetValue(mutableAttributes, kCTFontAttributeName, platformData().ctFont());
    5946
    6047    if (!(typesettingFeatures & Kerning)) {
    61         static const float kerningAdjustmentValue = 0;
    62         static CFNumberRef kerningAdjustment = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &kerningAdjustmentValue);
    63         static const void* keysWithKerningDisabled[] = { kCTFontAttributeName, kCTKernAttributeName, kCTLigatureAttributeName, kCTVerticalFormsAttributeName };
    64         const void* valuesWithKerningDisabled[] = { platformData().ctFont(), kerningAdjustment, allowLigatures
    65             ? ligaturesAllowed : ligaturesNotAllowed, treatLineAsVertical ? kCFBooleanTrue : kCFBooleanFalse };
    66         attributesDictionary.adoptCF(CFDictionaryCreate(0, keysWithKerningDisabled, valuesWithKerningDisabled,
    67             WTF_ARRAY_LENGTH(keysWithKerningDisabled), &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    68     } else {
    69         // By omitting the kCTKernAttributeName attribute, we get Core Text's standard kerning.
    70         static const void* keysWithKerningEnabled[] = { kCTFontAttributeName, kCTLigatureAttributeName, kCTVerticalFormsAttributeName };
    71         const void* valuesWithKerningEnabled[] = { platformData().ctFont(), allowLigatures ? ligaturesAllowed : ligaturesNotAllowed, treatLineAsVertical ? kCFBooleanTrue : kCFBooleanFalse };
    72         attributesDictionary.adoptCF(CFDictionaryCreate(0, keysWithKerningEnabled, valuesWithKerningEnabled,
    73             WTF_ARRAY_LENGTH(keysWithKerningEnabled), &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
     48        const float zero = 0;
     49        static CFNumberRef zeroKerningValue = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &zero);
     50        CFDictionarySetValue(mutableAttributes, kCTKernAttributeName, zeroKerningValue);
    7451    }
     52
     53    bool allowLigatures = (orientation == Horizontal && platformData().allowsLigatures()) || (typesettingFeatures & Ligatures);
     54    if (!allowLigatures) {
     55        const int zero = 0;
     56        static CFNumberRef essentialLigaturesValue = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &zero);
     57        CFDictionarySetValue(mutableAttributes, kCTLigatureAttributeName, essentialLigaturesValue);
     58    }
     59
     60    if (orientation == Vertical)
     61        CFDictionarySetValue(mutableAttributes, kCTVerticalFormsAttributeName, kCFBooleanTrue);
    7562
    7663    return attributesDictionary.get();
Note: See TracChangeset for help on using the changeset viewer.