diff --git a/Common/3dParty/harfbuzz/test/main.cpp b/Common/3dParty/harfbuzz/test/main.cpp new file mode 100644 index 0000000000..4d01396986 --- /dev/null +++ b/Common/3dParty/harfbuzz/test/main.cpp @@ -0,0 +1,818 @@ +// https://android.googlesource.com/platform/external/harfbuzz/+/ics-mr0/contrib/tables/script-properties.h + +/* + * https://unicode.org/reports/tr29/ + +As far as a user is concerned, the underlying representation of text is not important, +but it is important that an editing interface present a uniform implementation of what +the user thinks of as characters. Grapheme clusters can be treated as units, by default, +for processes such as the formatting of drop caps, as well as the implementation of text +selection, arrow key movement or backspacing through text, and so forth. For example, +when a grapheme cluster is represented internally by a character sequence consisting of +base character + accents, then using the right arrow key would skip from the start of the +base character to the end of the last accent. + +This document defines a default specification for grapheme clusters. It may be customized + for particular languages, operations, or other situations. For example, arrow key movement +could be tailored by language, or could use knowledge specific to particular fonts to move +in a more granular manner, in circumstances where it would be useful to edit individual +components. This could apply, for example, to the complex editorial requirements for the +Northern Thai script Tai Tham (Lanna). Similarly, editing a grapheme cluster element by +element may be preferable in some circumstances. For example, on a given system the backspace +key might delete by code point, while the delete key may delete an entire cluster. + * */ + +#include "../../../core/DesktopEditor/common/File.h" +#include "../../../core/DesktopEditor/raster/BgraFrame.h" + +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H +#include FT_OUTLINE_H + +#include +#include +#include + +class CDrawer +{ +public: + CBgraFrame m_oFrame; + BYTE *pixels; + int width; + int height; + int pitch; + BYTE Rshift; + BYTE Gshift; + BYTE Bshift; + BYTE Ashift; + +public: + CDrawer(int w, int h) + { + width = w; + height = h; + pitch = 4 * width; + m_oFrame.put_Width(width); + m_oFrame.put_Height(height); + m_oFrame.put_Stride(pitch); + + int size = 4 * width * height; + BYTE *pPixels = new BYTE[size]; + for (int i = 0; i < size; i += 4) + { + pPixels[i] = 0xFF; + pPixels[i + 1] = 0xFF; + pPixels[i + 2] = 0xFF; + pPixels[i + 3] = 0xFF; + } + pixels = pPixels; + m_oFrame.put_Data(pPixels); + + Bshift = 24; + Gshift = 16; + Rshift = 8; + Ashift = 0; + } + void Save() + { + m_oFrame.SaveFile(NSFile::GetProcessDirectory() + L"/output.png", 4); + } +}; + +#define NUM_EXAMPLES 3 + +/* fonts */ +const char *fonts_paths[NUM_EXAMPLES] = { + "C:/Windows/Fonts/calibri.ttf", + //"C:/Windows/Fonts/arial.ttf", + "C:/Users/korol/AppData/Local/Microsoft/Windows/Fonts/ArabicTest.ttf", + "C:/Windows/Fonts/simsun.ttc" +}; + +#define NUM_GLYPH_TYPES 5 +const char *num_glyph_types[NUM_GLYPH_TYPES] = {"UNCLASSIFIED", "BASE_GLYPH", "LIGATURE", "MARK", "COMPONENT"}; + +/* tranlations courtesy of google */ +const char *texts[NUM_EXAMPLES] = { + "fi", + "لا لآ لأ لا", + "懶惰的姜貓" +}; + +const hb_direction_t text_directions[NUM_EXAMPLES] = { + HB_DIRECTION_LTR, + HB_DIRECTION_RTL, + HB_DIRECTION_TTB, +}; + +const int text_skip[NUM_EXAMPLES] = { + 0, + 0, + 1, +}; + +/* XXX: These are not correct, though it doesn't seem to break anything + * regardless of their value. */ +const char *languages[NUM_EXAMPLES] = { + "en", + "ar", + "ch", +}; + +const hb_script_t scripts[NUM_EXAMPLES] = { + HB_SCRIPT_LATIN, + HB_SCRIPT_ARABIC, + HB_SCRIPT_HAN, +}; + +enum +{ + ENGLISH = 0, + ARABIC, + CHINESE +}; + +typedef struct _spanner_baton_t +{ + /* rendering part - assumes 32bpp surface */ + uint32_t *pixels; // set to the glyph's origin. + uint32_t *first_pixel, *last_pixel; // bounds check + uint32_t pitch; + uint32_t rshift; + uint32_t gshift; + uint32_t bshift; + uint32_t ashift; + + /* sizing part */ + int min_span_x; + int max_span_x; + int min_y; + int max_y; +} spanner_baton_t; + +/* This spanner is write only, suitable for write-only mapped buffers, + but can cause dark streaks where glyphs overlap, like in arabic scripts. + + Note how spanners don't clip against surface width - resize the window + and see what it leads to. */ +void spanner_wo(int y, int count, const FT_Span *spans, void *user) +{ + spanner_baton_t *baton = (spanner_baton_t *)user; + uint32_t *scanline = baton->pixels - y * ((int)baton->pitch / 4); + if (scanline < baton->first_pixel) + return; + for (int i = 0; i < count; i++) + { + uint32_t color = ((spans[i].coverage / 2) << baton->rshift) | ((spans[i].coverage / 2) << baton->gshift) | ((spans[i].coverage / 2) << baton->bshift); + + uint32_t *start = scanline + spans[i].x; + if (start + spans[i].len > baton->last_pixel) + return; + + for (int x = 0; x < spans[i].len; x++) + *start++ = color; + } +} + +/* This spanner does read/modify/write, trading performance for accuracy. + The color here is simply half coverage value in all channels, + effectively mid-gray. + Suitable for when artifacts mostly do come up and annoy. + This might be optimized if one does rmw only for some values of x. + But since the whole buffer has to be rw anyway, and the previous value + is probably still in the cache, there's little point to. */ +void spanner_rw(int y, int count, const FT_Span *spans, void *user) +{ + spanner_baton_t *baton = (spanner_baton_t *)user; + uint32_t *scanline = baton->pixels - y * ((int)baton->pitch / 4); + if (scanline < baton->first_pixel) + return; + + for (int i = 0; i < count; i++) + { + uint32_t color = ((spans[i].coverage / 2) << baton->rshift) | ((spans[i].coverage / 2) << baton->gshift) | ((spans[i].coverage / 2) << baton->bshift); + uint32_t *start = scanline + spans[i].x; + if (start + spans[i].len > baton->last_pixel) + return; + + for (int x = 0; x < spans[i].len; x++) + *start++ |= color; + } +} + +/* This spanner is for obtaining exact bounding box for the string. + Unfortunately this can't be done without rendering it (or pretending to). + After this runs, we get min and max values of coordinates used. +*/ +void spanner_sizer(int y, int count, const FT_Span *spans, void *user) +{ + spanner_baton_t *baton = (spanner_baton_t *)user; + + if (y < baton->min_y) + baton->min_y = y; + if (y > baton->max_y) + baton->max_y = y; + for (int i = 0; i < count; i++) + { + if (spans[i].x + spans[i].len > baton->max_span_x) + baton->max_span_x = spans[i].x + spans[i].len; + if (spans[i].x < baton->min_span_x) + baton->min_span_x = spans[i].x; + } +} + +FT_SpanFunc spanner = spanner_wo; + +void ftfdump(FT_Face ftf) +{ + for (int i = 0; i < ftf->num_charmaps; i++) + { + printf( + "%d: %s %s %c%c%c%c plat=%hu id=%hu\n", i, ftf->family_name, ftf->style_name, ftf->charmaps[i]->encoding >> 24, (ftf->charmaps[i]->encoding >> 16) & 0xff, + (ftf->charmaps[i]->encoding >> 8) & 0xff, (ftf->charmaps[i]->encoding) & 0xff, ftf->charmaps[i]->platform_id, ftf->charmaps[i]->encoding_id); + } +} + +/* See http://www.microsoft.com/typography/otspec/name.htm + for a list of some possible platform-encoding pairs. + We're interested in 0-3 aka 3-1 - UCS-2. + Otherwise, fail. If a font has some unicode map, but lacks + UCS-2 - it is a broken or irrelevant font. What exactly + Freetype will select on face load (it promises most wide + unicode, and if that will be slower that UCS-2 - left as + an excercise to check. */ +int force_ucs2_charmap(FT_Face ftf) +{ + for (int i = 0; i < ftf->num_charmaps; i++) + if (((ftf->charmaps[i]->platform_id == 0) && (ftf->charmaps[i]->encoding_id == 3)) || ((ftf->charmaps[i]->platform_id == 3) && (ftf->charmaps[i]->encoding_id == 1))) + return FT_Set_Charmap(ftf, ftf->charmaps[i]); + return -1; +} + +void hline(CDrawer *s, int min_x, int max_x, int y, uint32_t color) +{ + if (y < 0) + y = 0; + uint32_t *pix = (uint32_t *)s->pixels + (y * s->pitch) / 4 + min_x; + uint32_t *end = (uint32_t *)s->pixels + (y * s->pitch) / 4 + max_x; + + while (pix - 1 != end) + *pix++ = color; +} + +void vline(CDrawer *s, int min_y, int max_y, int x, uint32_t color) +{ + if (min_y < 0) + min_y = 0; + + uint32_t *pix = (uint32_t *)s->pixels + (min_y * s->pitch) / 4 + x; + uint32_t *end = (uint32_t *)s->pixels + (max_y * s->pitch) / 4 + x; + + while (pix - s->pitch / 4 != end) + { + *pix = color; + pix += s->pitch / 4; + } +} + +void assert(const bool &valid) +{ + // TODO: +} + +#define MAIN_CC_NO_PRIVATE_API +#ifndef MAIN_CC_NO_PRIVATE_API +/* Only this part of this mini app uses private API */ +#include "hb-open-file.hh" +#include "hb-ot-layout-gdef-table.hh" +#include "hb-ot-layout-gsubgpos.hh" +#include "hb-static.cc" + +using namespace OT; + +static void print_layout_info_using_private_api(hb_blob_t *blob) +{ + const char *font_data = hb_blob_get_data(blob, nullptr); + hb_blob_t *font_blob = hb_sanitize_context_t().sanitize_blob(blob); + const OpenTypeFontFile *sanitized = font_blob->as(); + if (!font_blob->data) + { + printf("Sanitization of the file wasn't successful. Exit"); + exit(1); + } + const OpenTypeFontFile &ot = *sanitized; + + switch (ot.get_tag()) + { + case OpenTypeFontFile::TrueTypeTag: + printf("OpenType font with TrueType outlines\n"); + break; + case OpenTypeFontFile::CFFTag: + printf("OpenType font with CFF (Type1) outlines\n"); + break; + case OpenTypeFontFile::TTCTag: + printf("TrueType Collection of OpenType fonts\n"); + break; + case OpenTypeFontFile::TrueTag: + printf("Obsolete Apple TrueType font\n"); + break; + case OpenTypeFontFile::Typ1Tag: + printf("Obsolete Apple Type1 font in SFNT container\n"); + break; + case OpenTypeFontFile::DFontTag: + printf("DFont Mac Resource Fork\n"); + break; + default: + printf("Unknown font format\n"); + break; + } + + unsigned num_faces = hb_face_count(blob); + printf("%d font(s) found in file\n", num_faces); + for (unsigned n_font = 0; n_font < num_faces; ++n_font) + { + const OpenTypeFontFace &font = ot.get_face(n_font); + printf("Font %d of %d:\n", n_font, num_faces); + + unsigned num_tables = font.get_table_count(); + printf(" %d table(s) found in font\n", num_tables); + for (unsigned n_table = 0; n_table < num_tables; ++n_table) + { + const OpenTypeTable &table = font.get_table(n_table); + printf(" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables, (const char *)table.tag, (unsigned)table.offset, (unsigned)table.length); + + switch (table.tag) + { + + case HB_OT_TAG_GSUB: + case HB_OT_TAG_GPOS: + { + + const GSUBGPOS &g = *reinterpret_cast(font_data + table.offset); + + unsigned num_scripts = g.get_script_count(); + printf(" %d script(s) found in table\n", num_scripts); + for (unsigned n_script = 0; n_script < num_scripts; ++n_script) + { + const Script &script = g.get_script(n_script); + printf(" Script %2d of %2d: %.4s\n", n_script, num_scripts, (const char *)g.get_script_tag(n_script)); + + if (!script.has_default_lang_sys()) + printf(" No default language system\n"); + int num_langsys = script.get_lang_sys_count(); + printf(" %d language system(s) found in script\n", num_langsys); + for (int n_langsys = script.has_default_lang_sys() ? -1 : 0; n_langsys < num_langsys; ++n_langsys) + { + const LangSys &langsys = n_langsys == -1 ? script.get_default_lang_sys() : script.get_lang_sys(n_langsys); + if (n_langsys == -1) + printf(" Default Language System\n"); + else + printf(" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys, (const char *)script.get_lang_sys_tag(n_langsys)); + if (!langsys.has_required_feature()) + printf(" No required feature\n"); + else + printf(" Required feature index: %d\n", langsys.get_required_feature_index()); + + unsigned num_features = langsys.get_feature_count(); + printf(" %d feature(s) found in language system\n", num_features); + for (unsigned n_feature = 0; n_feature < num_features; ++n_feature) + { + printf(" Feature index %2d of %2d: %d\n", n_feature, num_features, langsys.get_feature_index(n_feature)); + } + } + } + + unsigned num_features = g.get_feature_count(); + printf(" %d feature(s) found in table\n", num_features); + for (unsigned n_feature = 0; n_feature < num_features; ++n_feature) + { + const Feature &feature = g.get_feature(n_feature); + unsigned num_lookups = feature.get_lookup_count(); + printf(" Feature %2d of %2d: %c%c%c%c\n", n_feature, num_features, HB_UNTAG(g.get_feature_tag(n_feature))); + + printf(" %d lookup(s) found in feature\n", num_lookups); + for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup) + { + printf(" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups, feature.get_lookup_index(n_lookup)); + } + } + + unsigned num_lookups = g.get_lookup_count(); + printf(" %d lookup(s) found in table\n", num_lookups); + for (unsigned n_lookup = 0; n_lookup < num_lookups; ++n_lookup) + { + const Lookup &lookup = g.get_lookup(n_lookup); + printf(" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups, lookup.get_type(), lookup.get_props()); + } + } + break; + + case GDEF::tableTag: + { + + const GDEF &gdef = *reinterpret_cast(font_data + table.offset); + + printf(" Has %sglyph classes\n", gdef.has_glyph_classes() ? "" : "no "); + printf(" Has %smark attachment types\n", gdef.has_mark_attachment_types() ? "" : "no "); + printf(" Has %sattach points\n", gdef.has_attach_points() ? "" : "no "); + printf(" Has %slig carets\n", gdef.has_lig_carets() ? "" : "no "); + printf(" Has %smark sets\n", gdef.has_mark_sets() ? "" : "no "); + + hb_position_t caret_array[16]; + unsigned int caret_count = 16; + + unsigned int num_carets = gdef.get_lig_carets(nullptr, HB_DIRECTION_LTR, 302, 0, &caret_count, caret_array); + int y = 0; + ++y; + + break; + } + } + } + } +} +/* end of private API use */ +#endif + +struct hb_feature_test { + hb_tag_t tag; + uint32_t value; +}; + +int main(int argc, char *argv[]) +{ + // hb_blob_t* blobFileTest = hb_blob_create_from_file("C:/Windows/Fonts/calibri.ttf"); + // print_layout_info_using_private_api(blobFileTest); + + int ptSize = 40 * 64; + int device_hdpi = 72; + int device_vdpi = 72; + + /* Init freetype */ + FT_Library ft_library; + assert(!FT_Init_FreeType(&ft_library)); + + /* Load our fonts */ + FT_Face ft_face[NUM_EXAMPLES]; + assert(!FT_New_Face(ft_library, fonts_paths[0], 0, &ft_face[ENGLISH])); + assert(!FT_Set_Char_Size(ft_face[ENGLISH], 0, ptSize, device_hdpi, device_vdpi)); + ftfdump(ft_face[ENGLISH]); // wonderful world of encodings ... + // force_ucs2_charmap(ft_face[ENGLISH]); // which we ignore. + + assert(!FT_New_Face(ft_library, fonts_paths[1], 0, &ft_face[ARABIC])); + assert(!FT_Set_Char_Size(ft_face[ARABIC], 0, ptSize, device_hdpi, device_vdpi)); + ftfdump(ft_face[ARABIC]); + // force_ucs2_charmap(ft_face[ARABIC]); + + assert(!FT_New_Face(ft_library, fonts_paths[2], 0, &ft_face[CHINESE])); + assert(!FT_Set_Char_Size(ft_face[CHINESE], 0, ptSize, device_hdpi, device_vdpi)); + ftfdump(ft_face[CHINESE]); + // force_ucs2_charmap(ft_face[CHINESE]); + + /* Get our harfbuzz font structs */ + hb_font_t *hb_ft_font[NUM_EXAMPLES]; + hb_ft_font[ENGLISH] = hb_ft_font_create(ft_face[ENGLISH], NULL); + + // hb_blob_t* blobFile = hb_blob_create_from_file(sFont1.c_str()); + // hb_face_t* faceFile = hb_face_create(blobFile, 0); + // hb_ft_font[ENGLISH] = hb_font_create(faceFile); + + hb_ft_font[ARABIC] = hb_ft_font_create(ft_face[ARABIC], NULL); + hb_ft_font[CHINESE] = hb_ft_font_create(ft_face[CHINESE], NULL); + + hb_ft_font_set_funcs(hb_ft_font[ENGLISH]); + hb_ft_font_set_funcs(hb_ft_font[ARABIC]); + hb_ft_font_set_funcs(hb_ft_font[CHINESE]); + + /** Setup our SDL window **/ + int width = 800; + int height = 600; + int bpp = 32; + + CDrawer oDrawer(width, height); + + /* Create a buffer for harfbuzz to use */ + hb_buffer_t *buf = hb_buffer_create(); + for (int i = 0; i < NUM_EXAMPLES; ++i) + { + if (text_skip[i]) + continue; + + hb_buffer_set_direction(buf, text_directions[i]); /* or LTR */ + hb_buffer_set_script(buf, scripts[i]); /* see hb-unicode.h */ + hb_buffer_set_language(buf, hb_language_from_string(languages[i], strlen(languages[i]))); + // hb_buffer_set_cluster_level (buf, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES); + // hb_buffer_set_cluster_level (buf, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); + hb_buffer_set_cluster_level(buf, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES); + + hb_feature_test features[] { + {HB_TAG('r','l','i','g'), 1}, + {HB_TAG('l','i','g','a'), 0}, + {HB_TAG('c','l','i','g'), 1}, + {HB_TAG('h','l','i','g'), 1}, + {HB_TAG('d','l','i','g'), 1}, + {HB_TAG('k','e','r','n'), 2}, + {0, 0} + }; + + int userfeatures_count = 0; + hb_feature_t userfeatures[100]; + + hb_feature_test* current_feature = features; + while (current_feature->tag != 0) + { + if (current_feature->value != 2) + { + userfeatures[userfeatures_count].tag = current_feature->tag; + userfeatures[userfeatures_count].value = current_feature->value; + userfeatures[userfeatures_count].start = HB_FEATURE_GLOBAL_START; + userfeatures[userfeatures_count].end = HB_FEATURE_GLOBAL_END; + userfeatures_count++; + } + current_feature++; + } + + /* Layout the text */ + hb_buffer_add_utf8(buf, texts[i], strlen(texts[i]), 0, strlen(texts[i])); + + // detect script by codes + hb_buffer_guess_segment_properties(buf); + + // const char*const pHbShapers[] = { "graphite2", "coretext_aat", "ot", "fallback", nullptr }; + // bool ok = hb_shape_full(hb_ft_font[i], buf, userfeatures, userfeatures_count, pHbShapers); + + hb_shape(hb_ft_font[i], buf, (userfeatures_count != 0) ? userfeatures : NULL, userfeatures_count); + + unsigned int glyph_count; + hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count); + hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count); + +#if 1 + hb_position_t caret_array[16]; + unsigned int caret_count = 16; + + unsigned int num_carets = hb_ot_layout_get_ligature_carets(hb_ft_font[i], text_directions[i], glyph_info[0].codepoint, -1, &caret_count, caret_array); +#endif + + /* set up rendering via spanners */ + spanner_baton_t stuffbaton; + + FT_Raster_Params ftr_params; + ftr_params.target = 0; + ftr_params.flags = FT_RASTER_FLAG_DIRECT | FT_RASTER_FLAG_AA; + ftr_params.user = &stuffbaton; + ftr_params.black_spans = 0; + ftr_params.bit_set = 0; + ftr_params.bit_test = 0; + + /* Calculate string bounding box in pixels */ + ftr_params.gray_spans = spanner_sizer; + + /* See http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html */ + + int max_x = INT_MIN; // largest coordinate a pixel has been set at, or the pen was advanced to. + int min_x = INT_MAX; // smallest coordinate a pixel has been set at, or the pen was advanced to. + int max_y = INT_MIN; // this is max topside bearing along the string. + int min_y = INT_MAX; // this is max value of (height - topbearing) along the string. + /* Naturally, the above comments swap their meaning between horizontal and vertical scripts, + since the pen changes the axis it is advanced along. + However, their differences still make up the bounding box for the string. + Also note that all this is in FT coordinate system where y axis points upwards. + */ + + int sizer_x = 0; + int sizer_y = 0; /* in FT coordinate system. */ + + printf("----------------------------------------------------\n"); + for (unsigned j = 0; j < glyph_count; ++j) + { + hb_ot_layout_glyph_class_t glyph_type = hb_ot_layout_get_glyph_class(hb_font_get_face(hb_ft_font[i]), glyph_info[j].codepoint); + hb_glyph_flags_t glyph_type_flags = hb_glyph_info_get_glyph_flags(&glyph_info[j]); + printf( + "glyph(%s, flags: %d): gid:%d, cluster:%d, [%d, %d, %d, %d, %d]\n", num_glyph_types[glyph_type], glyph_type_flags, (int)glyph_info[j].codepoint, (int)glyph_info[j].cluster, + glyph_pos[j].x_advance, glyph_pos[j].y_advance, glyph_pos[j].x_offset, glyph_pos[j].y_offset, glyph_pos[j].var); + } + + FT_Error fterr; + for (unsigned j = 0; j < glyph_count; ++j) + { + if ((fterr = FT_Load_Glyph(ft_face[i], glyph_info[j].codepoint, 0))) + { + printf("load %08x failed fterr=%d.\n", glyph_info[j].codepoint, fterr); + } + else + { + if (ft_face[i]->glyph->format != FT_GLYPH_FORMAT_OUTLINE) + { + printf("glyph->format = %4s\n", (char *)&ft_face[i]->glyph->format); + } + else + { + int gx = sizer_x + (glyph_pos[j].x_offset / 64); + int gy = sizer_y + (glyph_pos[j].y_offset / 64); // note how the sign differs from the rendering pass + + stuffbaton.min_span_x = INT_MAX; + stuffbaton.max_span_x = INT_MIN; + stuffbaton.min_y = INT_MAX; + stuffbaton.max_y = INT_MIN; + + if ((fterr = FT_Outline_Render(ft_library, &ft_face[i]->glyph->outline, &ftr_params))) + printf("FT_Outline_Render() failed err=%d\n", fterr); + + if (stuffbaton.min_span_x != INT_MAX) + { + /* Update values if the spanner was actually called. */ + if (min_x > stuffbaton.min_span_x + gx) + min_x = stuffbaton.min_span_x + gx; + + if (max_x < stuffbaton.max_span_x + gx) + max_x = stuffbaton.max_span_x + gx; + + if (min_y > stuffbaton.min_y + gy) + min_y = stuffbaton.min_y + gy; + + if (max_y < stuffbaton.max_y + gy) + max_y = stuffbaton.max_y + gy; + } + else + { + /* The spanner wasn't called at all - an empty glyph, like space. */ + if (min_x > gx) + min_x = gx; + if (max_x < gx) + max_x = gx; + if (min_y > gy) + min_y = gy; + if (max_y < gy) + max_y = gy; + } + } + } + + sizer_x += glyph_pos[j].x_advance / 64; + sizer_y += glyph_pos[j].y_advance / 64; // note how the sign differs from the rendering pass + } + /* Still have to take into account last glyph's advance. Or not? */ + if (min_x > sizer_x) + min_x = sizer_x; + if (max_x < sizer_x) + max_x = sizer_x; + if (min_y > sizer_y) + min_y = sizer_y; + if (max_y < sizer_y) + max_y = sizer_y; + + /* The bounding box */ + int bbox_w = max_x - min_x; + int bbox_h = max_y - min_y; + + /* Two offsets below position the bounding box with respect to the 'origin', + which is sort of origin of string's first glyph. + + baseline_offset - offset perpendecular to the baseline to the topmost (horizontal), + or leftmost (vertical) pixel drawn. + + baseline_shift - offset along the baseline, from the first drawn glyph's origin + to the leftmost (horizontal), or topmost (vertical) pixel drawn. + + Thus those offsets allow positioning the bounding box to fit the rendered string, + as they are in fact offsets from the point given to the renderer, to the top left + corner of the bounding box. + + NB: baseline is defined as y==0 for horizontal and x==0 for vertical scripts. + (0,0) here is where the first glyph's origin ended up after shaping, not taking + into account glyph_pos[0].xy_offset (yeah, my head hurts too). + */ + + int baseline_offset; + int baseline_shift; + + if (HB_DIRECTION_IS_HORIZONTAL(hb_buffer_get_direction(buf))) + { + baseline_offset = max_y; + baseline_shift = min_x; + } + if (HB_DIRECTION_IS_VERTICAL(hb_buffer_get_direction(buf))) + { + baseline_offset = min_x; + baseline_shift = max_y; + } + + /* The pen/baseline start coordinates in window coordinate system + - with those text placement in the window is controlled. + - note that for RTL scripts pen still goes LTR */ + int x = 0, y = 50 + i * 75; + if (i == ENGLISH) + { + x = 20; + } /* left justify */ + if (i == ARABIC) + { + x = width - bbox_w - 20; + } /* right justify */ + if (i == CHINESE) + { + x = width / 2 - bbox_w / 2; + } /* center, and for TTB script h_advance is half-width. */ + + /* Draw baseline and the bounding box */ + /* The below is complicated since we simultaneously + convert to the window coordinate system. */ + int left, right, top, bottom; + + if (HB_DIRECTION_IS_HORIZONTAL(hb_buffer_get_direction(buf))) + { + /* bounding box in window coordinates without offsets */ + left = x; + right = x + bbox_w; + top = y - bbox_h; + bottom = y; + + /* apply offsets */ + left += baseline_shift; + right += baseline_shift; + top -= baseline_offset - bbox_h; + bottom -= baseline_offset - bbox_h; + + /* draw the baseline */ + hline(&oDrawer, x, x + bbox_w, y, 0x0000ff00); + } + + if (HB_DIRECTION_IS_VERTICAL(hb_buffer_get_direction(buf))) + { + left = x; + right = x + bbox_w; + top = y; + bottom = y + bbox_h; + + left += baseline_offset; + right += baseline_offset; + top -= baseline_shift; + bottom -= baseline_shift; + + vline(&oDrawer, y, y + bbox_h, x, 0x0000ff00); + } + + /* +1/-1 are for the bbox borders be the next pixel outside the bbox itself */ + hline(&oDrawer, left - 1, right + 1, top - 1, 0xffff0000); + hline(&oDrawer, left - 1, right + 1, bottom + 1, 0xffff0000); + vline(&oDrawer, top - 1, bottom + 1, left - 1, 0xffff0000); + vline(&oDrawer, top - 1, bottom + 1, right + 1, 0xffff0000); + + /* set rendering spanner */ + ftr_params.gray_spans = spanner; + + /* initialize rendering part of the baton */ + stuffbaton.pixels = NULL; + stuffbaton.first_pixel = (uint32_t *)oDrawer.pixels; + stuffbaton.last_pixel = (uint32_t *)(((uint8_t *)oDrawer.pixels) + oDrawer.pitch * oDrawer.height); + stuffbaton.pitch = oDrawer.pitch; + stuffbaton.rshift = oDrawer.Rshift; + stuffbaton.gshift = oDrawer.Gshift; + stuffbaton.bshift = oDrawer.Bshift; + + /* render */ + for (unsigned j = 0; j < glyph_count; ++j) + { + if ((fterr = FT_Load_Glyph(ft_face[i], glyph_info[j].codepoint, 0))) + { + printf("load %08x failed fterr=%d.\n", glyph_info[j].codepoint, fterr); + } + else + { + if (ft_face[i]->glyph->format != FT_GLYPH_FORMAT_OUTLINE) + { + printf("glyph->format = %4s\n", (char *)&ft_face[i]->glyph->format); + } + else + { + int gx = x + (glyph_pos[j].x_offset / 64); + int gy = y - (glyph_pos[j].y_offset / 64); + + stuffbaton.pixels = (uint32_t *)(((uint8_t *)oDrawer.pixels) + gy * oDrawer.pitch) + gx; + + if ((fterr = FT_Outline_Render(ft_library, &ft_face[i]->glyph->outline, &ftr_params))) + printf("FT_Outline_Render() failed err=%d\n", fterr); + } + } + + x += glyph_pos[j].x_advance / 64; + y -= glyph_pos[j].y_advance / 64; + } + + /* clean up the buffer, but don't kill it just yet */ + hb_buffer_clear_contents(buf); + } + + /* Cleanup */ + hb_buffer_destroy(buf); + for (int i = 0; i < NUM_EXAMPLES; ++i) + hb_font_destroy(hb_ft_font[i]); + + FT_Done_FreeType(ft_library); + + oDrawer.Save(); + + return 0; +} diff --git a/Common/3dParty/harfbuzz/test/test.pro b/Common/3dParty/harfbuzz/test/test.pro new file mode 100644 index 0000000000..0c12104f72 --- /dev/null +++ b/Common/3dParty/harfbuzz/test/test.pro @@ -0,0 +1,19 @@ +CONFIG -= qt +TARGET = test +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle + +CORE_ROOT_DIR = $$PWD/../../../../../core +PWD_ROOT_DIR = $$PWD +include($$CORE_ROOT_DIR/Common/base.pri) + +include($$CORE_ROOT_DIR/DesktopEditor/graphics/pro/freetype.pri) +include($$CORE_ROOT_DIR/Common/3dParty/harfbuzz/harfbuzz.pri) + +SOURCES += main.cpp + +ADD_DEPENDENCY(UnicodeConverter, kernel, graphics) +DESTDIR = $$PWD/build + + diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index d923e424eb..c5cb83d205 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -686,6 +686,7 @@ const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetDV() { return m_wsDV; } const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetT() { return m_wsT; } const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetFontName() { return m_wsFN; } const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetFontKey() { return m_wsFK; } +const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetOMetadata() { return m_wsOMetadata; } const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetTC() { return m_arrTC; } const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetBC() { return m_arrBC; } const std::vector& CAnnotFieldInfo::CWidgetAnnotPr::GetBG() { return m_arrBG; } @@ -886,6 +887,8 @@ void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader m_nParentID = pReader->ReadInt(); if (nFlags & (1 << 18)) m_wsT = pReader->ReadString(); + if (nFlags & (1 << 20)) + m_wsOMetadata = pReader->ReadString(); // Action int nAction = pReader->ReadInt(); diff --git a/DesktopEditor/graphics/commands/AnnotField.h b/DesktopEditor/graphics/commands/AnnotField.h index c0f202ad02..fe054d3500 100644 --- a/DesktopEditor/graphics/commands/AnnotField.h +++ b/DesktopEditor/graphics/commands/AnnotField.h @@ -194,6 +194,7 @@ public: const std::wstring& GetT(); const std::wstring& GetFontName(); const std::wstring& GetFontKey(); + const std::wstring& GetOMetadata(); const std::vector& GetTC(); const std::vector& GetBC(); const std::vector& GetBG(); @@ -223,6 +224,7 @@ public: std::wstring m_wsT; std::wstring m_wsFN; std::wstring m_wsFK; + std::wstring m_wsOMetadata; std::vector m_arrTC; std::vector m_arrBC; std::vector m_arrBG; diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js index c75590e0e7..608782cf79 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js @@ -519,6 +519,9 @@ function readAnnotAP(reader, AP) // 0 - Normal, 1 - Multiply, 2 - Screen, 3 - Overlay, 4 - Darken, 5 - Lighten, 6 - ColorDodge, 7 - ColorBurn, 8 - HardLight, // 9 - SoftLight, 10 - Difference, 11 - Exclusion, 12 - Hue, 13 - Saturation, 14 - Color, 15 - Luminosity APi["BlendMode"] = reader.readByte(); + let k = reader.readByte(); + if (k != 0) + APi["apValue"] = reader.readString(); } } @@ -651,6 +654,8 @@ CFile.prototype["getInteractiveFormsInfo"] = function() rec["name"] = reader.readString(); if (flags & (1 << 19)) rec["font"]["AP"] = reader.readString(); + if (flags & (1 << 20)) + rec["meta"] = reader.readString(); // Action let nAction = reader.readInt(); if (nAction > 0) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index e36f48cd53..d50befd840 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -542,6 +542,13 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i) std::cout << "Font button " << std::string((char*)(pWidgets + i), nPathLength) << ", "; i += nPathLength; } + if (nFlags & (1 << 20)) + { + nPathLength = READ_INT(pWidgets + i); + i += 4; + std::cout << "OMetadata " << std::string((char*)(pWidgets + i), nPathLength) << ", "; + i += nPathLength; + } //Action @@ -807,6 +814,16 @@ void ReadAnnotAP(BYTE* pWidgetsAP, int& i) std::string arrBlendMode[] = { "Normal", "Multiply", "Screen", "Overlay", "Darken", "Lighten", "ColorDodge", "ColorBurn", "HardLight", "SoftLight", "Difference", "Exclusion", "Hue", "Saturation", "Color", "Luminosity" }; std::cout << "Type " << arrBlendMode[nPathLength] << ", "; + + int bText = READ_BYTE(pWidgetsAP + i); + i += 1; + if (bText != 0) + { + nPathLength = READ_INT(pWidgetsAP + i); + i += 4; + std::cout << "Text " << std::string((char*)(pWidgetsAP + i), nPathLength) << ", "; + i += nPathLength; + } } std::cout << std::endl; } @@ -1090,7 +1107,7 @@ int main(int argc, char* argv[]) } // GLYPHS - if (true && nPagesCount > 0) + if (false && nPagesCount > 0) { BYTE* pGlyphs = GetGlyphs(pGrFile, nTestPage); nLength = READ_INT(pGlyphs); @@ -1165,7 +1182,7 @@ int main(int argc, char* argv[]) } // INTERACTIVE FORMS - if (false) + if (true) { ReadInteractiveFormsFonts(pGrFile, 1); ReadInteractiveFormsFonts(pGrFile, 2); diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/StringPtgParser.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/StringPtgParser.cpp index b6c345b5cc..fa24bcb4b8 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/StringPtgParser.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_structures/StringPtgParser.cpp @@ -317,9 +317,6 @@ const bool StringPtgParser::parseToPtgs(const std::wstring& assembled_formula, R [&](XLS::GlobalWorkbookInfo::_xti i) { return i.iSup == ixti; }); - if(pos->itabFirst == pos->itabLast) - rgce.addPtg(found_operand = OperandPtgPtr(new PtgRef3d(ixti, operand_str, OperandPtg::ptg_VALUE, rgce.getLocation()))); - else rgce.addPtg(found_operand = OperandPtgPtr(new PtgRef3d(ixti, operand_str, OperandPtg::ptg_REFERENCE, rgce.getLocation()))); } else if(SyntaxPtg::extract_PtgRefErr(it, itEnd)) diff --git a/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp b/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp index 7fbdad0424..5bb71f5962 100644 --- a/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp +++ b/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp @@ -2663,6 +2663,9 @@ void BinaryWorkbookTableWriter::WritePivotCache(OOX::Spreadsheet::CWorkbook& wor { nCurPos = m_oBcw.WriteItemStart(c_oSer_PivotTypes::cache); NSStringUtils::CStringBuilder writer; + writer.WriteString(L""); + if(pivotCacheFile->m_oPivotCashDefinition->m_oRid.IsInit()) + pivotCacheFile->m_oPivotCashDefinition->m_oRid.reset(); pivotCacheFile->m_oPivotCashDefinition->toXML(writer); auto wstringData = writer.GetData(); m_oBcw.m_oStream.WriteStringUtf8(wstringData); diff --git a/OOXML/Binary/Sheets/Writer/BinaryReader.cpp b/OOXML/Binary/Sheets/Writer/BinaryReader.cpp index 30cc7898a3..6d17e596fe 100644 --- a/OOXML/Binary/Sheets/Writer/BinaryReader.cpp +++ b/OOXML/Binary/Sheets/Writer/BinaryReader.cpp @@ -3579,7 +3579,7 @@ int BinaryWorkbookTableReader::ReadPivotCaches(BYTE type, long length, void* poR pFileRecords->OOX::File::m_pMainDocument = m_pXlsb; srIdRecords = pDefinitionFile->Add(pFileRecords).ToString(); } - pDefinitionFile->setData(oPivotCachesTemp.pDefinitionData, oPivotCachesTemp.nDefinitionLength, L""); + pDefinitionFile->setData(oPivotCachesTemp.pDefinitionData, oPivotCachesTemp.nDefinitionLength, srIdRecords); NSCommon::smart_ptr pFile(pDefinitionFile); OOX::RId rIdDefinition = m_oWorkbook.Add(pFile); diff --git a/OOXML/XlsbFormat/Biff12_records/BeginSXPI.h b/OOXML/XlsbFormat/Biff12_records/BeginSXPI.h index f2c6ab120d..cb384c31e9 100644 --- a/OOXML/XlsbFormat/Biff12_records/BeginSXPI.h +++ b/OOXML/XlsbFormat/Biff12_records/BeginSXPI.h @@ -51,11 +51,11 @@ namespace XLSB void readFields(XLS::CFRecord& record) override; void writeFields(XLS::CFRecord& record) override; - _INT32 isxvd; - _UINT32 isxvi; - _INT32 isxth; - bool fUnique; - bool fDisplay; + _INT32 isxvd = 0; + _UINT32 isxvi = 0x001000FE; + _INT32 isxth = -1; + bool fUnique = false; + bool fDisplay = false; XLWideString irstUnique; XLWideString irstDisplay; }; diff --git a/OOXML/XlsxFormat/Pivot/Pivots.cpp b/OOXML/XlsxFormat/Pivot/Pivots.cpp index 8faff378ad..4fa54109bc 100644 --- a/OOXML/XlsxFormat/Pivot/Pivots.cpp +++ b/OOXML/XlsxFormat/Pivot/Pivots.cpp @@ -1912,13 +1912,15 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" if(m_oHier.IsInit()) ptr->isxth = m_oHier.get(); if(m_oName.IsInit()) + { ptr->irstUnique = m_oName.get(); - else - ptr->irstUnique = 0xFFFFFFFF; + ptr->fUnique = true; + } if(m_oCap.IsInit()) + { ptr->irstDisplay = m_oCap.get(); - else - ptr->irstDisplay = 0xFFFFFFFF; + ptr->fDisplay = true; + } return objectPtr; } void CPageField::fromBin(XLS::BaseObjectPtr& obj) @@ -4225,7 +4227,6 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" writer.WriteString(L"GetValue()); WritingStringNullableAttrInt(L"mappingCount", m_oMappingCount, m_oMappingCount->GetValue()); WritingStringNullableAttrInt(L"numFmtId", m_oNumFmtId, m_oNumFmtId->GetValue()); + WritingStringNullableAttrBool2(L"databaseField", m_oDatabaseField); if(!m_oSharedItems.IsInit() && !m_oFieldGroup.IsInit()) { writer.WriteString(L"/>"); @@ -4459,22 +4461,29 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" void CSharedItems::toXML(NSStringUtils::CStringBuilder& writer) const { writer.WriteString(L"ToString()); WritingStringNullableAttrString(L"maxDate", m_oMaxDate, m_oMaxDate->ToString()); - writer.WriteString(L">"); - + if(!m_arrItems.empty()) + { + WritingStringAttrInt(L"count", (int)m_arrItems.size()); + } + WritingStringNullableAttrBool2(L"longText", m_oLongText); + if(m_arrItems.empty()) + { + writer.WriteString(L"/>"); + return; + } + writer.WriteString(L">"); for ( size_t i = 0; i < m_arrItems.size(); ++i) { if ( m_arrItems[i] ) @@ -5180,7 +5189,7 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" //------------------------------------ void CRangeGroupingProperties::toXML(NSStringUtils::CStringBuilder& writer) const { - writer.WriteString(L"ToString()); WritingStringNullableAttrBool2(L"autoStart", m_oAutoStart); WritingStringNullableAttrBool2(L"autoEnd", m_oAutoEnd); @@ -5888,6 +5897,11 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" } WritingStringNullableAttrBool2(L"f", m_oCalculated); WritingStringNullableAttrBool2(L"u", m_oUnused); + if(m_arrItems.empty()) + { + writer.WriteString(L"/>"); + return; + } writer.WriteString(L">"); for ( size_t i = 0; i < m_arrItems.size(); ++i) @@ -6020,6 +6034,11 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" } WritingStringNullableAttrBool2(L"f", m_oCalculated); WritingStringNullableAttrBool2(L"u", m_oUnused); + if(m_arrItems.empty()) + { + writer.WriteString(L"/>"); + return; + } writer.WriteString(L">"); for ( size_t i = 0; i < m_arrItems.size(); ++i) @@ -6917,8 +6936,8 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" void CFieldGroupProperties::toXML(NSStringUtils::CStringBuilder& writer) const { writer.WriteString(L"GetValue()); WritingStringNullableAttrInt(L"par", m_oPar, m_oPar->GetValue()); + WritingStringNullableAttrInt(L"base", m_oBase, m_oBase->GetValue()); writer.WriteString(L">"); if(m_oDiscretePr.IsInit()) diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index c16c76921e..56e4d1f8a9 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -2176,6 +2176,8 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF pWidgetAnnot->SetDV(pPr->GetDV()); if (nFlags & (1 << 18)) pWidgetAnnot->SetT(pPr->GetT()); + if (nFlags & (1 << 20)) + pWidgetAnnot->SetOMetadata(pPr->GetOMetadata()); const std::vector arrActions = pPr->GetActions(); for (CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pAction : arrActions) diff --git a/PdfFile/SrcReader/Adaptors.cpp b/PdfFile/SrcReader/Adaptors.cpp index ad8da8382c..62ac8e8001 100644 --- a/PdfFile/SrcReader/Adaptors.cpp +++ b/PdfFile/SrcReader/Adaptors.cpp @@ -185,6 +185,14 @@ bool GlobalParamsAdaptor::GetCMap(const char* sName, char*& pData, unsigned int& return false; } +void GlobalParamsAdaptor::AddTextFormField(const std::wstring& sText) +{ + m_sTextFormField += sText; +} +std::string GlobalParamsAdaptor::GetTextFormField() +{ + return U_TO_UTF8(m_sTextFormField); +} bool operator==(const Ref &a, const Ref &b) { diff --git a/PdfFile/SrcReader/Adaptors.h b/PdfFile/SrcReader/Adaptors.h index 825c4801f1..ca27ed5f15 100644 --- a/PdfFile/SrcReader/Adaptors.h +++ b/PdfFile/SrcReader/Adaptors.h @@ -59,6 +59,7 @@ class GlobalParamsAdaptor : public GlobalParams BYTE* m_bCMapData; DWORD m_nCMapDataLength; + std::wstring m_sTextFormField; bool m_bDrawFormField; public: @@ -90,6 +91,8 @@ public: void SetCMapMemory(BYTE* pData, DWORD nSizeData); bool GetCMap(const char* sName, char*& pData, unsigned int& nSize); + void AddTextFormField(const std::wstring& sText); + std::string GetTextFormField(); void setDrawFormField(bool bDrawFormField) { m_bDrawFormField = bDrawFormField; } bool getDrawFormField() { return m_bDrawFormField; } private: diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index 6db2cbd03b..5a5e5ecf8f 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -1274,7 +1274,7 @@ CAnnotWidgetCh::CAnnotWidgetCh(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnotWi Object oOpt; // 10 - Список значений - if (pField->fieldLookup("Opt", &oOpt)->isArray()) + if (oField.dictLookup("Opt", &oOpt)->isArray()) { m_unFlags |= (1 << 10); int nOptLength = oOpt.arrayGetLength(); @@ -1502,6 +1502,9 @@ CAnnotWidget::CAnnotWidget(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot(pdfDo // 18 - Частичное имя поля - T m_sT = DictLookupString(&oField, "T", 18); + // 20 - OO метаданные форм - OMetadata + m_sOMetadata = DictLookupString(&oField, "OMetadata", 20); + // Action - A Object oAction; if (pField->fieldLookup("A", &oAction)->isDict()) @@ -3545,6 +3548,7 @@ void CAnnotAP::WriteAppearance(unsigned int nColor, CAnnotAPView* pView) } pView->pAP = pSubMatrix; + pView->sText = ((GlobalParamsAdaptor*)globalParams)->GetTextFormField(); } BYTE CAnnotAP::GetBlendMode() { @@ -3577,6 +3581,14 @@ void CAnnotAP::ToWASM(NSWasm::CData& oRes) oRes.AddInt(npSubMatrix >> 32); oRes.WriteBYTE(m_arrAP[i]->nBlendMode); + + if (m_arrAP[i]->sText.empty()) + oRes.WriteBYTE(0); + else + { + oRes.WriteBYTE(1); + oRes.WriteString(m_arrAP[i]->sText); + } } } void CAnnots::ToWASM(NSWasm::CData& oRes) @@ -3720,6 +3732,8 @@ void CAnnotWidget::ToWASM(NSWasm::CData& oRes) oRes.WriteString(m_sT); if (m_unFlags & (1 << 19)) oRes.WriteString(m_sButtonFontName); + if (m_unFlags & (1 << 20)) + oRes.WriteString(m_sOMetadata); oRes.AddInt(m_arrAction.size()); for (int i = 0; i < m_arrAction.size(); ++i) { diff --git a/PdfFile/SrcReader/PdfAnnot.h b/PdfFile/SrcReader/PdfAnnot.h index 4eeec542c6..7b10bf5360 100644 --- a/PdfFile/SrcReader/PdfAnnot.h +++ b/PdfFile/SrcReader/PdfAnnot.h @@ -129,6 +129,7 @@ private: BYTE nBlendMode; std::string sAPName; std::string sASName; + std::string sText; BYTE* pAP; }; @@ -246,6 +247,7 @@ private: std::string m_sT; // Частичное имя поля - T std::string m_sFontKey; // Уникальный идентификатор шрифта std::string m_sFontName; // Имя шрифта - из DA + std::string m_sOMetadata; // OO метаданные формы std::string m_sActualFontName; // Имя замененного шрифта std::string m_sButtonFontName; // Имя шрифта кнопки }; diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index 4109ae0b24..69eb23eb36 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -2518,6 +2518,8 @@ namespace PdfReader } } } + if (((GlobalParamsAdaptor*)globalParams)->getDrawFormField()) + ((GlobalParamsAdaptor*)globalParams)->AddTextFormField(wsUnicodeText); #endif m_pRenderer->CommandDrawTextEx(wsUnicodeText, &unGid, unGidsCount, PDFCoordsToMM(dShiftX), PDFCoordsToMM(dShiftY), PDFCoordsToMM(dDx), PDFCoordsToMM(dDy)); if (bReplace) diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index 2cf08c0312..eb123ae3a8 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -1628,6 +1628,16 @@ namespace PdfWriter pOwner->Add("T", new CStringObject(sValue.c_str(), true)); } } + void CWidgetAnnotation::SetOMetadata(const std::wstring& wsOMetadata) + { + std::string sValue = U_TO_UTF8(wsOMetadata); + CDictObject* pOwner = GetObjOwnValue("OMetadata"); + if (!pOwner) + { + pOwner = this; + pOwner->Add("OMetadata", new CStringObject(sValue.c_str(), true)); + } + } void CWidgetAnnotation::SetBC(const std::vector& arrBC) { CheckMK(); diff --git a/PdfFile/SrcWriter/Annotation.h b/PdfFile/SrcWriter/Annotation.h index 890249a9de..e1bb6a46ec 100644 --- a/PdfFile/SrcWriter/Annotation.h +++ b/PdfFile/SrcWriter/Annotation.h @@ -447,6 +447,7 @@ namespace PdfWriter void SetDS(const std::wstring& wsDS); void SetDV(const std::wstring& wsDV); void SetT (const std::wstring& wsT); + void SetOMetadata(const std::wstring& wsOMetadata); void SetBC(const std::vector& arrBC); void SetBG(const std::vector& arrBG); void AddAction(CAction* pAction);