Skip to content

Commit

Permalink
refactor: som class clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
4silvertooth committed Feb 15, 2021
1 parent 4f76d51 commit a04d299
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ sciter::value Doc::loadTTFontFromFile(sciter::astring path, HPDF_BOOL embed) {
return sciter::value::make_string(font_name);
}

sciter::value Doc::getFont(sciter::astring name, sciter::value encoding) {
sciter::value Doc::getFont(sciter::astring name, sciter::astring encoding) {
auto ret = new libharu::Font(pdf, name.c_str(), encoding);
return sciter::value::wrap_asset(ret);
}
Expand Down
16 changes: 6 additions & 10 deletions PDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace libharu {
class Image;
class Page : public sciter::om::asset<Page> {
HPDF_Doc pdf;
HPDF_Page page;

sciter::value TALIGN_LEFT = HPDF_TALIGN_LEFT;
Expand Down Expand Up @@ -38,7 +37,7 @@ class Page : public sciter::om::asset<Page> {

public:

Page(HPDF_Doc& _pdf) : pdf(_pdf) {
Page(HPDF_Doc& pdf) {
page = HPDF_AddPage (pdf);
}
virtual ~Page() {};
Expand Down Expand Up @@ -136,7 +135,7 @@ class Doc : public sciter::om::asset<Doc> {
int setPassword(sciter::astring, sciter::astring);
sciter::value loadJpegImageFromFile(sciter::astring);
sciter::value loadPngImageFromFile(sciter::astring);
sciter::value getFont(sciter::astring, sciter::value encoding);
sciter::value getFont(sciter::astring, sciter::astring);

SOM_PASSPORT_BEGIN(Doc)
SOM_PASSPORT_FLAGS(SOM_EXTENDABLE_OBJECT)
Expand All @@ -155,14 +154,13 @@ class Doc : public sciter::om::asset<Doc> {
};

class Image : public sciter::om::asset<Image> {
HPDF_Doc pdf;
HPDF_Image image;

public:
static const int JPEG = 1;
static const int PNG = 2;

Image(HPDF_Doc& _pdf, const char* filename, int type) : pdf(_pdf) {
Image(HPDF_Doc& pdf, const char* filename, int type) {
if(type == JPEG) {
image = HPDF_LoadJpegImageFromFile(pdf, filename);
} else if(type == PNG) {
Expand All @@ -189,14 +187,13 @@ class Image : public sciter::om::asset<Image> {
};

class Font : public sciter::om::asset<Image> {
HPDF_Doc pdf;
HPDF_Font font;

public:

Font(HPDF_Doc& _pdf, const char* name, sciter::value encoding) : pdf(_pdf) {
if(encoding.is_string()){
font = HPDF_GetFont(pdf, name, aux::w2a(encoding.to_string().c_str()));
Font(HPDF_Doc& pdf, const char* name, sciter::astring encoding) {
if(!encoding.empty()){
font = HPDF_GetFont(pdf, name, encoding.c_str());
}
else {
font = HPDF_GetFont(pdf, name, NULL);
Expand All @@ -209,7 +206,6 @@ class Font : public sciter::om::asset<Image> {

SOM_PASSPORT_BEGIN(Font)
SOM_PASSPORT_FLAGS(SOM_SEALED_OBJECT)
SOM_FUNCS()
SOM_PASSPORT_END
};

Expand Down

0 comments on commit a04d299

Please sign in to comment.