gfx/src/nsFontMetrics.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/src/nsFontMetrics.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,228 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef NSFONTMETRICS__H__
    1.10 +#define NSFONTMETRICS__H__
    1.11 +
    1.12 +#include <stdint.h>                     // for uint32_t
    1.13 +#include <sys/types.h>                  // for int32_t
    1.14 +#include "gfxFont.h"                    // for gfxFont, gfxFontGroup
    1.15 +#include "mozilla/Assertions.h"         // for MOZ_ASSERT_HELPER2
    1.16 +#include "nsAutoPtr.h"                  // for nsRefPtr
    1.17 +#include "nsCOMPtr.h"                   // for nsCOMPtr
    1.18 +#include "nsCoord.h"                    // for nscoord
    1.19 +#include "nsError.h"                    // for nsresult
    1.20 +#include "nsFont.h"                     // for nsFont
    1.21 +#include "nsISupports.h"                // for NS_INLINE_DECL_REFCOUNTING
    1.22 +#include "nscore.h"                     // for char16_t
    1.23 +
    1.24 +class gfxUserFontSet;
    1.25 +class gfxTextPerfMetrics;
    1.26 +class nsDeviceContext;
    1.27 +class nsIAtom;
    1.28 +class nsRenderingContext;
    1.29 +struct nsBoundingMetrics;
    1.30 +
    1.31 +/**
    1.32 + * Font metrics
    1.33 + *
    1.34 + * This class may be somewhat misnamed. A better name might be
    1.35 + * nsFontList. The style system uses the nsFont struct for various
    1.36 + * font properties, one of which is font-family, which can contain a
    1.37 + * *list* of font names. The nsFont struct is "realized" by asking the
    1.38 + * device context to cough up an nsFontMetrics object, which contains
    1.39 + * a list of real font handles, one for each font mentioned in
    1.40 + * font-family (and for each fallback when we fall off the end of that
    1.41 + * list).
    1.42 + *
    1.43 + * The style system needs to have access to certain metrics, such as
    1.44 + * the em height (for the CSS "em" unit), and we use the first Western
    1.45 + * font's metrics for that purpose. The platform-specific
    1.46 + * implementations are expected to select non-Western fonts that "fit"
    1.47 + * reasonably well with the Western font that is loaded at Init time.
    1.48 + */
    1.49 +class nsFontMetrics MOZ_FINAL
    1.50 +{
    1.51 +public:
    1.52 +    nsFontMetrics();
    1.53 +
    1.54 +    NS_INLINE_DECL_REFCOUNTING(nsFontMetrics)
    1.55 +
    1.56 +    /**
    1.57 +     * Initialize the font metrics. Call this after creating the font metrics.
    1.58 +     * Font metrics you get from the font cache do NOT need to be initialized
    1.59 +     *
    1.60 +     * @see nsDeviceContext#GetMetricsFor()
    1.61 +     */
    1.62 +    nsresult Init(const nsFont& aFont, nsIAtom* aLanguage,
    1.63 +                  nsDeviceContext *aContext,
    1.64 +                  gfxUserFontSet *aUserFontSet,
    1.65 +                  gfxTextPerfMetrics *aTextPerf);
    1.66 +
    1.67 +    /**
    1.68 +     * Destroy this font metrics. This breaks the association between
    1.69 +     * the font metrics and the device context.
    1.70 +     */
    1.71 +    void Destroy();
    1.72 +
    1.73 +    /**
    1.74 +     * Return the font's x-height.
    1.75 +     */
    1.76 +    nscoord XHeight();
    1.77 +
    1.78 +    /**
    1.79 +     * Return the font's superscript offset (the distance from the
    1.80 +     * baseline to where a superscript's baseline should be placed).
    1.81 +     * The value returned will be positive.
    1.82 +     */
    1.83 +    nscoord SuperscriptOffset();
    1.84 +
    1.85 +    /**
    1.86 +     * Return the font's subscript offset (the distance from the
    1.87 +     * baseline to where a subscript's baseline should be placed).
    1.88 +     * The value returned will be positive.
    1.89 +     */
    1.90 +    nscoord SubscriptOffset();
    1.91 +
    1.92 +    /**
    1.93 +     * Return the font's strikeout offset (the distance from the
    1.94 +     * baseline to where a strikeout should be placed) and size.
    1.95 +     * Positive values are above the baseline, negative below.
    1.96 +     */
    1.97 +    void GetStrikeout(nscoord& aOffset, nscoord& aSize);
    1.98 +
    1.99 +    /**
   1.100 +     * Return the font's underline offset (the distance from the
   1.101 +     * baseline to where a underline should be placed) and size.
   1.102 +     * Positive values are above the baseline, negative below.
   1.103 +     */
   1.104 +    void GetUnderline(nscoord& aOffset, nscoord& aSize);
   1.105 +
   1.106 +    /**
   1.107 +     * Returns the amount of internal leading for the font.
   1.108 +     * This is normally the difference between the max ascent
   1.109 +     * and the em ascent.
   1.110 +     */
   1.111 +    nscoord InternalLeading();
   1.112 +
   1.113 +    /**
   1.114 +     * Returns the amount of external leading for the font.
   1.115 +     * em ascent(?) plus external leading is the font designer's
   1.116 +     * recommended line-height for this font.
   1.117 +     */
   1.118 +    nscoord ExternalLeading();
   1.119 +
   1.120 +    /**
   1.121 +     * Returns the height of the em square.
   1.122 +     * This is em ascent plus em descent.
   1.123 +     */
   1.124 +    nscoord EmHeight();
   1.125 +
   1.126 +    /**
   1.127 +     * Returns the ascent part of the em square.
   1.128 +     */
   1.129 +    nscoord EmAscent();
   1.130 +
   1.131 +    /**
   1.132 +     * Returns the descent part of the em square.
   1.133 +     */
   1.134 +    nscoord EmDescent();
   1.135 +
   1.136 +    /**
   1.137 +     * Returns the height of the bounding box.
   1.138 +     * This is max ascent plus max descent.
   1.139 +     */
   1.140 +    nscoord MaxHeight();
   1.141 +
   1.142 +    /**
   1.143 +     * Returns the maximum distance characters in this font extend
   1.144 +     * above the base line.
   1.145 +     */
   1.146 +    nscoord MaxAscent();
   1.147 +
   1.148 +    /**
   1.149 +     * Returns the maximum distance characters in this font extend
   1.150 +     * below the base line.
   1.151 +     */
   1.152 +    nscoord MaxDescent();
   1.153 +
   1.154 +    /**
   1.155 +     * Returns the maximum character advance for the font.
   1.156 +     */
   1.157 +    nscoord MaxAdvance();
   1.158 +
   1.159 +    /**
   1.160 +     * Returns the average character width
   1.161 +     */
   1.162 +    nscoord AveCharWidth();
   1.163 +
   1.164 +    /**
   1.165 +     * Returns the often needed width of the space character
   1.166 +     */
   1.167 +    nscoord SpaceWidth();
   1.168 +
   1.169 +    /**
   1.170 +     * Returns the font associated with these metrics. The return value
   1.171 +     * is only defined after Init() has been called.
   1.172 +     */
   1.173 +    const nsFont &Font() { return mFont; }
   1.174 +
   1.175 +    /**
   1.176 +     * Returns the language associated with these metrics
   1.177 +     */
   1.178 +    nsIAtom* Language() { return mLanguage; }
   1.179 +
   1.180 +    int32_t GetMaxStringLength();
   1.181 +
   1.182 +    // Get the width for this string.  aWidth will be updated with the
   1.183 +    // width in points, not twips.  Callers must convert it if they
   1.184 +    // want it in another format.
   1.185 +    nscoord GetWidth(const char* aString, uint32_t aLength,
   1.186 +                     nsRenderingContext *aContext);
   1.187 +    nscoord GetWidth(const char16_t* aString, uint32_t aLength,
   1.188 +                     nsRenderingContext *aContext);
   1.189 +
   1.190 +    // Draw a string using this font handle on the surface passed in.
   1.191 +    void DrawString(const char *aString, uint32_t aLength,
   1.192 +                    nscoord aX, nscoord aY,
   1.193 +                    nsRenderingContext *aContext);
   1.194 +    void DrawString(const char16_t* aString, uint32_t aLength,
   1.195 +                    nscoord aX, nscoord aY,
   1.196 +                    nsRenderingContext *aContext,
   1.197 +                    nsRenderingContext *aTextRunConstructionContext);
   1.198 +
   1.199 +    nsBoundingMetrics GetBoundingMetrics(const char16_t *aString,
   1.200 +                                         uint32_t aLength,
   1.201 +                                         nsRenderingContext *aContext);
   1.202 +
   1.203 +    // Returns the LOOSE_INK_EXTENTS bounds of the text for determing the
   1.204 +    // overflow area of the string.
   1.205 +    nsBoundingMetrics GetInkBoundsForVisualOverflow(const char16_t *aString,
   1.206 +                                                    uint32_t aLength,
   1.207 +                                                    nsRenderingContext *aContext);
   1.208 +
   1.209 +    void SetTextRunRTL(bool aIsRTL) { mTextRunRTL = aIsRTL; }
   1.210 +    bool GetTextRunRTL() { return mTextRunRTL; }
   1.211 +
   1.212 +    gfxFontGroup* GetThebesFontGroup() { return mFontGroup; }
   1.213 +    gfxUserFontSet* GetUserFontSet() { return mFontGroup->GetUserFontSet(); }
   1.214 +
   1.215 +    int32_t AppUnitsPerDevPixel() { return mP2A; }
   1.216 +
   1.217 +private:
   1.218 +    // Private destructor, to discourage deletion outside of Release():
   1.219 +    ~nsFontMetrics();
   1.220 +
   1.221 +    const gfxFont::Metrics& GetMetrics() const;
   1.222 +
   1.223 +    nsFont mFont;
   1.224 +    nsRefPtr<gfxFontGroup> mFontGroup;
   1.225 +    nsCOMPtr<nsIAtom> mLanguage;
   1.226 +    nsDeviceContext *mDeviceContext;
   1.227 +    int32_t mP2A;
   1.228 +    bool mTextRunRTL;
   1.229 +};
   1.230 +
   1.231 +#endif /* NSFONTMETRICS__H__ */

mercurial