Home | History | Annotate | Download | only in mac
      1 /*
      2  * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
      3  * Copyright (C) 2006 Alexey Proskuryakov
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      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.
     28  */
     29 
     30 #import "config.h"
     31 #import "SimpleFontData.h"
     32 
     33 #if USE(ATSUI)
     34 
     35 #import "Font.h"
     36 #import "FontCache.h"
     37 #import "FontDescription.h"
     38 #import <ApplicationServices/ApplicationServices.h>
     39 #import <AppKit/AppKit.h>
     40 #import <wtf/Assertions.h>
     41 
     42 using namespace std;
     43 
     44 namespace WebCore {
     45 
     46 void SimpleFontData::checkShapesArabic() const
     47 {
     48     ASSERT(!m_checkedShapesArabic);
     49 
     50     m_checkedShapesArabic = true;
     51 
     52     ATSUFontID fontID = m_platformData.ctFont() ? CTFontGetPlatformFont(m_platformData.ctFont(), 0) : 0;
     53     if (!fontID) {
     54         LOG_ERROR("unable to get ATSUFontID for %@", m_platformData.font());
     55         return;
     56     }
     57 
     58     // This function is called only on fonts that contain Arabic glyphs. Our
     59     // heuristic is that if such a font has a glyph metamorphosis table, then
     60     // it includes shaping information for Arabic.
     61     FourCharCode tables[] = { 'morx', 'mort' };
     62     for (size_t i = 0; i < WTF_ARRAY_LENGTH(tables); ++i) {
     63         ByteCount tableSize;
     64         OSStatus status = ATSFontGetTable(fontID, tables[i], 0, 0, 0, &tableSize);
     65         if (status == noErr) {
     66             m_shapesArabic = true;
     67             return;
     68         }
     69 
     70         if (status != kATSInvalidFontTableAccess)
     71             LOG_ERROR("ATSFontGetTable failed (%d)", status);
     72     }
     73 }
     74 
     75 } // namespace WebCore
     76 
     77 #endif
     78