1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef mozilla_dom_TextMetrics_h
7 #define mozilla_dom_TextMetrics_h
8 
9 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
10 #include "mozilla/dom/NonRefcountedDOMObject.h"
11 
12 namespace mozilla {
13 namespace dom {
14 
15 class TextMetrics final : public NonRefcountedDOMObject {
16  public:
TextMetrics(double aWidth,double aActualBoundingBoxLeft,double aActualBoundingBoxRight,double aFontBoundingBoxAscent,double aFontBoundingBoxDescent,double aActualBoundingBoxAscent,double aActualBoundingBoxDescent,double aEmHeightAscent,double aEmHeightDescent,double aHangingBaseline,double aAlphabeticBaseline,double aIdeographicBaseline)17   explicit TextMetrics(double aWidth, double aActualBoundingBoxLeft,
18                        double aActualBoundingBoxRight,
19                        double aFontBoundingBoxAscent,
20                        double aFontBoundingBoxDescent,
21                        double aActualBoundingBoxAscent,
22                        double aActualBoundingBoxDescent, double aEmHeightAscent,
23                        double aEmHeightDescent, double aHangingBaseline,
24                        double aAlphabeticBaseline, double aIdeographicBaseline)
25       : width(aWidth),
26         actualBoundingBoxLeft(aActualBoundingBoxLeft),
27         actualBoundingBoxRight(aActualBoundingBoxRight),
28         fontBoundingBoxAscent(aFontBoundingBoxAscent),
29         fontBoundingBoxDescent(aFontBoundingBoxDescent),
30         actualBoundingBoxAscent(aActualBoundingBoxAscent),
31         actualBoundingBoxDescent(aActualBoundingBoxDescent),
32         emHeightAscent(aEmHeightAscent),
33         emHeightDescent(aEmHeightDescent),
34         hangingBaseline(aHangingBaseline),
35         alphabeticBaseline(aAlphabeticBaseline),
36         ideographicBaseline(aIdeographicBaseline) {
37     MOZ_COUNT_CTOR(TextMetrics);
38   }
39 
MOZ_COUNTED_DTOR(TextMetrics)40   MOZ_COUNTED_DTOR(TextMetrics)
41 
42   double Width() const { return width; }
43 
ActualBoundingBoxLeft()44   double ActualBoundingBoxLeft() const { return actualBoundingBoxLeft; }
45 
ActualBoundingBoxRight()46   double ActualBoundingBoxRight() const { return actualBoundingBoxRight; }
47 
48   // y-direction
49 
FontBoundingBoxAscent()50   double FontBoundingBoxAscent() const { return fontBoundingBoxAscent; }
51 
FontBoundingBoxDescent()52   double FontBoundingBoxDescent() const { return fontBoundingBoxDescent; }
53 
ActualBoundingBoxAscent()54   double ActualBoundingBoxAscent() const { return actualBoundingBoxAscent; }
55 
ActualBoundingBoxDescent()56   double ActualBoundingBoxDescent() const { return actualBoundingBoxDescent; }
57 
EmHeightAscent()58   double EmHeightAscent() const { return emHeightAscent; }
59 
EmHeightDescent()60   double EmHeightDescent() const { return emHeightDescent; }
61 
HangingBaseline()62   double HangingBaseline() const { return hangingBaseline; }
63 
AlphabeticBaseline()64   double AlphabeticBaseline() const { return alphabeticBaseline; }
65 
IdeographicBaseline()66   double IdeographicBaseline() const { return ideographicBaseline; }
67 
WrapObject(JSContext * aCx,JS::Handle<JSObject * > aGivenProto,JS::MutableHandle<JSObject * > aReflector)68   bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
69                   JS::MutableHandle<JSObject*> aReflector) {
70     return TextMetrics_Binding::Wrap(aCx, this, aGivenProto, aReflector);
71   }
72 
73  private:
74   double width;
75   double actualBoundingBoxLeft;
76   double actualBoundingBoxRight;
77   double fontBoundingBoxAscent;
78   double fontBoundingBoxDescent;
79   double actualBoundingBoxAscent;
80   double actualBoundingBoxDescent;
81   double emHeightAscent;
82   double emHeightDescent;
83   double hangingBaseline;
84   double alphabeticBaseline;
85   double ideographicBaseline;
86 };
87 
88 }  // namespace dom
89 }  // namespace mozilla
90 
91 #endif  // mozilla_dom_TextMetrics_h
92