Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur committed Jul 18, 2020
1 parent 52a844f commit ed370b7
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <algorithm>
#include "backend/ImageBackend.h"
#include <cairo-pdf.h>
#include <cairo/cairo-pdf.h>
#include "Canvas.h"
#include "CanvasGradient.h"
#include "CanvasPattern.h"
Expand Down Expand Up @@ -1828,23 +1828,24 @@ NAN_GETTER(Context2d::GetFillStyle) {
NAN_SETTER(Context2d::SetFillStyle) {
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());

if (value->IsString()) {
MaybeLocal<String> mstr = Nan::To<String>(value);
if (mstr.IsEmpty()) return;
Local<String> str = mstr.ToLocalChecked();
context->_fillStyle.Reset();
context->_setFillColor(str);
} else if (value->IsObject()) {
if (Nan::New(Gradient::constructor)->HasInstance(value) ||
Nan::New(Pattern::constructor)->HasInstance(value)) {
context->_fillStyle.Reset(value);

Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
if (Nan::New(Gradient::constructor)->HasInstance(obj)) {
context->_fillStyle.Reset(value);
if (Nan::New(Gradient::constructor)->HasInstance(obj)){
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
context->state->fillGradient = grad->pattern();
} else if (Nan::New(Pattern::constructor)->HasInstance(obj)) {
context->_fillStyle.Reset(value);
} else if(Nan::New(Pattern::constructor)->HasInstance(obj)){
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
context->state->fillPattern = pattern->pattern();
}
} else {
MaybeLocal<String> mstr = Nan::To<String>(value);
if (mstr.IsEmpty()) return;
Local<String> str = mstr.ToLocalChecked();
context->_fillStyle.Reset();
context->_setFillColor(str);
}
}

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

if (value->IsString()) {
MaybeLocal<String> mstr = Nan::To<String>(value);
if (mstr.IsEmpty()) return;
Local<String> str = mstr.ToLocalChecked();
context->_strokeStyle.Reset();
context->_setStrokeColor(str);
} else if (value->IsObject()) {
if (Nan::New(Gradient::constructor)->HasInstance(value) ||
Nan::New(Pattern::constructor)->HasInstance(value)) {
context->_strokeStyle.Reset(value);

Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
if (Nan::New(Gradient::constructor)->HasInstance(obj)) {
context->_strokeStyle.Reset(value);
if (Nan::New(Gradient::constructor)->HasInstance(obj)){
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
context->state->strokeGradient = grad->pattern();
} else if (Nan::New(Pattern::constructor)->HasInstance(obj)) {
context->_strokeStyle.Reset(value);
} else if(Nan::New(Pattern::constructor)->HasInstance(obj)){
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
context->state->strokePattern = pattern->pattern();
} else {
return Nan::ThrowTypeError("Gradient or Pattern expected");
}
} else {
MaybeLocal<String> mstr = Nan::To<String>(value);
if (mstr.IsEmpty()) return;
Local<String> str = mstr.ToLocalChecked();
context->_strokeStyle.Reset();
context->_setStrokeColor(str);
}
}

Expand Down Expand Up @@ -2399,16 +2403,11 @@ NAN_METHOD(Context2d::StrokeText) {
inline double getBaselineAdjustment(PangoLayout* layout, short baseline) {
PangoRectangle logical_rect;
PangoLayout* measureLayout = pango_layout_copy(layout);
PangoFontMetrics *metrics;
pango_layout_set_text(measureLayout, "gjĮ測試ÅÊ", -1);
pango_layout_line_get_extents(pango_layout_get_line(measureLayout, 0), NULL, &logical_rect);
metrics = PANGO_LAYOUT_GET_METRICS(measureLayout);
int strike_thickness = pango_font_metrics_get_strikethrough_thickness(metrics);
int strike_position = pango_font_metrics_get_strikethrough_position(metrics);
double scale = 1.0 / PANGO_SCALE;
double ascent = scale * pango_layout_get_baseline(measureLayout);
double descent = scale * logical_rect.height - ascent;
double middle = ascent - (scale * strike_position) + (scale * strike_thickness / 2);
// 0.072 is a constant that has been chosen comparing the canvas output
// if some code change, this constant can be changed too to keep results aligned
double correction_factor = scale * logical_rect.height * 0.072;
Expand All @@ -2419,7 +2418,7 @@ inline double getBaselineAdjustment(PangoLayout* layout, short baseline) {
case TEXT_BASELINE_IDEOGRAPHIC:
return ascent + correction_factor;
case TEXT_BASELINE_MIDDLE:
return middle;
return (ascent + descent) / 2.0;
case TEXT_BASELINE_BOTTOM:
return (ascent + descent) - correction_factor;
case TEXT_BASELINE_HANGING:
Expand Down

0 comments on commit ed370b7

Please sign in to comment.