4
4
5
5
#include < algorithm>
6
6
#include " backend/ImageBackend.h"
7
- #include < cairo-pdf.h>
7
+ #include < cairo/cairo -pdf.h>
8
8
#include " Canvas.h"
9
9
#include " CanvasGradient.h"
10
10
#include " CanvasPattern.h"
@@ -1828,23 +1828,24 @@ NAN_GETTER(Context2d::GetFillStyle) {
1828
1828
NAN_SETTER (Context2d::SetFillStyle) {
1829
1829
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This ());
1830
1830
1831
- if (value->IsString ()) {
1832
- MaybeLocal<String> mstr = Nan::To<String>(value);
1833
- if (mstr.IsEmpty ()) return ;
1834
- Local<String> str = mstr.ToLocalChecked ();
1835
- context->_fillStyle .Reset ();
1836
- context->_setFillColor (str);
1837
- } else if (value->IsObject ()) {
1831
+ if (Nan::New (Gradient::constructor)->HasInstance (value) ||
1832
+ Nan::New (Pattern::constructor)->HasInstance (value)) {
1833
+ context->_fillStyle .Reset (value);
1834
+
1838
1835
Local<Object> obj = Nan::To<Object>(value).ToLocalChecked ();
1839
- if (Nan::New (Gradient::constructor)->HasInstance (obj)) {
1840
- context->_fillStyle .Reset (value);
1836
+ if (Nan::New (Gradient::constructor)->HasInstance (obj)){
1841
1837
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
1842
1838
context->state ->fillGradient = grad->pattern ();
1843
- } else if (Nan::New (Pattern::constructor)->HasInstance (obj)) {
1844
- context->_fillStyle .Reset (value);
1839
+ } else if (Nan::New (Pattern::constructor)->HasInstance (obj)){
1845
1840
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
1846
1841
context->state ->fillPattern = pattern->pattern ();
1847
1842
}
1843
+ } else {
1844
+ MaybeLocal<String> mstr = Nan::To<String>(value);
1845
+ if (mstr.IsEmpty ()) return ;
1846
+ Local<String> str = mstr.ToLocalChecked ();
1847
+ context->_fillStyle .Reset ();
1848
+ context->_setFillColor (str);
1848
1849
}
1849
1850
}
1850
1851
@@ -1871,23 +1872,26 @@ NAN_GETTER(Context2d::GetStrokeStyle) {
1871
1872
NAN_SETTER (Context2d::SetStrokeStyle) {
1872
1873
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This ());
1873
1874
1874
- if (value->IsString ()) {
1875
- MaybeLocal<String> mstr = Nan::To<String>(value);
1876
- if (mstr.IsEmpty ()) return ;
1877
- Local<String> str = mstr.ToLocalChecked ();
1878
- context->_strokeStyle .Reset ();
1879
- context->_setStrokeColor (str);
1880
- } else if (value->IsObject ()) {
1875
+ if (Nan::New (Gradient::constructor)->HasInstance (value) ||
1876
+ Nan::New (Pattern::constructor)->HasInstance (value)) {
1877
+ context->_strokeStyle .Reset (value);
1878
+
1881
1879
Local<Object> obj = Nan::To<Object>(value).ToLocalChecked ();
1882
- if (Nan::New (Gradient::constructor)->HasInstance (obj)) {
1883
- context->_strokeStyle .Reset (value);
1880
+ if (Nan::New (Gradient::constructor)->HasInstance (obj)){
1884
1881
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
1885
1882
context->state ->strokeGradient = grad->pattern ();
1886
- } else if (Nan::New (Pattern::constructor)->HasInstance (obj)) {
1887
- context->_strokeStyle .Reset (value);
1883
+ } else if (Nan::New (Pattern::constructor)->HasInstance (obj)){
1888
1884
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
1889
1885
context->state ->strokePattern = pattern->pattern ();
1886
+ } else {
1887
+ return Nan::ThrowTypeError (" Gradient or Pattern expected" );
1890
1888
}
1889
+ } else {
1890
+ MaybeLocal<String> mstr = Nan::To<String>(value);
1891
+ if (mstr.IsEmpty ()) return ;
1892
+ Local<String> str = mstr.ToLocalChecked ();
1893
+ context->_strokeStyle .Reset ();
1894
+ context->_setStrokeColor (str);
1891
1895
}
1892
1896
}
1893
1897
@@ -2399,16 +2403,11 @@ NAN_METHOD(Context2d::StrokeText) {
2399
2403
inline double getBaselineAdjustment (PangoLayout* layout, short baseline) {
2400
2404
PangoRectangle logical_rect;
2401
2405
PangoLayout* measureLayout = pango_layout_copy (layout);
2402
- PangoFontMetrics *metrics;
2403
2406
pango_layout_set_text (measureLayout, " gjĮ測試ÅÊ" , -1 );
2404
2407
pango_layout_line_get_extents (pango_layout_get_line (measureLayout, 0 ), NULL , &logical_rect);
2405
- metrics = PANGO_LAYOUT_GET_METRICS (measureLayout);
2406
- int strike_thickness = pango_font_metrics_get_strikethrough_thickness (metrics);
2407
- int strike_position = pango_font_metrics_get_strikethrough_position (metrics);
2408
2408
double scale = 1.0 / PANGO_SCALE;
2409
2409
double ascent = scale * pango_layout_get_baseline (measureLayout);
2410
2410
double descent = scale * logical_rect.height - ascent;
2411
- double middle = ascent - (scale * strike_position) + (scale * strike_thickness / 2 );
2412
2411
// 0.072 is a constant that has been chosen comparing the canvas output
2413
2412
// if some code change, this constant can be changed too to keep results aligned
2414
2413
double correction_factor = scale * logical_rect.height * 0.072 ;
@@ -2419,7 +2418,7 @@ inline double getBaselineAdjustment(PangoLayout* layout, short baseline) {
2419
2418
case TEXT_BASELINE_IDEOGRAPHIC:
2420
2419
return ascent + correction_factor;
2421
2420
case TEXT_BASELINE_MIDDLE:
2422
- return middle ;
2421
+ return (ascent + descent) / 2.0 ;
2423
2422
case TEXT_BASELINE_BOTTOM:
2424
2423
return (ascent + descent) - correction_factor;
2425
2424
case TEXT_BASELINE_HANGING:
0 commit comments