gfx/skia/trunk/include/core/SkFontHost.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkFontHost.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkFontHost_DEFINED
    1.14 +#define SkFontHost_DEFINED
    1.15 +
    1.16 +#include "SkTypeface.h"
    1.17 +
    1.18 +class SkDescriptor;
    1.19 +class SkScalerContext;
    1.20 +struct SkScalerContextRec;
    1.21 +class SkStream;
    1.22 +class SkWStream;
    1.23 +
    1.24 +/** \class SkFontHost
    1.25 +
    1.26 +    This class is ported to each environment. It is responsible for bridging
    1.27 +    the gap between the (sort of) abstract class SkTypeface and the
    1.28 +    platform-specific implementation that provides access to font files.
    1.29 +
    1.30 +    One basic task is for each create (subclass of) SkTypeface, the FontHost is
    1.31 +    responsible for assigning a uniqueID. The ID should be unique for the
    1.32 +    underlying font file/data, not unique per typeface instance. Thus it is
    1.33 +    possible/common to request a typeface for the same font more than once
    1.34 +    (e.g. asking for the same font by name several times). The FontHost may
    1.35 +    return seperate typeface instances in that case, or it may choose to use a
    1.36 +    cache and return the same instance (but calling typeface->ref(), since the
    1.37 +    caller is always responsible for calling unref() on each instance that is
    1.38 +    returned). Either way, the fontID for those instance(s) will be the same.
    1.39 +    In addition, the fontID should never be set to 0. That value is used as a
    1.40 +    sentinel to indicate no-font-id.
    1.41 +
    1.42 +    The major aspects are:
    1.43 +    1) Given either a name/style, return a subclass of SkTypeface that
    1.44 +        references the closest matching font available on the host system.
    1.45 +    2) Given the data for a font (either in a stream or a file name), return
    1.46 +        a typeface that allows access to that data.
    1.47 +    3) Each typeface instance carries a 32bit ID for its corresponding font.
    1.48 +        SkFontHost turns that ID into a stream to access the font's data.
    1.49 +    4) Given a font ID, return a subclass of SkScalerContext, which connects a
    1.50 +        font scaler (e.g. freetype or other) to the font's data.
    1.51 +    5) Utilites to manage the font cache (budgeting) and gamma correction
    1.52 +*/
    1.53 +class SK_API SkFontHost {
    1.54 +public:
    1.55 +    /** LCDs either have their color elements arranged horizontally or
    1.56 +     vertically. When rendering subpixel glyphs we need to know which way
    1.57 +     round they are.
    1.58 +
    1.59 +     Note, if you change this after startup, you'll need to flush the glyph
    1.60 +     cache because it'll have the wrong type of masks cached.
    1.61 +
    1.62 +     @deprecated use SkPixelGeometry instead.
    1.63 +     */
    1.64 +    enum LCDOrientation {
    1.65 +        kHorizontal_LCDOrientation = 0,    //!< this is the default
    1.66 +        kVertical_LCDOrientation   = 1
    1.67 +    };
    1.68 +
    1.69 +    /** @deprecated set on Device creation. */
    1.70 +    static void SetSubpixelOrientation(LCDOrientation orientation);
    1.71 +    /** @deprecated get from Device. */
    1.72 +    static LCDOrientation GetSubpixelOrientation();
    1.73 +
    1.74 +    /** LCD color elements can vary in order. For subpixel text we need to know
    1.75 +     the order which the LCDs uses so that the color fringes are in the
    1.76 +     correct place.
    1.77 +
    1.78 +     Note, if you change this after startup, you'll need to flush the glyph
    1.79 +     cache because it'll have the wrong type of masks cached.
    1.80 +
    1.81 +     kNONE_LCDOrder means that the subpixel elements are not spatially
    1.82 +     separated in any usable fashion.
    1.83 +
    1.84 +     @deprecated use SkPixelGeometry instead.
    1.85 +     */
    1.86 +    enum LCDOrder {
    1.87 +        kRGB_LCDOrder = 0,    //!< this is the default
    1.88 +        kBGR_LCDOrder = 1,
    1.89 +        kNONE_LCDOrder = 2
    1.90 +    };
    1.91 +
    1.92 +    /** @deprecated set on Device creation. */
    1.93 +    static void SetSubpixelOrder(LCDOrder order);
    1.94 +    /** @deprecated get from Device. */
    1.95 +    static LCDOrder GetSubpixelOrder();
    1.96 +
    1.97 +private:
    1.98 +    /** Return a new, closest matching typeface given either an existing family
    1.99 +        (specified by a typeface in that family) or by a familyName and a
   1.100 +        requested style.
   1.101 +        1) If familyFace is null, use familyName.
   1.102 +        2) If familyName is null, use data (UTF-16 to cover).
   1.103 +        3) If all are null, return the default font that best matches style
   1.104 +     */
   1.105 +    static SkTypeface* CreateTypeface(const SkTypeface* familyFace,
   1.106 +                                      const char familyName[],
   1.107 +                                      SkTypeface::Style style);
   1.108 +
   1.109 +    /** Return a new typeface given the data buffer. If the data does not
   1.110 +        represent a valid font, returns null.
   1.111 +
   1.112 +        If a typeface instance is returned, the caller is responsible for
   1.113 +        calling unref() on the typeface when they are finished with it.
   1.114 +
   1.115 +        The returned typeface may or may not have called ref() on the stream
   1.116 +        parameter. If the typeface has not called ref(), then it may have made
   1.117 +        a copy of the releveant data. In either case, the caller is still
   1.118 +        responsible for its refcnt ownership of the stream.
   1.119 +     */
   1.120 +    static SkTypeface* CreateTypefaceFromStream(SkStream*);
   1.121 +
   1.122 +    /** Return a new typeface from the specified file path. If the file does not
   1.123 +        represent a valid font, this returns null. If a typeface is returned,
   1.124 +        the caller is responsible for calling unref() when it is no longer used.
   1.125 +     */
   1.126 +    static SkTypeface* CreateTypefaceFromFile(const char path[]);
   1.127 +
   1.128 +    ///////////////////////////////////////////////////////////////////////////
   1.129 +
   1.130 +    friend class SkScalerContext;
   1.131 +    friend class SkTypeface;
   1.132 +};
   1.133 +
   1.134 +#endif

mercurial