Ace 图形第二批次提交

渐变、pattern,Linedash、混合

Signed-off-by: xucheng57 <xucheng57@huawei.com>
This commit is contained in:
xucheng57@huawei.com
2022-04-13 16:08:40 +08:00
committed by daihengdong
parent 13d8ac04ea
commit bf09d04cd8
10 changed files with 1673 additions and 55 deletions
@@ -215,6 +215,19 @@ int16_t IntegerOf(jerry_value_t source)
return static_cast<int16_t>(number);
}
float FloatOf(jerry_value_t source)
{
float value = 0;
if (jerry_value_is_number(source)) {
value = static_cast<float>(jerry_get_number_value(source));
} else {
char* cstr = MallocStringOf(source);
value = static_cast<float>(atof(cstr));
ACE_FREE(cstr);
}
return value;
}
jerry_value_t WatcherCallbackFunc(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t *args,
@@ -1312,5 +1325,38 @@ uint16_t ParseKeyIdFromJSString(const jerry_value_t str)
}
return keyId;
}
int8_t ParseLineCap(const char *lineCap)
{
if (lineCap == nullptr) {
return -1;
}
if (strcasecmp(lineCap, LINECAP_BUTT) == 0) {
return BUTT_VALUE;
}
if (strcasecmp(lineCap, LINECAP_SQUARE) == 0) {
return SQUARE_VALUE;
}
if (strcasecmp(lineCap, LINECAP_ROUND) == 0) {
return ROUND_VALUE;
}
return -1;
}
int8_t ParseLineJoin(const char *lineJoin)
{
if (lineJoin == nullptr) {
return -1;
}
if (strcasecmp(lineJoin, LINEJOIN_MITER) == 0) {
return LINEJOIN_MITER_VALUE;
}
if (strcasecmp(lineJoin, LINEJOIN_ROUND) == 0) {
return LINEJOIN_ROUND_VALUE;
}
if (strcasecmp(lineJoin, LINEJOIN_BEVEL) == 0) {
return LINEJOIN_BEVEL_VALUE;
}
return -1;
}
} // namespace ACELite
} // namespace OHOS
+9
View File
@@ -188,6 +188,7 @@ char *MallocStringOf(jerry_value_t source);
// convert one jerry string value to char*, and return the string length
char *MallocStringOf(jerry_value_t source, uint16_t *strLength);
int16_t IntegerOf(jerry_value_t source);
float FloatOf(jerry_value_t source);
bool BoolOf(jerry_value_t source);
// relocate file name to full path of the current app path
@@ -297,6 +298,12 @@ constexpr char PATH_DEFAULT[] = "/";
constexpr char PREFIX_HEX_COLOR[] = "#";
constexpr char PREFIX_RGB_COLOR[] = "rgb";
constexpr char PREFIX_RGBA_COLOR[] = "rgba";
constexpr char LINEJOIN_MITER[] = "miter";
constexpr char LINEJOIN_ROUND[] = "round";
constexpr char LINEJOIN_BEVEL[] = "bevel";
constexpr char LINECAP_BUTT[] = "butt";
constexpr char LINECAP_SQUARE[] = "square";
constexpr char LINECAP_ROUND[] = "round";
constexpr uint8_t ALPHA_MAX = 255;
constexpr char BRACE_OPEN = '(';
constexpr char BRACE_CLOSE = ')';
@@ -311,6 +318,8 @@ bool ParseHexColor(const char * const source, uint32_t &color, uint8_t &alpha);
bool ParseRgbaColor(const char * const source, uint32_t &color, uint8_t &alpha);
bool ParseColor(const char * const source, uint32_t &color, uint8_t &alpha);
bool CopyFontFamily(char *&destination, const char * const fontFamily, uint32_t fontFamilyNameLen = 0);
int8_t ParseLineCap(const char* lineCap);
int8_t ParseLineJoin(const char* lineJoin);
constexpr int16_t BUTT_VALUE = 0;
constexpr int16_t SQUARE_VALUE = 1;
+8
View File
@@ -72,6 +72,8 @@ enum {
#if (FEATURE_COMPONENT_CANVAS == 1)
KEYWORD(CANVAS, canvas) // tag name
#endif // FEATURE_COMPONENT_CANVAS
KEYWORD(CANVASGRADIENT, canvasGradient) // gradient fillstyle or strokestyle
KEYWORD(CANVASPATTERN, canvasPattern) // pattern fillstyle or strokestyle
KEYWORD(CENTER, center) // text align type
KEYWORD(CENTER_X, centerX) // circle progress x
KEYWORD(CENTER_Y, centerY) // circle progress y
@@ -180,6 +182,7 @@ enum {
#endif // FEATURE_COMPONENT_VIDEO
KEYWORD(NAME, name) // the attribute name
KEYWORD(NONE, none) // animation fill value
KEYWORD(NO_REPEAT, no-repeat) // no-repeat pattern type
#if (FEATURE_DATE_FORMAT == 1)
KEYWORD(NUMERIC, numeric)
#endif
@@ -212,6 +215,9 @@ enum {
KEYWORD(PAUSE, pause) // video component pause event tag
#endif // FEATURE_COMPONENT_VIDEO
KEYWORD(REVERSE, reverse) // image-animator attribute
KEYWORD(REPEAT, repeat) // repeat pattern type
KEYWORD(REPEAT_X, repeat-x) // repeat-x pattern type
KEYWORD(REPEAT_Y, repeat-y) // repeat-y pattern type
KEYWORD(RIGHT, right) // text align type
KEYWORD(ROTATE, rotate) // animation rotate
KEYWORD(ROW, row) // layout style
@@ -246,6 +252,8 @@ enum {
KEYWORD(SPACE_BETWEEN, space-between) // layout style
KEYWORD(SPACE_EVENLY, space-evenly) // layout style
KEYWORD(SRC, src) // common attributes, use for image view, video compnent
KEYWORD(IMAGE_WIDTH, width) // common attributes, use for image view, video compnent
KEYWORD(IMAGE_HEIGHT, height) // common attributes, use for image view, video compnent
KEYWORD(STACK, stack) // tag name
KEYWORD(STANDARD, standard) // text font size type
KEYWORD(STOP, stop) // image-animator stop event, video component end event tag
File diff suppressed because it is too large Load Diff
@@ -68,10 +68,10 @@ private:
const char *drawMethodName,
jerry_external_handler_t handler);
static jerry_value_t GetDom(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t GetContext(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t FillStyleSetter(const jerry_value_t func,
const jerry_value_t dom,
@@ -123,6 +123,46 @@ private:
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t LineCapSetter(const jerry_value_t func,
const jerry_value_t contex,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t LineCapGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t LineJoinSetter(const jerry_value_t func,
const jerry_value_t contex,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t LineJoinGetter(const jerry_value_t func,
const jerry_value_t contex,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t MiterLimitSetter(const jerry_value_t func,
const jerry_value_t contex,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t MiterLimitGetter(const jerry_value_t func,
const jerry_value_t contex,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t LineDashOffsetSetter(const jerry_value_t func,
const jerry_value_t contex,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t LineDashOffsetGetter(const jerry_value_t func,
const jerry_value_t contex,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t GlobalAlphaSetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
@@ -133,6 +173,53 @@ private:
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t GlobalCompositeOperationSetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowOffsetXSetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowOffsetXGetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowOffsetYSetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowOffsetYGetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowColorSetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowColorGetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowBlurSetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ShadowBlurGetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t GlobalCompositeOperationGetter(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t FillRect(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
@@ -193,6 +280,24 @@ private:
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t DrawImage(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t SetLineDash(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t GetLineDash(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t StrokeText(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t Rotate(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
@@ -203,6 +308,11 @@ private:
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t MeasureText(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t Translate(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
@@ -233,6 +343,11 @@ private:
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t CreatePattern(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t Save(const jerry_value_t func,
const jerry_value_t dom,
const jerry_value_t args[],
@@ -247,6 +362,11 @@ private:
const jerry_value_t dom,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t ParseImageName(const jerry_value_t args[],
char*& imageName,
int16_t &width,
int16_t &height);
static char* GetImageObjectParam(const jerry_value_t args[], int16_t &width, int16_t &height);
UICanvas canvas_;
jerry_value_t dom_;
jerry_value_t dashArray_;
@@ -258,14 +378,20 @@ private:
char *strokeStyleValue_;
char *fontValue_;
char *textAlignValue_;
int16_t shadowOffsetXValue_;
int16_t shadowOffsetYValue_;
int16_t shadowBlurValue_;
char *shadowColorValue_;
int16_t lineWidthValue_;
char *lineCapValue_;
char *lineJoinValue_;
double miterLimitValue_;
float miterLimitValue_;
float lineDashOffsetValue_;
char *colorStopValue_;
char *patternPathValue_;
char *patternRepeatTypeValue_;
static const char * const DEFAULT_FILLSTYLE;
static const char * const DEFAULT_STROKESTYLE;
@@ -290,7 +416,11 @@ private:
static const char * const ATTR_GLOBALALPHA;
static const char * const ATTR_GLOBALCOMPOSITEOPERATION;
static const char * const FUNC_GETdom;
static const char * const ATTR_SHADOWOFFSETX;
static const char * const ATTR_SHADOWOFFSETY;
static const char * const ATTR_SHADOWBLUR;
static const char * const ATTR_SHADOWCOLOR;
static const char * const FUNC_GETCONTEXT;
static const char * const FUNC_FILLRECT;
static const char * const FUNC_STROKERECT;
static const char * const FUNC_FILLTEXT;
@@ -298,15 +428,18 @@ private:
static const char * const FUNC_MOVETO;
static const char * const FUNC_LINETO;
static const char * const FUNC_RECT;
static const char * const FUNC_CLEANRECT;
static const char * const FUNC_ARC;
static const char * const FUNC_CLOSEPATH;
static const char * const FUNC_STROKE;
static const char * const FUNC_FILL;
static const char * const FUNC_DRAWIMAGE;
static const char * const FUNC_SETLINEDASH;
static const char * const FUNC_GETLINEDASH;
static const char * const FUNC_STROKETEXT;
static const char * const FUNC_ROTATE;
static const char * const FUNC_SCALE;
static const char * const FUNC_MEASURETEXT;
static const char * const FUNC_TRANSLATE;
static const char * const FUNC_TRANFORM;
static const char * const FUNC_SETTRANFORM;
@@ -316,6 +449,7 @@ private:
static const char * const FUNC_CREATELINEARGRADIENT;
static const char * const FUNC_CREATERADIALGRADIENT;
static const char * const FUNC_ADDCOLORSTOP;
static const char * const FUNC_CREATEPATTERN;
};
} // namespace ACELite
} // namespace OHOS
@@ -32,6 +32,11 @@ ImageComponent::ImageComponent(jerry_value_t options, jerry_value_t children, Ap
SetComponentName(K_IMAGE);
}
const char *ImageComponent::GetSrc()
{
return imageView_.GetPath();
}
bool ImageComponent::CreateNativeViews()
{
// set default value
@@ -57,6 +62,16 @@ bool ImageComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrV
ACE_FREE(src);
break;
}
case K_WIDTH: {
int16_t width = IntegerOf(attrValue);
imageView_.SetWidth(width);
break;
}
case K_HEIGHT: {
int16_t height = IntegerOf(attrValue);
imageView_.SetWidth(height);
break;
}
default:
setResult = false;
break;
@@ -95,11 +110,15 @@ bool ImageComponent::ApplyPrivateStyle(const AppStyleItem *style)
break;
}
case K_HEIGHT: {
int16_t value = GetStyleNumValue(style);
imageView_.SetHeight(value);
hasSetHeight_ = true;
setResult = false;
break;
}
case K_WIDTH: {
int16_t value = GetStyleNumValue(style);
imageView_.SetWidth(value);
hasSetWidth_ = true;
setResult = false;
break;
@@ -12,3 +12,323 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstring>
#include "ace_log.h"
#include "locale_util.h"
#include "key_parser.h"
#include "keys.h"
#include "image.h"
#include "image_module.h"
namespace OHOS {
namespace ACELite {
constexpr jerry_object_native_info_t ImageModule::gcCallback;
const char * const ImageModule::attrOnload = "onload";
const char * const ImageModule::attrOnError = "onerror";
const char * const ImageModule::attrSrc = "src";
const char * const ImageModule::attrWidth = "width";
const char * const ImageModule::attrHeight = "height";
const char * const ImageModule::className = "Image";
void ImageModule::Init(jerry_value_t intlHandle)
{
(void)intlHandle;
jerry_value_t gObj = jerry_get_global_object();
JerrySetFuncProperty(gObj, className, CreateImage);
}
void ImageModule::RegisterAttributeFunc(jerry_value_t canvas2dContext,
const char *attributeName,
jerry_external_handler_t setterHandler,
jerry_external_handler_t getterHandler)
{
// register canvas js attribute setter property via the jerry_define_own_property method
jerry_value_t propName = jerry_create_string(reinterpret_cast<const jerry_char_t *>(attributeName));
jerry_property_descriptor_t desc;
jerry_init_property_descriptor_fields(&desc);
desc.is_set_defined = true;
desc.setter = jerry_create_external_function(setterHandler);
desc.is_get_defined = true;
desc.getter = jerry_create_external_function(getterHandler);
jerry_value_t returnValue = jerry_define_own_property(canvas2dContext, propName, &desc);
jerry_free_property_descriptor_fields(&desc);
ReleaseJerryValue(propName, returnValue, VA_ARG_END_FLAG);
}
jerry_value_t ImageModule::CreateImage(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
if (!jerry_value_is_constructor(func)) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("use new to create Image"));
}
ImageModule *imageModule = new ImageModule();
if (imageModule == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("memory is not enough"));
}
imageModule->width_ = -1;
imageModule->height_ = -1;
if (argsNum >= 1) {
if (jerry_value_is_number(args[0])) {
imageModule->width_ = jerry_value_to_number(args[0]);
} else if (jerry_value_is_string(args[0])) {
char* val = MallocStringOf(args[0]);
imageModule->width_ = atoi(val);
ACE_FREE(val);
}
}
if (argsNum >= static_cast<uint32_t>(ArgsCount::NUM_2)) {
if (jerry_value_is_number(args[1])) {
imageModule->height_ = jerry_value_to_number(args[1]);
} else if (jerry_value_is_string(args[1])) {
char* val = MallocStringOf(args[1]);
imageModule->height_ = atoi(val);
ACE_FREE(val);
}
}
jerry_set_object_native_pointer(context, imageModule, &gcCallback);
RegisterAttributeFunc(context, attrWidth, OnLoadSetter, OnLoadGetter);
RegisterAttributeFunc(context, attrOnError, OnErrorSetter, OnErrorGetter);
RegisterAttributeFunc(context, attrSrc, OnSrcSetter, OnSrcGetter);
RegisterAttributeFunc(context, attrWidth, OnWidthSetter, OnWidthGetter);
RegisterAttributeFunc(context, attrHeight, OnHeightSetter, OnHeightGetter);
return UNDEFINED;
}
jerry_value_t ImageModule::OnLoadSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
if (argsNum == 1 && jerry_value_is_function(args[0])) {
jerry_release_value(imageModel->onLoadFunc_);
imageModel->onLoadFunc_ = args[0];
} else {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("set imageModel onload arg fail"));
}
return UNDEFINED;
}
jerry_value_t ImageModule::OnLoadGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
(void)args;
(void)argsNum;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
return imageModel->onLoadFunc_;
}
jerry_value_t ImageModule::OnErrorSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
if (argsNum >= 1 && jerry_value_is_function(args[0])) {
jerry_release_value(imageModel->onErrorFunc_);
imageModel->onErrorFunc_ = args[0];
} else {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("set imageModel onload arg fail"));
}
return UNDEFINED;
}
jerry_value_t ImageModule::OnErrorGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
(void)args;
(void)argsNum;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
return imageModel->onErrorFunc_;
}
jerry_value_t ImageModule::OnSrcSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
if (argsNum >= 1) {
ACE_FREE(imageModel->src_);
imageModel->src_ = MallocStringOf(args[0]);
}
if (imageModel->src_ == nullptr || strlen(imageModel->src_) == 0) {
OnCallBack(context, imageModel, false, "src is null");
return UNDEFINED;
}
jerry_release_value(imageModel->jerrySrc_);
imageModel->jerrySrc_ = jerry_create_string(reinterpret_cast<const jerry_char_t *>(imageModel->src_));
Image image;
bool isLoad = image.PreParse(imageModel->src_);
if (!isLoad) {
OnCallBack(context, imageModel, false, "unknown image");
return UNDEFINED;
}
OnCallBack(context, imageModel, true, "load sucess");
return UNDEFINED;
}
jerry_value_t ImageModule::OnSrcGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
(void)args;
(void)argsNum;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
if (jerry_value_is_string(imageModel->jerrySrc_)) {
return imageModel->jerrySrc_;
}
return UNDEFINED;
}
jerry_value_t ImageModule::OnHeightSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
if (argsNum < 1) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("set height fail"));
}
imageModel->height_ = IntegerOf(args[0]);
return UNDEFINED;
}
jerry_value_t ImageModule::OnHeightGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
(void)args;
(void)argsNum;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
return imageModel->height_;
}
jerry_value_t ImageModule::OnWidthSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
if (argsNum < 1) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("set width fail"));
}
imageModel->width_ = IntegerOf(args[0]);
return UNDEFINED;
}
jerry_value_t ImageModule::OnWidthGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum)
{
(void)func;
(void)args;
(void)argsNum;
ImageModule* imageModel = nullptr;
jerry_get_object_native_pointer(context, (void**)&imageModel, &gcCallback);
if (imageModel == nullptr) {
return jerry_create_error(JERRY_ERROR_EVAL,
reinterpret_cast<const jerry_char_t *>("get imageModel fail"));
}
return imageModel->width_;
}
void ImageModule::OnCallBack(const jerry_value_t context,
const ImageModule *imageModule,
bool isSucess,
const char* msg)
{
jerry_value_t targetFunction;
if (imageModule == nullptr) {
return;
}
if (isSucess) {
targetFunction = imageModule->onLoadFunc_;
} else {
targetFunction = imageModule->onErrorFunc_;
}
if (!jerry_value_is_function(targetFunction)) {
return;
}
const int16_t argcount = 1;
jerry_value_t arg = jerry_create_string(reinterpret_cast<const jerry_char_t *>(msg));
jerry_value_t args[argcount] = {arg};
jerry_value_t ret_val = jerry_call_function (targetFunction, context, args, argcount);
if (jerry_value_is_error (ret_val)) {
HILOG_ERROR(HILOG_MODULE_ACE, "call back failed!");
}
jerry_release_value(arg);
jerry_release_value (ret_val);
}
}
}
@@ -16,4 +16,131 @@
#ifndef OHOS_ACELITE_IMAGE_MODEL_H
#define OHOS_ACELITE_IMAGE_MODEL_H
#include "acelite_config.h"
#include "image_component.h"
#include "gfx_utils/list.h"
#include "js_fwk_common.h"
namespace OHOS {
namespace ACELite {
class ImageModule final : public MemoryHeap {
enum class ArgsCount { NUM_1 = 1, NUM_2, NUM_3, NUM_4, NUM_5, NUM_6 };
public:
const char* GetSrc()
{
return src_;
}
int16_t GetWidth()
{
return width_;
}
int16_t GetHeight()
{
return height_;
}
ACE_DISALLOW_COPY(ImageModule);
/**
* @brief register Image object
*/
static void Init(jerry_value_t intlHandle);
static void RegisterAttributeFunc(jerry_value_t canvas2dContext,
const char *attributeName,
jerry_external_handler_t setterHandler,
jerry_external_handler_t getterHandler);
#if ENABLED_DELETE_MODULE_IAMGE
static void DeleteImage(void* ptr)
{
ImageModule* image = reinterpret_cast<ImageModule*>(ptr);
ACE_DELETE(image);
}
#endif
static void OnCallBack(const jerry_value_t context, const ImageModule *imageModule, bool isSucess, const char* msg);
// the handle to release the native value when the js value number format object is not needed.
static constexpr jerry_object_native_info_t gcCallback = {
#if ENABLED_DELETE_MODULE_IAMGE
.free_cb = DeleteImage
#endif
};
static const char * const attrOnload;
static const char * const attrOnError;
static const char * const attrSrc;
static const char * const attrWidth;
static const char * const attrHeight;
static const char * const className;
private:
ImageModule()
: src_(nullptr),
width_(-1),
height_(-1),
onLoadFunc_(UNDEFINED),
onErrorFunc_(UNDEFINED),
jerrySrc_(UNDEFINED) {}
~ImageModule()
{
jerry_release_value(onLoadFunc_);
jerry_release_value(onErrorFunc_);
jerry_release_value(jerrySrc_);
ACE_FREE(src_);
}
static jerry_value_t CreateImage(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnLoadSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnLoadGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnErrorSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnErrorGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnSrcSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnSrcGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnHeightSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnHeightGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnWidthSetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
static jerry_value_t OnWidthGetter(const jerry_value_t func,
const jerry_value_t context,
const jerry_value_t args[],
const jerry_length_t argsNum);
private:
char* src_;
int16_t width_;
int16_t height_;
jerry_value_t onLoadFunc_;
jerry_value_t onErrorFunc_;
jerry_value_t jerrySrc_;
};
}
}
#endif // NUMBER_FORMAT_MODEL_H
@@ -20,6 +20,7 @@
#include "global.h"
#include "string.h"
#include "number_format_module.h"
#include "image_module.h"
#include "js_fwk_common.h"
namespace OHOS {
namespace ACELite {
@@ -33,6 +34,7 @@ void IntlModule::Init()
#if (FEATURE_DATE_FORMAT == 1)
DateTimeFormatModule::Init(baseObj);
#endif
ImageModule::Init(baseObj);
JerrySetNamedProperty(globalObj, "Intl", baseObj);
jerry_release_value(globalObj);
}
@@ -45,7 +45,6 @@ private:
}
}
#endif // FEATURE_INTL_MODULE
#include "image_module.h"
namespace OHOS {
namespace ACELite {
class IntlControlModule final {