1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 /*
  27  *
  28  *
  29  * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
  30  *
  31  */
  32 
  33 #include "LETypes.h"
  34 #include "OpenTypeUtilities.h"
  35 #include "OpenTypeTables.h"
  36 #include "ICUFeatures.h"
  37 #include "LESwaps.h"
  38 
  39 U_NAMESPACE_BEGIN
  40 
  41 LEReferenceTo<FeatureTable> FeatureListTable::getFeatureTable(const LETableReference &base, le_uint16 featureIndex, LETag *featureTag, LEErrorCode &success) const
  42 {
  43   if (featureIndex >= SWAPW(featureCount) || LE_FAILURE(success)) {
  44     return LEReferenceTo<FeatureTable>();
  45   }
  46 
  47     Offset featureTableOffset = featureRecordArray[featureIndex].featureTableOffset;
  48 
  49     *featureTag = SWAPT(featureRecordArray[featureIndex].featureTag);
  50 
  51     return LEReferenceTo<FeatureTable>(base, success, SWAPW(featureTableOffset));
  52 }
  53 
  54 #if 0
  55 /*
  56  * Note: according to the OpenType Spec. v 1.4, the entries in the Feature
  57  * List Table are sorted alphabetically by feature tag; however, there seem
  58  * to be some fonts which have an unsorted list; that's why the binary search
  59  * is #if 0'd out and replaced by a linear search.
  60  *
  61  * Also note: as of ICU 2.6, this method isn't called anyhow...
  62  */
  63 const FeatureTable *FeatureListTable::getFeatureTable(LETag featureTag) const
  64 {
  65 #if 0
  66     Offset featureTableOffset =
  67         OpenTypeUtilities::getTagOffset(featureTag, (TagAndOffsetRecord *) featureRecordArray, SWAPW(featureCount));
  68 
  69     if (featureTableOffset == 0) {
  70         return 0;
  71     }
  72 
  73     return (const FeatureTable *) ((char *) this + SWAPW(featureTableOffset));
  74 #else
  75     int count = SWAPW(featureCount);
  76 
  77     for (int i = 0; i < count; i += 1) {
  78         if (SWAPT(featureRecordArray[i].featureTag) == featureTag) {
  79             return (const FeatureTable *) ((char *) this + SWAPW(featureRecordArray[i].featureTableOffset));
  80         }
  81     }
  82 
  83     return 0;
  84 #endif
  85 }
  86 #endif
  87 
  88 U_NAMESPACE_END