Skip to content

Commit ed370b7

Browse files
committed
revert
1 parent 52a844f commit ed370b7

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

src/CanvasRenderingContext2d.cc

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <algorithm>
66
#include "backend/ImageBackend.h"
7-
#include <cairo-pdf.h>
7+
#include <cairo/cairo-pdf.h>
88
#include "Canvas.h"
99
#include "CanvasGradient.h"
1010
#include "CanvasPattern.h"
@@ -1828,23 +1828,24 @@ NAN_GETTER(Context2d::GetFillStyle) {
18281828
NAN_SETTER(Context2d::SetFillStyle) {
18291829
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
18301830

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+
18381835
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)){
18411837
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
18421838
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)){
18451840
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
18461841
context->state->fillPattern = pattern->pattern();
18471842
}
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);
18481849
}
18491850
}
18501851

@@ -1871,23 +1872,26 @@ NAN_GETTER(Context2d::GetStrokeStyle) {
18711872
NAN_SETTER(Context2d::SetStrokeStyle) {
18721873
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
18731874

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+
18811879
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)){
18841881
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
18851882
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)){
18881884
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
18891885
context->state->strokePattern = pattern->pattern();
1886+
} else {
1887+
return Nan::ThrowTypeError("Gradient or Pattern expected");
18901888
}
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);
18911895
}
18921896
}
18931897

@@ -2399,16 +2403,11 @@ NAN_METHOD(Context2d::StrokeText) {
23992403
inline double getBaselineAdjustment(PangoLayout* layout, short baseline) {
24002404
PangoRectangle logical_rect;
24012405
PangoLayout* measureLayout = pango_layout_copy(layout);
2402-
PangoFontMetrics *metrics;
24032406
pango_layout_set_text(measureLayout, "gjĮ測試ÅÊ", -1);
24042407
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);
24082408
double scale = 1.0 / PANGO_SCALE;
24092409
double ascent = scale * pango_layout_get_baseline(measureLayout);
24102410
double descent = scale * logical_rect.height - ascent;
2411-
double middle = ascent - (scale * strike_position) + (scale * strike_thickness / 2);
24122411
// 0.072 is a constant that has been chosen comparing the canvas output
24132412
// if some code change, this constant can be changed too to keep results aligned
24142413
double correction_factor = scale * logical_rect.height * 0.072;
@@ -2419,7 +2418,7 @@ inline double getBaselineAdjustment(PangoLayout* layout, short baseline) {
24192418
case TEXT_BASELINE_IDEOGRAPHIC:
24202419
return ascent + correction_factor;
24212420
case TEXT_BASELINE_MIDDLE:
2422-
return middle;
2421+
return (ascent + descent) / 2.0;
24232422
case TEXT_BASELINE_BOTTOM:
24242423
return (ascent + descent) - correction_factor;
24252424
case TEXT_BASELINE_HANGING:

0 commit comments

Comments
 (0)