mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Compare commits
495 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37a5ce4781 | |||
| 80ed0318b6 | |||
| 3723ba064c | |||
| ac2562f83e | |||
| 85b6e2d568 | |||
| 43becd1cdb | |||
| 6aa68f1c81 | |||
| e9852e812f | |||
| d2ea9521b5 | |||
| 06f8099497 | |||
| ba9d3bcda5 | |||
| a3878b3770 | |||
| b177d01071 | |||
| 3d7638c3cc | |||
| ccad697cd8 | |||
| dd60367d01 | |||
| 54bbbbc3d7 | |||
| 9b901f7834 | |||
| 4f59af17b8 | |||
| b9258429f6 | |||
| e8f2c55ad4 | |||
| 46f6ba4d0a | |||
| 09b55bd1f1 | |||
| 176053e8d8 | |||
| 01365f938c | |||
| d168e4594f | |||
| cad36a73be | |||
| 0c9fa4709f | |||
| 27d2e40da7 | |||
| 14b09ce582 | |||
| aeeab690b1 | |||
| 016a0a971b | |||
| afe55a456f | |||
| a430ba92ad | |||
| efc1149235 | |||
| 567cc14bc7 | |||
| 0fc7f2a8b3 | |||
| b14fa1c2a1 | |||
| 2c27cfc720 | |||
| 1d31e5836b | |||
| 6adf65d3a8 | |||
| 093e1348fa | |||
| b78157487a | |||
| 77b30109f0 | |||
| efd047be74 | |||
| 61abfdb272 | |||
| f5088f43d8 | |||
| 6b3c395220 | |||
| 67cb29652d | |||
| d0cb082b33 | |||
| 2eff67efc3 | |||
| 84416ef5b6 | |||
| 447ade207f | |||
| ddd7628bbe | |||
| 1f86b0265a | |||
| e484db496b | |||
| 5bc1c8d860 | |||
| dbdf4bd120 | |||
| a93db0e012 | |||
| f145378002 | |||
| 4e800f6952 | |||
| 8098fec345 | |||
| 7bfcea0fff | |||
| 4b4845c558 | |||
| b26e3e2fee | |||
| 388951670c | |||
| 7d3488abc9 | |||
| fea3910254 | |||
| 2d58b08f0f | |||
| 612142f0ae | |||
| 2a0c84513b | |||
| b7d3464609 | |||
| beb8574dfd | |||
| c22cc89ef0 | |||
| 58255093bf | |||
| 50846677d5 | |||
| 3b450306f1 | |||
| c67ec5f632 | |||
| 62450ee1fb | |||
| ad301b6f50 | |||
| d251682639 | |||
| 896427db83 | |||
| e03f02103b | |||
| 27c7920def | |||
| a1b0421ec1 | |||
| b7972ea391 | |||
| 17840c5ed7 | |||
| ff4726e6ec | |||
| 4e9cd74367 | |||
| b8737d2474 | |||
| 2f4b7442c7 | |||
| d97d2668d2 | |||
| 45da53e9ae | |||
| 618a7ea09e | |||
| a33743cff2 | |||
| a83e19cbdf | |||
| 8a991ae24a | |||
| 6caca87b64 | |||
| 9ab884ae24 | |||
| e493d976e3 | |||
| d75e7342cf | |||
| ddd750be9c | |||
| 79a4434583 | |||
| 44ff2aff3c | |||
| 2f4b3e41b3 | |||
| fe208f5243 | |||
| e41c1d9703 | |||
| 1cb56e532c | |||
| 5c5f98a6e3 | |||
| f9dd82ad47 | |||
| 084c8f4b94 | |||
| bf15325a9e | |||
| 1b50b3a53a | |||
| 70b40c46d2 | |||
| 23798f3c96 | |||
| d91c6ff830 | |||
| b75a577793 | |||
| 1e8d22080d | |||
| 90bcd47fb7 | |||
| c1adf0b30c | |||
| b65ed1ccb4 | |||
| 8e4bbb5e27 | |||
| 81a4d9ccd0 | |||
| a97014c173 | |||
| b3951d083a | |||
| 7d78b37540 | |||
| ff162d451e | |||
| 5dc6402006 | |||
| fae17d9bfc | |||
| 931f4edae4 | |||
| 3609cf1237 | |||
| cc8fa641aa | |||
| 3b9a865d77 | |||
| f3b0a992bd | |||
| 74f3e7f279 | |||
| d195aa4a79 | |||
| 4a384edf08 | |||
| 30f96cbc6c | |||
| 007362d8be | |||
| f4aac048ea | |||
| f815fec8ed | |||
| 4ec217226d | |||
| 3cef41e876 | |||
| 20bff1d6fe | |||
| 8da1a109de | |||
| 704cef604e | |||
| 3c850e2086 | |||
| ab660cb8a3 | |||
| af4343b1d8 | |||
| 7e4fe558f4 | |||
| f942e56361 | |||
| 8b85f6987f | |||
| cbe412d3c7 | |||
| 6913cae8f3 | |||
| d3d9c8df94 | |||
| 01b582c4b9 | |||
| 4568144a22 | |||
| cc4df3726a | |||
| 696610862a | |||
| da6a5e9e98 | |||
| d395e63b80 | |||
| 0350675df6 | |||
| aead2e9fb8 | |||
| d12bad7bd1 | |||
| da2284fff6 | |||
| 1382aa0b3d | |||
| 8ba5df60d9 | |||
| 5299872b17 | |||
| e1757dd5d1 | |||
| 87dcea55b1 | |||
| b5c5a5f1ed | |||
| 6979e17c3d | |||
| c43fb92860 | |||
| c2dc112949 | |||
| 63887c95b6 | |||
| d3d4e86925 | |||
| f6383571eb | |||
| a6f6a67aed | |||
| f9543ef9de | |||
| bb58be4f18 | |||
| 40efe7dabc | |||
| 80b7caaf7a | |||
| 08e3dfb061 | |||
| 3a9d91b291 | |||
| 45b26554b2 | |||
| 09c4df8e05 | |||
| 85533a6553 | |||
| 65898a94ad | |||
| 86009ff6fa | |||
| b91dfb075e | |||
| f057a16bc1 | |||
| bd76adc97f | |||
| 27b5dbf15e | |||
| 58a7c7cd9d | |||
| 18fa4639b0 | |||
| 389e5314df | |||
| 42636a8ab1 | |||
| a3c87e7119 | |||
| 2115371c0c | |||
| bd95478d77 | |||
| 965680de23 | |||
| ad44ddf682 | |||
| 06386d5458 | |||
| ffda83848d | |||
| 55dc0b789f | |||
| 53e3f8c561 | |||
| 731a7addee | |||
| 36b82c1ef9 | |||
| 229a8f9dad | |||
| 5f5d74df92 | |||
| 66ea88bf14 | |||
| 3953044063 | |||
| 9a4a1546cb | |||
| 4085ee5002 | |||
| f6ef582658 | |||
| 7b62295149 | |||
| 421dcd780d | |||
| b9e7a3143c | |||
| c85713d82a | |||
| 6d970d0706 | |||
| 6026841c00 | |||
| 1e6d0a9f25 | |||
| adad3a05ba | |||
| 99fa27e693 | |||
| cf047defac | |||
| 6b66c8fb50 | |||
| 9faa7fb69d | |||
| 84042360ab | |||
| 8a8a6e78eb | |||
| 8bd655dd17 | |||
| 34ecf84835 | |||
| 4cf79c985d | |||
| 18e359c1a6 | |||
| dc777f43d9 | |||
| 8cd7ca9731 | |||
| 8f91c47178 | |||
| fdac954df5 | |||
| 70c98eb9f3 | |||
| aa72db079f | |||
| 024efd2e35 | |||
| da252bfa5e | |||
| c9ce68eab3 | |||
| 3af549a158 | |||
| 34627ff1c5 | |||
| 483ead4243 | |||
| 0c2b49af11 | |||
| 4324ea847c | |||
| df76ff3778 | |||
| 172bb09305 | |||
| aa0ba83d32 | |||
| fb934ef527 | |||
| a2b817bbc2 | |||
| ecd80408e2 | |||
| b78e2cb33c | |||
| ddd92777b4 | |||
| f0c52d2e81 | |||
| 23ac269339 | |||
| 07ab24638e | |||
| 8239d6f51d | |||
| 3adf336384 | |||
| 8e1810697f | |||
| 7c2105b613 | |||
| 2027defafb | |||
| ffe44155e2 | |||
| 2ea586ec6f | |||
| 7c2093a4c7 | |||
| 4f6fa2a15c | |||
| a6940c42ac | |||
| 6ed1cb60d6 | |||
| 2c9e58280b | |||
| f18b50cd4f | |||
| aa2af5d280 | |||
| dde69ba65f | |||
| f51b58c927 | |||
| 43f1ac0596 | |||
| 321e0de9f3 | |||
| ca77113e79 | |||
| 9c70225a9e | |||
| 2098c72a35 | |||
| 06e34fc303 | |||
| 7b56d56c0e | |||
| aa90104b18 | |||
| 98b285ab64 | |||
| cbd7e8ee7b | |||
| b76235d4fc | |||
| b9e1d77038 | |||
| 8f448d3842 | |||
| 89d7242d21 | |||
| 9aaa241523 | |||
| 02bd5c4b0b | |||
| 4003a39ef9 | |||
| a5fed4af70 | |||
| a9d8cbbc57 | |||
| 6c79ab37fa | |||
| 17762b71db | |||
| be2f142fd3 | |||
| fdcb2cf7ba | |||
| b42e3ad01f | |||
| 07bf7a44aa | |||
| 3a40dc1f8b | |||
| a2bfbd8368 | |||
| 25553904df | |||
| 954ef08975 | |||
| aea8b7873c | |||
| 6952bedbc3 | |||
| a7774a6bc3 | |||
| bf299e82bb | |||
| 915790e26e | |||
| e18a26a252 | |||
| 4d15b5c19d | |||
| 73ccefd720 | |||
| 11385b946d | |||
| e230fa1d43 | |||
| 3d30144ebb | |||
| 3365ca15d6 | |||
| c0debdfe39 | |||
| f7d55d48fe | |||
| f2510a9410 | |||
| f2a8a9878b | |||
| 39adc06921 | |||
| 64af642c40 | |||
| ef26ac732e | |||
| 8bbaaf4cef | |||
| de821b73c8 | |||
| a7d5fe3994 | |||
| 7deeefbcf4 | |||
| 3666bdf6fc | |||
| eaa7bb30db | |||
| d4619c5786 | |||
| 0f3852ab1e | |||
| fb5b1c5a6e | |||
| 7598e882b8 | |||
| cef8ac9fd9 | |||
| 45aa5df267 | |||
| e8c94aa103 | |||
| aa5b7e1276 | |||
| dd98d0c11d | |||
| 08971025bd | |||
| 00f6a823d6 | |||
| b4f4da26d6 | |||
| 1c9f7ac597 | |||
| 673139f5a9 | |||
| 4bf0cee034 | |||
| 00abbab370 | |||
| 3125a7a928 | |||
| f20c944c72 | |||
| 6d7dc6517b | |||
| 6fd84c6c8c | |||
| d37f31208c | |||
| c472b19e0d | |||
| 7b03bcde89 | |||
| 51cc45d178 | |||
| 03a7eb0fd4 | |||
| c0a779727e | |||
| 52d3f0bc19 | |||
| c17497e304 | |||
| 6bc4ecbc73 | |||
| 2246077589 | |||
| 91eb74773b | |||
| 5b8d2660aa | |||
| 60ad1c10fd | |||
| 36b0cc524e | |||
| bb33e70b3e | |||
| 9dc3d3ed82 | |||
| 5f2d7b2f5a | |||
| 02aeaa6a64 | |||
| 7696541430 | |||
| 6fe92e1725 | |||
| e512ceedec | |||
| d05a40389e | |||
| ea0494e8c2 | |||
| 614156f575 | |||
| 127680c988 | |||
| cdbd9bdba3 | |||
| 397abd51a5 | |||
| d311090ced | |||
| 1910151224 | |||
| 4a110d68c1 | |||
| cd27981734 | |||
| 505a3c6224 | |||
| 75a21ee162 | |||
| 9509d5e730 | |||
| 440cf968d5 | |||
| 3daa374a51 | |||
| 5d83d912fc | |||
| 695fd3ba1c | |||
| 75f68904f2 | |||
| b99badda9f | |||
| 219733c437 | |||
| 48d86cb7ce | |||
| 9991cc8c03 | |||
| 36a3b693d5 | |||
| dbd6be9520 | |||
| 42ef948fcc | |||
| 69f4ac3ed7 | |||
| 328e379ec2 | |||
| ad4fee9581 | |||
| 2af29de849 | |||
| 7d65d4b11a | |||
| 57ba4355f9 | |||
| 2eea44bc8c | |||
| cb982a1ad4 | |||
| 0aca0a0a5a | |||
| 0c1df859e2 | |||
| 7a153285c8 | |||
| c2d00ee819 | |||
| 3603787df8 | |||
| d58424d089 | |||
| fe2ca8c566 | |||
| 20d2ff7954 | |||
| b125c19d02 | |||
| 2f2d11a5f6 | |||
| de4897fdef | |||
| f9952d0f94 | |||
| 5483a8d36b | |||
| 80ac89f16b | |||
| fcf9830aa6 | |||
| 0c847ce1d8 | |||
| f1905b524b | |||
| d7b435a446 | |||
| f742a0ef10 | |||
| 887d963d8d | |||
| 3547ad9c57 | |||
| 0d2248352b | |||
| bc4c39b7aa | |||
| 012a724069 | |||
| 8d89026d19 | |||
| 4e6e3ce5f0 | |||
| 3d7eced836 | |||
| 2e50a2ede4 | |||
| 78d7d40c0a | |||
| 7130b1be34 | |||
| a5917c389f | |||
| dac47c3214 | |||
| be3a84dcf7 | |||
| 35dff37820 | |||
| 22a2079c5f | |||
| fe2bac216f | |||
| d89e94bb8e | |||
| a95aba3ff4 | |||
| a93f00d0af | |||
| a1ebcaea23 | |||
| ab10854dde | |||
| e8aa709d4e | |||
| 3f25120e04 | |||
| b776b7b63f | |||
| 44d0a0ca23 | |||
| ecd71dd92a | |||
| ec645c0202 | |||
| 63134aa586 | |||
| 8489127f71 | |||
| e024463770 | |||
| 7e11af5553 | |||
| 168dc1ddb8 | |||
| 8918b7fae0 | |||
| d20d1af154 | |||
| 925ffa09e2 | |||
| 25fa85c218 | |||
| 6e20c656e7 | |||
| a158529c70 | |||
| 87b5ae8f75 | |||
| 1c163421c7 | |||
| 295dbbbb86 | |||
| 10ff332f4d | |||
| d5e7ccac2d | |||
| f57179911f | |||
| 925f3614c7 | |||
| ce0f8251d3 | |||
| 6b21323e8c | |||
| b3f5d84a51 | |||
| cc2867e292 | |||
| 92b0f4e654 | |||
| cebc04b852 | |||
| dbfdffd0c5 | |||
| b8d2cba3ae | |||
| b56d62442d | |||
| 50fec65617 | |||
| 42466cf648 | |||
| b4bb20bea7 | |||
| 2ce37e34c4 | |||
| c8b8462d31 | |||
| d21d0caa68 | |||
| 63bf1797c0 | |||
| f8ba0c59a6 | |||
| 0553db3a69 | |||
| a7ef6ea3be | |||
| d72b9b47ed | |||
| 7e7186f068 | |||
| 2d61e8bbd2 | |||
| c4c350f1aa | |||
| 2f382d21dc | |||
| a968a3a035 | |||
| deb875337d | |||
| 1b0791364b | |||
| d939aa7247 |
807
Common/3dParty/harfbuzz/test/main.cpp
Normal file
807
Common/3dParty/harfbuzz/test/main.cpp
Normal file
@ -0,0 +1,807 @@
|
||||
// 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 <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_GLYPH_H
|
||||
#include FT_OUTLINE_H
|
||||
|
||||
#include <hb-ft.h>
|
||||
#include <hb-ot.h>
|
||||
#include <hb.h>
|
||||
|
||||
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/arial.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] = {
|
||||
"hello",
|
||||
"لا لآ لأ لا",
|
||||
"懶惰的姜貓"
|
||||
};
|
||||
|
||||
const hb_direction_t text_directions[NUM_EXAMPLES] = {
|
||||
HB_DIRECTION_LTR,
|
||||
HB_DIRECTION_RTL,
|
||||
HB_DIRECTION_TTB,
|
||||
};
|
||||
|
||||
const int text_skip[NUM_EXAMPLES] = {
|
||||
1,
|
||||
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<OpenTypeFontFile>(blob);
|
||||
const OpenTypeFontFile *sanitized = font_blob->as<OpenTypeFontFile>();
|
||||
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<const GSUBGPOS *>(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<const GDEF *>(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
|
||||
|
||||
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_CHARACTERS);
|
||||
|
||||
#if 0
|
||||
#define userfeatures_count 4
|
||||
hb_feature_t userfeatures[userfeatures_count];
|
||||
hb_tag_t tags[] = {
|
||||
HB_TAG('l','i','g','a'),
|
||||
HB_TAG('c','l','i','g'),
|
||||
HB_TAG('d','l','i','g'),
|
||||
HB_TAG('h','l','i','g'),
|
||||
};
|
||||
for (int f = 0; f < userfeatures_count; f++)
|
||||
{
|
||||
userfeatures[f].tag = tags[f];
|
||||
userfeatures[f].value = 1;
|
||||
userfeatures[f].start = HB_FEATURE_GLOBAL_START;
|
||||
userfeatures[f].end = HB_FEATURE_GLOBAL_END;
|
||||
}
|
||||
#else
|
||||
#define userfeatures_count 0
|
||||
hb_feature_t *userfeatures = NULL;
|
||||
#endif
|
||||
|
||||
/* 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, 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;
|
||||
}
|
||||
19
Common/3dParty/harfbuzz/test/test.pro
Normal file
19
Common/3dParty/harfbuzz/test/test.pro
Normal file
@ -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
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ namespace NSCSS
|
||||
m_arParentsStyles(oStyle.m_arParentsStyles), m_sId(oStyle.m_sId),
|
||||
m_nDpi(oStyle.m_nDpi), m_UnitMeasure(oStyle.m_UnitMeasure), m_dCoreFontSize(oStyle.m_dCoreFontSize),
|
||||
m_oFont(oStyle.m_oFont), m_oMargin(oStyle.m_oMargin), m_oPadding(oStyle.m_oPadding), m_oBackground(oStyle.m_oBackground),
|
||||
m_oText(oStyle.m_oText), m_oBorder(oStyle.m_oBorder), m_oDisplay(oStyle.m_oDisplay){}
|
||||
m_oText(oStyle.m_oText), m_oBorder(oStyle.m_oBorder), m_oDisplay(oStyle.m_oDisplay), m_oTransform(oStyle.m_oTransform){}
|
||||
|
||||
CCompiledStyle::~CCompiledStyle()
|
||||
{
|
||||
@ -44,6 +44,7 @@ namespace NSCSS
|
||||
m_oPadding += oElement.m_oPadding;
|
||||
m_oText += oElement.m_oText;
|
||||
m_oDisplay += oElement.m_oDisplay;
|
||||
m_oTransform += oElement.m_oTransform;
|
||||
|
||||
if (!oElement.m_sId.empty())
|
||||
m_sId += L'+' + oElement.m_sId;
|
||||
@ -66,6 +67,7 @@ namespace NSCSS
|
||||
m_oPadding = oElement.m_oPadding;
|
||||
m_oText = oElement.m_oText;
|
||||
m_oDisplay = oElement.m_oDisplay;
|
||||
m_oTransform = oElement.m_oTransform;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -78,7 +80,8 @@ namespace NSCSS
|
||||
m_oMargin == oStyle.m_oMargin &&
|
||||
m_oPadding == oStyle.m_oPadding &&
|
||||
m_oText == oStyle.m_oText &&
|
||||
m_oDisplay == oStyle.m_oDisplay;
|
||||
m_oDisplay == oStyle.m_oDisplay &&
|
||||
m_oTransform == oStyle.m_oTransform;
|
||||
}
|
||||
|
||||
void CCompiledStyle::StyleEquation(CCompiledStyle &oFirstStyle, CCompiledStyle &oSecondStyle)
|
||||
@ -90,6 +93,7 @@ namespace NSCSS
|
||||
NSProperties::CText ::Equation(oFirstStyle.m_oText, oSecondStyle.m_oText);
|
||||
NSProperties::CBorder ::Equation(oFirstStyle.m_oBorder, oSecondStyle.m_oBorder);
|
||||
NSProperties::CDisplay ::Equation(oFirstStyle.m_oDisplay, oSecondStyle.m_oDisplay);
|
||||
NSProperties::CTransform ::Equation(oFirstStyle.m_oTransform, oSecondStyle.m_oTransform);
|
||||
}
|
||||
|
||||
void CCompiledStyle::SetDpi(const unsigned short &uiDpi)
|
||||
@ -431,6 +435,12 @@ namespace NSCSS
|
||||
m_oDisplay.SetVAlign(pPropertie.second, unLevel, bHardMode);
|
||||
break;
|
||||
}
|
||||
//TRANSFORM
|
||||
CASE(L"transform"):
|
||||
{
|
||||
m_oTransform.SetMatrix(pPropertie.second, unLevel, bHardMode);
|
||||
break;
|
||||
}
|
||||
default: AddOtherStyle(pPropertie, unLevel, bHardMode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,11 +31,12 @@ namespace NSCSS
|
||||
NSProperties::CText m_oText;
|
||||
NSProperties::CBorder m_oBorder;
|
||||
NSProperties::CDisplay m_oDisplay;
|
||||
NSProperties::CTransform m_oTransform;
|
||||
|
||||
CCompiledStyle();
|
||||
CCompiledStyle(const CCompiledStyle& oStyle);
|
||||
|
||||
~CCompiledStyle();
|
||||
virtual ~CCompiledStyle();
|
||||
|
||||
void SetDpi(const unsigned short& uiDpi);
|
||||
void SetUnitMeasure(const UnitMeasure& enUnitMeasure);
|
||||
|
||||
@ -13,14 +13,14 @@ namespace NSCSS
|
||||
delete m_pInternal;
|
||||
}
|
||||
|
||||
CCompiledStyle CCssCalculator::GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings, const UnitMeasure& unitMeasure) const
|
||||
CCompiledStyle CCssCalculator::GetCompiledStyle(const std::vector<CNode> &arSelectors) const
|
||||
{
|
||||
return m_pInternal->GetCompiledStyle(arSelectors, bIsSettings, unitMeasure);
|
||||
return m_pInternal->GetCompiledStyle(arSelectors);
|
||||
}
|
||||
|
||||
bool CCssCalculator::GetCompiledStyle(CCompiledStyle &oStyle, const std::vector<CNode> &arSelectors, const bool &bIsSettings, const UnitMeasure &unitMeasure) const
|
||||
bool CCssCalculator::GetCompiledStyle(CCompiledStyle &oStyle, const std::vector<CNode> &arSelectors) const
|
||||
{
|
||||
return m_pInternal->GetCompiledStyle(oStyle, arSelectors, bIsSettings, unitMeasure);
|
||||
return m_pInternal->GetCompiledStyle(oStyle, arSelectors);
|
||||
}
|
||||
|
||||
std::wstring CCssCalculator::CalculateStyleId(const CNode& oNode)
|
||||
@ -48,26 +48,11 @@ namespace NSCSS
|
||||
m_pInternal->AddStylesFromFile(wsFileName);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetUnitMeasure(const UnitMeasure& nType)
|
||||
{
|
||||
m_pInternal->SetUnitMeasure(nType);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetDpi(const unsigned short int& nValue)
|
||||
{
|
||||
m_pInternal->SetDpi(nValue);
|
||||
}
|
||||
|
||||
void CCssCalculator::SetBodyTree(const CTree &oTree)
|
||||
{
|
||||
m_pInternal->SetBodyTree(oTree);
|
||||
}
|
||||
|
||||
UnitMeasure CCssCalculator::GetUnitMeasure() const
|
||||
{
|
||||
return m_pInternal->GetUnitMeasure();
|
||||
}
|
||||
|
||||
std::wstring CCssCalculator::GetEncoding() const
|
||||
{
|
||||
return m_pInternal->GetEncoding();
|
||||
@ -78,6 +63,26 @@ namespace NSCSS
|
||||
return m_pInternal->GetDpi();
|
||||
}
|
||||
|
||||
void CCssCalculator::ClearPageData()
|
||||
{
|
||||
m_pInternal->ClearPageData();
|
||||
}
|
||||
|
||||
void CCssCalculator::ClearEmbeddedStyles()
|
||||
{
|
||||
m_pInternal->ClearEmbeddedStyles();
|
||||
}
|
||||
|
||||
void CCssCalculator::ClearAllowedStyleFiles()
|
||||
{
|
||||
m_pInternal->ClearAllowedStyleFiles();
|
||||
}
|
||||
|
||||
void CCssCalculator::ClearStylesFromFile(const std::wstring& wsFilePath)
|
||||
{
|
||||
m_pInternal->ClearStylesFromFile(wsFilePath);
|
||||
}
|
||||
|
||||
void CCssCalculator::Clear()
|
||||
{
|
||||
m_pInternal->Clear();
|
||||
|
||||
@ -19,8 +19,8 @@ namespace NSCSS
|
||||
CCssCalculator();
|
||||
~CCssCalculator();
|
||||
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point) const;
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point) const;
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors) const;
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors) const;
|
||||
|
||||
std::wstring CalculateStyleId(const CNode& oNode);
|
||||
bool CalculatePageStyle(NSProperties::CPage& oPageData, const std::vector<CNode> &arSelectors);
|
||||
@ -30,14 +30,15 @@ namespace NSCSS
|
||||
void AddStyles (const std::wstring& wsStyle);
|
||||
void AddStylesFromFile(const std::wstring& wsFileName);
|
||||
|
||||
void SetUnitMeasure(const UnitMeasure& nType);
|
||||
void SetDpi(const unsigned short int& nValue);
|
||||
void SetBodyTree(const CTree &oTree);
|
||||
|
||||
UnitMeasure GetUnitMeasure() const;
|
||||
std::wstring GetEncoding() const;
|
||||
unsigned short int GetDpi() const;
|
||||
|
||||
void ClearPageData();
|
||||
void ClearEmbeddedStyles();
|
||||
void ClearAllowedStyleFiles();
|
||||
void ClearStylesFromFile(const std::wstring& wsFilePath);
|
||||
void Clear();
|
||||
};
|
||||
}
|
||||
|
||||
@ -5,12 +5,9 @@
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
#include "../../katana-parser/src/selector.h"
|
||||
#include "../../../../../UnicodeConverter/UnicodeConverter.h"
|
||||
#include "ConstValues.h"
|
||||
#include "../../../../../DesktopEditor/common/File.h"
|
||||
#include "StaticFunctions.h"
|
||||
|
||||
@ -41,61 +38,120 @@ bool operator<(const std::vector<NSCSS::CNode> &arLeftSelectors, const std::vect
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
CCssCalculator_Private::CCssCalculator_Private() : m_nDpi(96), m_nCountNodes(0), m_UnitMeasure(Point), m_mStatictics(NULL), m_sEncoding(L"UTF-8"){}
|
||||
CStyleStorage::CStyleStorage()
|
||||
{}
|
||||
|
||||
CCssCalculator_Private::~CCssCalculator_Private()
|
||||
CStyleStorage::~CStyleStorage()
|
||||
{
|
||||
m_arFiles.clear();
|
||||
|
||||
for (std::map<std::wstring, CElement*>::iterator oIter = m_mData.begin(); oIter != m_mData.end(); ++oIter)
|
||||
if (oIter->second != NULL)
|
||||
delete oIter->second;
|
||||
|
||||
m_mData.clear();
|
||||
|
||||
if (NULL != m_mStatictics)
|
||||
delete m_mStatictics;
|
||||
Clear();
|
||||
}
|
||||
|
||||
inline void CCssCalculator_Private::GetOutputData(KatanaOutput *oOutput)
|
||||
void CStyleStorage::Clear()
|
||||
{
|
||||
if ( NULL == oOutput )
|
||||
return;
|
||||
for (TStyleFileData* pStyleFileData : m_arStyleFiles)
|
||||
{
|
||||
if (nullptr == pStyleFileData)
|
||||
continue;
|
||||
|
||||
switch (oOutput->mode) {
|
||||
case KatanaParserModeStylesheet:
|
||||
GetStylesheet(oOutput->stylesheet);
|
||||
break;
|
||||
case KatanaParserModeRule:
|
||||
GetRule(oOutput->rule);
|
||||
break;
|
||||
case KatanaParserModeKeyframeRule:
|
||||
case KatanaParserModeKeyframeKeyList:
|
||||
case KatanaParserModeMediaList:
|
||||
case KatanaParserModeValue:
|
||||
case KatanaParserModeSelector:
|
||||
case KatanaParserModeDeclarationList:
|
||||
break;
|
||||
for (std::map<std::wstring, CElement*>::iterator oIter = pStyleFileData->m_mStyleData.begin(); oIter != pStyleFileData->m_mStyleData.end(); ++oIter)
|
||||
if (oIter->second != nullptr)
|
||||
delete oIter->second;
|
||||
|
||||
delete pStyleFileData;
|
||||
}
|
||||
|
||||
m_arStyleFiles.clear();
|
||||
m_arEmptyStyleFiles.clear();
|
||||
|
||||
ClearEmbeddedStyles();
|
||||
ClearAllowedStyleFiles();
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
ClearPageData();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CStyleStorage::AddStyles(const std::string& sStyle)
|
||||
{
|
||||
if (sStyle.empty())
|
||||
return;
|
||||
|
||||
KatanaOutput *output = katana_parse(sStyle.c_str(), sStyle.length(), KatanaParserModeStylesheet);
|
||||
this->GetOutputData(output, m_mEmbeddedStyleData);
|
||||
katana_destroy_output(output);
|
||||
}
|
||||
|
||||
void CStyleStorage::AddStyles(const std::wstring& wsStyle)
|
||||
{
|
||||
if (wsStyle.empty())
|
||||
return;
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
std::wregex oRegex(L"@page\\s*([^{]*)(\\{[^}]*\\})");
|
||||
std::wsmatch oMatch;
|
||||
std::wstring::const_iterator oSearchStart(wsStyle.cbegin());
|
||||
|
||||
while (std::regex_search(oSearchStart, wsStyle.cend(), oMatch, oRegex))
|
||||
{
|
||||
AddPageData(oMatch[1].str(), oMatch[2].str());
|
||||
oSearchStart = oMatch.suffix().first;
|
||||
}
|
||||
#endif
|
||||
|
||||
AddStyles(U_TO_UTF8(wsStyle));
|
||||
}
|
||||
|
||||
void CStyleStorage::AddStylesFromFile(const std::wstring& wsFileName)
|
||||
{
|
||||
std::set<std::wstring>::const_iterator itEmptyFileFound = m_arEmptyStyleFiles.find(wsFileName);
|
||||
|
||||
if (m_arEmptyStyleFiles.cend() != itEmptyFileFound)
|
||||
return;
|
||||
|
||||
std::vector<TStyleFileData*>::const_iterator itFound = std::find_if(m_arStyleFiles.cbegin(), m_arStyleFiles.cend(),
|
||||
[wsFileName](const TStyleFileData* pStyleFileData)
|
||||
{ return wsFileName == pStyleFileData->m_wsStyleFilepath; });
|
||||
|
||||
m_arAllowedStyleFiles.insert(wsFileName);
|
||||
|
||||
if (m_arStyleFiles.cend() != itFound)
|
||||
return;
|
||||
|
||||
TStyleFileData *pStyleFileData = new TStyleFileData();
|
||||
|
||||
pStyleFileData->m_wsStyleFilepath = wsFileName;
|
||||
|
||||
AddStyles(NS_STATIC_FUNCTIONS::GetContentAsUTF8(wsFileName), pStyleFileData->m_mStyleData);
|
||||
|
||||
if (!pStyleFileData->m_mStyleData.empty())
|
||||
m_arStyleFiles.push_back(pStyleFileData);
|
||||
else
|
||||
{
|
||||
m_arEmptyStyleFiles.insert(wsFileName);
|
||||
delete pStyleFileData;
|
||||
}
|
||||
}
|
||||
|
||||
void CStyleStorage::ClearStylesFromFile(const std::wstring& wsFileName)
|
||||
{
|
||||
std::vector<TStyleFileData*>::const_iterator itFound = std::find_if(m_arStyleFiles.cbegin(), m_arStyleFiles.cend(),
|
||||
[wsFileName](const TStyleFileData* pStyleFileData)
|
||||
{ return wsFileName == pStyleFileData->m_wsStyleFilepath; });
|
||||
|
||||
if (m_arStyleFiles.cend() != itFound)
|
||||
{
|
||||
m_arStyleFiles.erase(itFound);
|
||||
delete *itFound;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
std::map<std::wstring, std::wstring> CCssCalculator_Private::GetPageData(const std::wstring &wsPageName)
|
||||
void CStyleStorage::AddPageData(const std::wstring& wsPageName, const std::wstring& wsStyles)
|
||||
{
|
||||
if (m_arPageDatas.empty())
|
||||
return {};
|
||||
|
||||
for (const TPageData& oPageData : m_arPageDatas)
|
||||
{
|
||||
if (std::find(oPageData.m_wsNames.begin(), oPageData.m_wsNames.end(), wsPageName) != oPageData.m_wsNames.end())
|
||||
return oPageData.m_mData;
|
||||
}
|
||||
|
||||
return {};
|
||||
m_arPageDatas.push_back({NS_STATIC_FUNCTIONS::GetWordsW(wsPageName), NS_STATIC_FUNCTIONS::GetRules(wsStyles)});
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::SetPageData(NSProperties::CPage &oPage, const std::map<std::wstring, std::wstring> &mData, unsigned int unLevel, bool bHardMode)
|
||||
|
||||
void CStyleStorage::SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode)
|
||||
{
|
||||
for (const std::pair<std::wstring, std::wstring> &oData : mData)
|
||||
{
|
||||
@ -110,162 +166,84 @@ namespace NSCSS
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CCssCalculator_Private::CalculateAllNodes(const std::vector<CNode> &arSelectors)
|
||||
std::map<std::wstring, std::wstring> CStyleStorage::GetPageData(const std::wstring& wsPageName)
|
||||
{
|
||||
std::vector<std::wstring> arNodes;
|
||||
|
||||
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
|
||||
{
|
||||
if (!oNode->m_wsName.empty())
|
||||
arNodes.push_back(oNode->m_wsName);
|
||||
|
||||
if (!oNode->m_wsClass.empty())
|
||||
{
|
||||
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
|
||||
{
|
||||
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, false, L" ");
|
||||
|
||||
arNodes.push_back(std::accumulate(arClasses.begin(), arClasses.end(), std::wstring(),
|
||||
[](std::wstring sRes, const std::wstring& sClass)
|
||||
{return sRes += L'.' + sClass + L' ';}));
|
||||
}
|
||||
else
|
||||
arNodes.push_back(L'.' + oNode->m_wsClass);
|
||||
}
|
||||
|
||||
if (!oNode->m_wsId.empty())
|
||||
arNodes.push_back(L'#' + oNode->m_wsId);
|
||||
}
|
||||
|
||||
return arNodes;
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::FindPrevAndKindElements(const CElement *pElement, const std::vector<std::wstring> &arNextNodes, std::vector<CElement*>& arFindedElements, const std::wstring &wsName, const std::vector<std::wstring> &arClasses)
|
||||
{
|
||||
if (arNextNodes.empty())
|
||||
return;
|
||||
|
||||
const std::vector<CElement*> arTempPrev = pElement->GetPrevElements(arNextNodes.crbegin() + 1, arNextNodes.crend());
|
||||
const std::vector<CElement*> arTempKins = pElement->GetNextOfKin(wsName, arClasses);
|
||||
|
||||
if (!arTempPrev.empty())
|
||||
arFindedElements.insert(arFindedElements.end(), arTempPrev.begin(), arTempPrev.end());
|
||||
|
||||
if (!arTempKins.empty())
|
||||
arFindedElements.insert(arFindedElements.end(), arTempKins.begin(), arTempKins.end());
|
||||
}
|
||||
|
||||
std::vector<CElement*> CCssCalculator_Private::FindElements(std::vector<std::wstring> &arNodes, std::vector<std::wstring> &arNextNodes, bool bIsSettings)
|
||||
{
|
||||
if (arNodes.empty())
|
||||
if (m_arPageDatas.empty())
|
||||
return {};
|
||||
|
||||
std::vector<CElement*> arFindedElements;
|
||||
|
||||
std::wstring wsName, wsId;
|
||||
std::vector<std::wstring> arClasses;
|
||||
|
||||
if (!arNodes.empty() && arNodes.back()[0] == L'#')
|
||||
for (const TPageData& oPageData : m_arPageDatas)
|
||||
{
|
||||
wsId = arNodes.back();
|
||||
arNodes.pop_back();
|
||||
arNextNodes.push_back(wsId);
|
||||
if (std::find(oPageData.m_wsNames.begin(), oPageData.m_wsNames.end(), wsPageName) != oPageData.m_wsNames.end())
|
||||
return oPageData.m_mData;
|
||||
}
|
||||
|
||||
if (!arNodes.empty() && arNodes.back()[0] == L'.')
|
||||
{
|
||||
arClasses = NS_STATIC_FUNCTIONS::GetWordsW(arNodes.back(), false, L" ");
|
||||
arNextNodes.push_back(arNodes.back());
|
||||
arNodes.pop_back();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!arNodes.empty())
|
||||
{
|
||||
wsName = arNodes.back();
|
||||
arNodes.pop_back();
|
||||
arNextNodes.push_back(wsName);
|
||||
}
|
||||
|
||||
const std::map<std::wstring, CElement*>::const_iterator oFindName = m_mData.find(wsName);
|
||||
std::map<std::wstring, CElement*>::const_iterator oFindId;
|
||||
|
||||
if (!wsId.empty())
|
||||
{
|
||||
oFindId = m_mData.find(wsId);
|
||||
|
||||
if (oFindId != m_mData.end() && NULL != m_mStatictics)
|
||||
{
|
||||
std::map<StatistickElement, unsigned int>::const_iterator oFindCountId = m_mStatictics->find(StatistickElement{StatistickElement::IsId, wsId});
|
||||
|
||||
if ((m_mStatictics->end() != oFindCountId) &&
|
||||
(((bIsSettings && oFindCountId->second < MaxNumberRepetitions) ||
|
||||
(!bIsSettings && oFindCountId->second >= MaxNumberRepetitions))))
|
||||
{
|
||||
if (!oFindId->second->Empty())
|
||||
arFindedElements.push_back(oFindId->second);
|
||||
}
|
||||
|
||||
FindPrevAndKindElements(oFindId->second, arNextNodes, arFindedElements, wsName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!arClasses.empty())
|
||||
{
|
||||
if (!bIsSettings)
|
||||
{
|
||||
for (std::vector<std::wstring>::const_reverse_iterator iClass = arClasses.rbegin(); iClass != arClasses.rend(); ++iClass)
|
||||
{
|
||||
const std::map<std::wstring, CElement*>::const_iterator oFindClass = m_mData.find(*iClass);
|
||||
if (oFindClass != m_mData.end())
|
||||
{
|
||||
if (!oFindClass->second->Empty())
|
||||
arFindedElements.push_back(oFindClass->second);
|
||||
|
||||
FindPrevAndKindElements(oFindClass->second, arNextNodes, arFindedElements, wsName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (oFindName != m_mData.end())
|
||||
{
|
||||
if (!bIsSettings)
|
||||
{
|
||||
if (!oFindName->second->Empty())
|
||||
arFindedElements.push_back(oFindName->second);
|
||||
|
||||
FindPrevAndKindElements(oFindName->second, arNextNodes, arFindedElements, wsName, arClasses);
|
||||
}
|
||||
}
|
||||
|
||||
if (arFindedElements.size() > 1)
|
||||
{
|
||||
std::sort(arFindedElements.rbegin(), arFindedElements.rend(),
|
||||
[](CElement* oFirstElement, CElement* oSecondElement)
|
||||
{
|
||||
return oFirstElement->GetWeight() > oSecondElement->GetWeight();
|
||||
});
|
||||
}
|
||||
|
||||
return arFindedElements;
|
||||
void CStyleStorage::ClearPageData()
|
||||
{
|
||||
m_arPageDatas.clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
void CCssCalculator_Private::AddPageData(const std::wstring &wsPageNames, const std::wstring &wsStyles)
|
||||
const CElement* CStyleStorage::FindElement(const std::wstring& wsSelector)
|
||||
{
|
||||
m_arPageDatas.push_back({NS_STATIC_FUNCTIONS::GetWordsW(wsPageNames), NS_STATIC_FUNCTIONS::GetRules(wsStyles)});
|
||||
if (wsSelector.empty())
|
||||
return nullptr;
|
||||
|
||||
const CElement* pFoundElement = FindSelectorFromStyleData(wsSelector, m_mEmbeddedStyleData);
|
||||
|
||||
if (nullptr != pFoundElement)
|
||||
return pFoundElement;
|
||||
|
||||
for (std::vector<TStyleFileData*>::const_reverse_iterator itIter = m_arStyleFiles.crbegin(); itIter < m_arStyleFiles.crend(); ++itIter)
|
||||
{
|
||||
if (m_arAllowedStyleFiles.cend() == std::find(m_arAllowedStyleFiles.cbegin(), m_arAllowedStyleFiles.cend(), (*itIter)->m_wsStyleFilepath))
|
||||
continue;
|
||||
|
||||
pFoundElement = FindSelectorFromStyleData(wsSelector, (*itIter)->m_mStyleData);
|
||||
|
||||
if (nullptr != pFoundElement)
|
||||
return pFoundElement;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline void CCssCalculator_Private::GetStylesheet(const KatanaStylesheet *oStylesheet)
|
||||
|
||||
void CStyleStorage::AddStyles(const std::string& sStyle, std::map<std::wstring, CElement*>& mStyleData)
|
||||
{
|
||||
if (sStyle.empty())
|
||||
return;
|
||||
|
||||
KatanaOutput *output = katana_parse(sStyle.c_str(), sStyle.length(), KatanaParserModeStylesheet);
|
||||
this->GetOutputData(output, mStyleData);
|
||||
katana_destroy_output(output);
|
||||
}
|
||||
|
||||
void CStyleStorage::ClearEmbeddedStyles()
|
||||
{
|
||||
for (std::map<std::wstring, CElement*>::iterator oIter = m_mEmbeddedStyleData.begin(); oIter != m_mEmbeddedStyleData.end(); ++oIter)
|
||||
if (oIter->second != nullptr)
|
||||
delete oIter->second;
|
||||
|
||||
m_mEmbeddedStyleData.clear();
|
||||
}
|
||||
|
||||
void CStyleStorage::ClearAllowedStyleFiles()
|
||||
{
|
||||
m_arAllowedStyleFiles.clear();
|
||||
}
|
||||
|
||||
void CStyleStorage::GetStylesheet(const KatanaStylesheet* oStylesheet, std::map<std::wstring, CElement*>& mStyleData)
|
||||
{
|
||||
for (size_t i = 0; i < oStylesheet->imports.length; ++i)
|
||||
GetRule((KatanaRule*)oStylesheet->imports.data[i]);
|
||||
GetRule((KatanaRule*)oStylesheet->imports.data[i], mStyleData);
|
||||
|
||||
for (size_t i = 0; i < oStylesheet->rules.length; ++i)
|
||||
GetRule((KatanaRule*)oStylesheet->rules.data[i]);
|
||||
GetRule((KatanaRule*)oStylesheet->rules.data[i], mStyleData);
|
||||
}
|
||||
|
||||
inline void CCssCalculator_Private::GetRule(const KatanaRule *oRule)
|
||||
void CStyleStorage::GetRule(const KatanaRule* oRule, std::map<std::wstring, CElement*>& mStyleData)
|
||||
{
|
||||
if ( NULL == oRule )
|
||||
return;
|
||||
@ -273,7 +251,7 @@ namespace NSCSS
|
||||
switch (oRule->type) {
|
||||
case KatanaRuleStyle:
|
||||
{
|
||||
GetStyleRule((KatanaStyleRule*)oRule);
|
||||
GetStyleRule((KatanaStyleRule*)oRule, mStyleData);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -281,7 +259,7 @@ namespace NSCSS
|
||||
}
|
||||
}
|
||||
|
||||
inline void CCssCalculator_Private::GetStyleRule(const KatanaStyleRule *oRule)
|
||||
void CStyleStorage::GetStyleRule(const KatanaStyleRule* oRule, std::map<std::wstring, CElement*>& mStyleData)
|
||||
{
|
||||
if (oRule->declarations->length == 0)
|
||||
return;
|
||||
@ -297,7 +275,7 @@ namespace NSCSS
|
||||
|
||||
for (std::vector<std::wstring>::reverse_iterator oWord = arWords.rbegin(); oWord != arWords.rend(); ++oWord)
|
||||
{
|
||||
const size_t posPoint = oWord->find(L'.');
|
||||
const size_t posPoint = oWord->find(L'.');
|
||||
const size_t posLattice = oWord->find(L'#');
|
||||
|
||||
const std::wstring sName = (posPoint != std::wstring::npos) ? oWord->substr(0, posPoint) : (posLattice != std::wstring::npos) ? oWord->substr(0, posLattice) : *oWord;
|
||||
@ -313,8 +291,8 @@ namespace NSCSS
|
||||
{
|
||||
if (NULL == oFirstElement && bCreateFirst)
|
||||
{
|
||||
const std::map<std::wstring, CElement*>::const_iterator& oFindId = m_mData.find(sId);
|
||||
if (oFindId != m_mData.end())
|
||||
const std::map<std::wstring, CElement*>::const_iterator& oFindId = mStyleData.find(sId);
|
||||
if (oFindId != mStyleData.end())
|
||||
{
|
||||
oIdElement = oFindId->second;
|
||||
bCreateFirst = false;
|
||||
@ -342,8 +320,8 @@ namespace NSCSS
|
||||
{
|
||||
if (NULL == oFirstElement && bCreateFirst)
|
||||
{
|
||||
const std::map<std::wstring, CElement*>::const_iterator& oFindClass = m_mData.find(sClass);
|
||||
if (oFindClass != m_mData.end())
|
||||
const std::map<std::wstring, CElement*>::const_iterator& oFindClass = mStyleData.find(sClass);
|
||||
if (oFindClass != mStyleData.end())
|
||||
{
|
||||
oClassElement = oFindClass->second;
|
||||
bCreateFirst = false;
|
||||
@ -375,8 +353,8 @@ namespace NSCSS
|
||||
{
|
||||
if (NULL == oFirstElement && bCreateFirst)
|
||||
{
|
||||
const std::map<std::wstring, CElement*>::const_iterator& oFindName = m_mData.find(sName);
|
||||
if (oFindName != m_mData.end())
|
||||
const std::map<std::wstring, CElement*>::const_iterator& oFindName = mStyleData.find(sName);
|
||||
if (oFindName != mStyleData.end())
|
||||
{
|
||||
oNameElement = oFindName->second;
|
||||
bCreateFirst = false;
|
||||
@ -408,11 +386,16 @@ namespace NSCSS
|
||||
oLastElement->AddProperties(mStyle);
|
||||
|
||||
if (NULL != oFirstElement)
|
||||
m_mData[oFirstElement->GetSelector()] = oFirstElement;
|
||||
mStyleData[oFirstElement->GetSelector()] = oFirstElement;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<std::wstring> CCssCalculator_Private::GetSelectorList(const KatanaArray* oSelectors) const
|
||||
std::wstring CStyleStorage::GetValueList(const KatanaArray* oValues)
|
||||
{
|
||||
return StringifyValueList(oValues);
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CStyleStorage::GetSelectorList(const KatanaArray* oSelectors) const
|
||||
{
|
||||
if (oSelectors->length == 0)
|
||||
return std::vector<std::wstring>();
|
||||
@ -425,7 +408,7 @@ namespace NSCSS
|
||||
return arSelectors;
|
||||
}
|
||||
|
||||
inline std::wstring CCssCalculator_Private::GetSelector(const KatanaSelector *oSelector) const
|
||||
std::wstring CStyleStorage::GetSelector(const KatanaSelector* oSelector) const
|
||||
{
|
||||
KatanaParser oParser;
|
||||
oParser.options = &kKatanaDefaultOptions;
|
||||
@ -444,7 +427,7 @@ namespace NSCSS
|
||||
return wsText;
|
||||
}
|
||||
|
||||
inline std::map<std::wstring, std::wstring> CCssCalculator_Private::GetDeclarationList(const KatanaArray* oDeclarations) const
|
||||
std::map<std::wstring, std::wstring> CStyleStorage::GetDeclarationList(const KatanaArray* oDeclarations) const
|
||||
{
|
||||
if(oDeclarations->length == 0)
|
||||
return std::map<std::wstring, std::wstring>();
|
||||
@ -457,7 +440,7 @@ namespace NSCSS
|
||||
return arDeclarations;
|
||||
}
|
||||
|
||||
inline std::pair<std::wstring, std::wstring> CCssCalculator_Private::GetDeclaration(const KatanaDeclaration* oDecl) const
|
||||
std::pair<std::wstring, std::wstring> CStyleStorage::GetDeclaration(const KatanaDeclaration* oDecl) const
|
||||
{
|
||||
std::wstring sValueList = StringifyValueList(oDecl->values);
|
||||
|
||||
@ -467,52 +450,213 @@ namespace NSCSS
|
||||
return std::make_pair(UTF8_TO_U(std::string(oDecl->property)), sValueList);
|
||||
}
|
||||
|
||||
inline std::wstring CCssCalculator_Private::GetValueList(const KatanaArray *oValues)
|
||||
void CStyleStorage::GetOutputData(KatanaOutput* oOutput, std::map<std::wstring, CElement*>& mStyleData)
|
||||
{
|
||||
return StringifyValueList(oValues);
|
||||
if ( NULL == oOutput )
|
||||
return;
|
||||
|
||||
switch (oOutput->mode) {
|
||||
case KatanaParserModeStylesheet:
|
||||
GetStylesheet(oOutput->stylesheet, mStyleData);
|
||||
break;
|
||||
case KatanaParserModeRule:
|
||||
GetRule(oOutput->rule, mStyleData);
|
||||
break;
|
||||
case KatanaParserModeKeyframeRule:
|
||||
case KatanaParserModeKeyframeKeyList:
|
||||
case KatanaParserModeMediaList:
|
||||
case KatanaParserModeValue:
|
||||
case KatanaParserModeSelector:
|
||||
case KatanaParserModeDeclarationList:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const CElement* CStyleStorage::FindSelectorFromStyleData(const std::wstring& wsSelector, const std::map<std::wstring, CElement*>& mStyleData)
|
||||
{
|
||||
std::map<std::wstring, CElement*>::const_iterator itFound = mStyleData.find(wsSelector);
|
||||
|
||||
if (mStyleData.cend() != itFound)
|
||||
return itFound->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CCssCalculator_Private::CCssCalculator_Private() : m_nDpi(96), m_nCountNodes(0), m_sEncoding(L"UTF-8"){}
|
||||
|
||||
CCssCalculator_Private::~CCssCalculator_Private()
|
||||
{}
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
void CCssCalculator_Private::SetPageData(NSProperties::CPage &oPage, const std::map<std::wstring, std::wstring> &mData, unsigned int unLevel, bool bHardMode)
|
||||
{
|
||||
//TODO:: пересмотреть данный метод
|
||||
m_oStyleStorage.SetPageData(oPage, mData, unLevel, bHardMode);
|
||||
}
|
||||
|
||||
std::map<std::wstring, std::wstring> CCssCalculator_Private::GetPageData(const std::wstring &wsPageName)
|
||||
{
|
||||
return m_oStyleStorage.GetPageData(wsPageName);
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::ClearPageData()
|
||||
{
|
||||
m_oStyleStorage.ClearPageData();
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<std::wstring> CCssCalculator_Private::CalculateAllNodes(const std::vector<CNode> &arSelectors)
|
||||
{
|
||||
std::vector<std::wstring> arNodes;
|
||||
|
||||
for (std::vector<CNode>::const_reverse_iterator oNode = arSelectors.rbegin(); oNode != arSelectors.rend(); ++oNode)
|
||||
{
|
||||
if (!oNode->m_wsName.empty())
|
||||
arNodes.push_back(oNode->m_wsName);
|
||||
|
||||
if (!oNode->m_wsClass.empty())
|
||||
{
|
||||
if (oNode->m_wsClass.find(L' ') != std::wstring::npos)
|
||||
{
|
||||
std::vector<std::wstring> arClasses = NS_STATIC_FUNCTIONS::GetWordsW(oNode->m_wsClass, false, L" ");
|
||||
|
||||
arNodes.push_back(std::accumulate(arClasses.begin(), arClasses.end(), std::wstring(),
|
||||
[](std::wstring sRes, const std::wstring& sClass)
|
||||
{return sRes += L'.' + sClass + L' ';}));
|
||||
}
|
||||
else
|
||||
arNodes.push_back(L'.' + oNode->m_wsClass);
|
||||
}
|
||||
|
||||
if (!oNode->m_wsId.empty())
|
||||
arNodes.push_back(L'#' + oNode->m_wsId);
|
||||
}
|
||||
|
||||
return arNodes;
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::FindPrevAndKindElements(const CElement *pElement, const std::vector<std::wstring> &arNextNodes, std::vector<const CElement*>& arFindedElements, const std::wstring &wsName, const std::vector<std::wstring> &arClasses)
|
||||
{
|
||||
if (arNextNodes.empty())
|
||||
return;
|
||||
|
||||
const std::vector<CElement*> arTempPrev = pElement->GetPrevElements(arNextNodes.crbegin() + 1, arNextNodes.crend());
|
||||
const std::vector<CElement*> arTempKins = pElement->GetNextOfKin(wsName, arClasses);
|
||||
|
||||
if (!arTempPrev.empty())
|
||||
arFindedElements.insert(arFindedElements.end(), arTempPrev.begin(), arTempPrev.end());
|
||||
|
||||
if (!arTempKins.empty())
|
||||
arFindedElements.insert(arFindedElements.end(), arTempKins.begin(), arTempKins.end());
|
||||
}
|
||||
|
||||
std::vector<const CElement*> CCssCalculator_Private::FindElements(std::vector<std::wstring> &arNodes, std::vector<std::wstring> &arNextNodes)
|
||||
{
|
||||
if (arNodes.empty())
|
||||
return {};
|
||||
|
||||
std::vector<const CElement*> arFindedElements;
|
||||
|
||||
std::wstring wsName, wsId;
|
||||
std::vector<std::wstring> arClasses;
|
||||
|
||||
if (!arNodes.empty() && arNodes.back()[0] == L'#')
|
||||
{
|
||||
wsId = arNodes.back();
|
||||
arNodes.pop_back();
|
||||
arNextNodes.push_back(wsId);
|
||||
}
|
||||
|
||||
if (!arNodes.empty() && arNodes.back()[0] == L'.')
|
||||
{
|
||||
arClasses = NS_STATIC_FUNCTIONS::GetWordsW(arNodes.back(), false, L" ");
|
||||
arNextNodes.push_back(arNodes.back());
|
||||
arNodes.pop_back();
|
||||
}
|
||||
|
||||
if (!arNodes.empty())
|
||||
{
|
||||
wsName = arNodes.back();
|
||||
arNodes.pop_back();
|
||||
arNextNodes.push_back(wsName);
|
||||
}
|
||||
|
||||
if (!wsId.empty())
|
||||
{
|
||||
const CElement* pFoundId = m_oStyleStorage.FindElement(wsId);
|
||||
|
||||
if(nullptr != pFoundId)
|
||||
{
|
||||
if (!pFoundId->Empty())
|
||||
arFindedElements.push_back(pFoundId);
|
||||
|
||||
FindPrevAndKindElements(pFoundId, arNextNodes, arFindedElements, wsName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!arClasses.empty())
|
||||
{
|
||||
for (std::vector<std::wstring>::const_reverse_iterator iClass = arClasses.rbegin(); iClass != arClasses.rend(); ++iClass)
|
||||
{
|
||||
const CElement* pFoundClass = m_oStyleStorage.FindElement(*iClass);
|
||||
|
||||
if (nullptr != pFoundClass)
|
||||
{
|
||||
if (!pFoundClass->Empty())
|
||||
arFindedElements.push_back(pFoundClass);
|
||||
|
||||
FindPrevAndKindElements(pFoundClass, arNextNodes, arFindedElements, wsName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CElement* pFoundName = m_oStyleStorage.FindElement(wsName);
|
||||
|
||||
if (nullptr != pFoundName)
|
||||
{
|
||||
if (!pFoundName->Empty())
|
||||
arFindedElements.push_back(pFoundName);
|
||||
|
||||
FindPrevAndKindElements(pFoundName, arNextNodes, arFindedElements, wsName, arClasses);
|
||||
}
|
||||
|
||||
if (arFindedElements.size() > 1)
|
||||
{
|
||||
std::sort(arFindedElements.rbegin(), arFindedElements.rend(),
|
||||
[](const CElement* oFirstElement, const CElement* oSecondElement)
|
||||
{ return oFirstElement->GetWeight() > oSecondElement->GetWeight(); });
|
||||
}
|
||||
|
||||
return arFindedElements;
|
||||
}
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
CCompiledStyle CCssCalculator_Private::GetCompiledStyle(const std::vector<CNode>& arSelectors, const bool& bIsSettings, const UnitMeasure& unitMeasure)
|
||||
CCompiledStyle CCssCalculator_Private::GetCompiledStyle(const std::vector<CNode>& arSelectors)
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return CCompiledStyle();
|
||||
|
||||
CCompiledStyle oStyle;
|
||||
|
||||
GetCompiledStyle(oStyle, arSelectors, bIsSettings, unitMeasure);
|
||||
GetCompiledStyle(oStyle, arSelectors);
|
||||
|
||||
return oStyle;
|
||||
}
|
||||
|
||||
bool CCssCalculator_Private::GetCompiledStyle(CCompiledStyle &oStyle, const std::vector<CNode> &arSelectors, const bool &bIsSettings, const UnitMeasure &unitMeasure)
|
||||
bool CCssCalculator_Private::GetCompiledStyle(CCompiledStyle &oStyle, const std::vector<CNode> &arSelectors)
|
||||
{
|
||||
if (arSelectors.empty())
|
||||
return false;
|
||||
|
||||
SetUnitMeasure(unitMeasure);
|
||||
const std::map<std::vector<CNode>, CCompiledStyle>::iterator oItem = m_mUsedStyles.find(arSelectors);
|
||||
|
||||
if (!bIsSettings)
|
||||
if (oItem != m_mUsedStyles.end())
|
||||
{
|
||||
const std::map<std::vector<CNode>, CCompiledStyle>::iterator oItem = m_mUsedStyles.find(arSelectors);
|
||||
|
||||
if (oItem != m_mUsedStyles.end())
|
||||
{
|
||||
oStyle = oItem->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (NULL == m_mStatictics || m_mStatictics->empty())
|
||||
{
|
||||
oStyle.SetDpi(m_nDpi);
|
||||
oStyle.SetUnitMeasure(m_UnitMeasure);
|
||||
oStyle.SetID(arSelectors.back().m_wsName + ((!arSelectors.back().m_wsClass.empty()) ? L'.' + arSelectors.back().m_wsClass : L"") + ((arSelectors.back().m_wsId.empty()) ? L"" : L'#' + arSelectors.back().m_wsId) + L'-' + std::to_wstring(++m_nCountNodes));
|
||||
|
||||
return false;
|
||||
oStyle = oItem->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
oStyle.SetDpi(m_nDpi);
|
||||
oStyle.SetUnitMeasure(m_UnitMeasure);
|
||||
|
||||
std::vector<std::wstring> arNodes = CalculateAllNodes(arSelectors);
|
||||
std::vector<std::wstring> arPrevNodes;
|
||||
@ -535,25 +679,10 @@ namespace NSCSS
|
||||
|
||||
oTempStyle.AddStyle(arSelectors[i].m_mAttributes, i + 1);
|
||||
|
||||
for (const CElement* oElement : FindElements(arNodes, arPrevNodes, bIsSettings))
|
||||
for (const CElement* oElement : FindElements(arNodes, arPrevNodes))
|
||||
oTempStyle.AddStyle(oElement->GetStyle(), i + 1);
|
||||
|
||||
if (NULL != m_mStatictics)
|
||||
{
|
||||
std::map<StatistickElement, unsigned int>::const_iterator oFindCountStyle = m_mStatictics->find(StatistickElement{StatistickElement::IsStyle, arSelectors[i].m_wsStyle});
|
||||
|
||||
if (oFindCountStyle != m_mStatictics->end())
|
||||
{
|
||||
if ((bIsSettings && oFindCountStyle->second < MaxNumberRepetitions) ||
|
||||
(!bIsSettings && oFindCountStyle->second >= MaxNumberRepetitions))
|
||||
oTempStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
else if (!bIsSettings)
|
||||
oTempStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
}
|
||||
else /*if (bIsSettings)*/
|
||||
oTempStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
}
|
||||
else
|
||||
if (!arSelectors[i].m_wsStyle.empty())
|
||||
oTempStyle.AddStyle(arSelectors[i].m_wsStyle, i + 1, true);
|
||||
|
||||
oStyle += oTempStyle;
|
||||
@ -569,7 +698,7 @@ namespace NSCSS
|
||||
|
||||
oStyle.SetID(CalculateStyleId(arSelectors.back()));
|
||||
|
||||
if (!bIsSettings && !oStyle.Empty())
|
||||
if (!oStyle.Empty())
|
||||
m_mUsedStyles[arSelectors] = oStyle;
|
||||
|
||||
return true;
|
||||
@ -597,7 +726,7 @@ namespace NSCSS
|
||||
SetPageData(oPageData, GetPageData(mRules[L"page"]), i + 1, true);
|
||||
}
|
||||
|
||||
for (const CElement* oElement : FindElements(arNodes, arNextNodes, false))
|
||||
for (const CElement* oElement : FindElements(arNodes, arNextNodes))
|
||||
{
|
||||
std::map<std::wstring, std::wstring> mRules = oElement->GetStyle();
|
||||
if (mRules.end() != mRules.find(L"page"))
|
||||
@ -611,42 +740,20 @@ namespace NSCSS
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
void CCssCalculator_Private::AddStyles(const std::string &sStyle)
|
||||
{
|
||||
if (sStyle.empty())
|
||||
return;
|
||||
|
||||
KatanaOutput *output = katana_parse(sStyle.c_str(), sStyle.length(), KatanaParserModeStylesheet);
|
||||
this->GetOutputData(output);
|
||||
katana_destroy_output(output);
|
||||
void CCssCalculator_Private::AddStyles(const std::string& sStyle)
|
||||
{
|
||||
m_oStyleStorage.AddStyles(sStyle);
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::AddStyles(const std::wstring &wsStyle)
|
||||
void CCssCalculator_Private::AddStyles(const std::wstring& wsStyle)
|
||||
{
|
||||
if (wsStyle.empty())
|
||||
return;
|
||||
|
||||
std::wregex oRegex(L"@page\\s*([^{]*)(\\{[^}]*\\})");
|
||||
std::wsmatch oMatch;
|
||||
std::wstring::const_iterator oSearchStart(wsStyle.cbegin());
|
||||
|
||||
while (std::regex_search(oSearchStart, wsStyle.cend(), oMatch, oRegex))
|
||||
{
|
||||
AddPageData(oMatch[1].str(), oMatch[2].str());
|
||||
oSearchStart = oMatch.suffix().first;
|
||||
}
|
||||
|
||||
AddStyles(U_TO_UTF8(wsStyle));
|
||||
m_oStyleStorage.AddStyles(wsStyle);
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::AddStylesFromFile(const std::wstring& wsFileName)
|
||||
{
|
||||
if (std::find(m_arFiles.begin(), m_arFiles.end(), wsFileName) != m_arFiles.end())
|
||||
return;
|
||||
|
||||
m_arFiles.push_back(wsFileName);
|
||||
|
||||
AddStyles(NS_STATIC_FUNCTIONS::GetContentAsUTF8(wsFileName));
|
||||
m_oStyleStorage.AddStylesFromFile(wsFileName);
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::SetDpi(unsigned short int nValue)
|
||||
@ -654,32 +761,28 @@ namespace NSCSS
|
||||
m_nDpi = nValue;
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::SetBodyTree(const CTree &oTree)
|
||||
{
|
||||
if (NULL == m_mStatictics)
|
||||
m_mStatictics = new std::map<StatistickElement, unsigned int>();
|
||||
|
||||
CTree::CountingNumberRepetitions(oTree, *m_mStatictics);
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::SetUnitMeasure(const UnitMeasure& nType)
|
||||
{
|
||||
m_UnitMeasure = nType;
|
||||
}
|
||||
|
||||
unsigned short int CCssCalculator_Private::GetDpi() const
|
||||
{
|
||||
return m_nDpi;
|
||||
}
|
||||
|
||||
const std::map<std::wstring, CElement *> *CCssCalculator_Private::GetData() const
|
||||
void CCssCalculator_Private::ClearEmbeddedStyles()
|
||||
{
|
||||
return &m_mData;
|
||||
m_oStyleStorage.ClearEmbeddedStyles();
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
m_mUsedStyles.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
UnitMeasure CCssCalculator_Private::GetUnitMeasure() const
|
||||
void CCssCalculator_Private::ClearAllowedStyleFiles()
|
||||
{
|
||||
return m_UnitMeasure;
|
||||
m_oStyleStorage.ClearAllowedStyleFiles();
|
||||
}
|
||||
|
||||
void CCssCalculator_Private::ClearStylesFromFile(const std::wstring& wsFilePath)
|
||||
{
|
||||
m_oStyleStorage.ClearStylesFromFile(wsFilePath);
|
||||
}
|
||||
|
||||
std::wstring CCssCalculator_Private::GetEncoding() const
|
||||
@ -691,12 +794,22 @@ namespace NSCSS
|
||||
{
|
||||
m_sEncoding = L"UTF-8";
|
||||
m_nDpi = 96;
|
||||
m_UnitMeasure = Point;
|
||||
|
||||
m_mData.clear();
|
||||
m_arFiles.clear();
|
||||
m_oStyleStorage.Clear();
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
m_mUsedStyles.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsTableElement(const std::wstring& wsNameTag)
|
||||
{
|
||||
return L"td" == wsNameTag || L"tr" == wsNameTag || L"table" == wsNameTag ||
|
||||
L"tbody" == wsNameTag || L"thead" == wsNameTag || L"tfoot" == wsNameTag ||
|
||||
L"th" == wsNameTag;
|
||||
}
|
||||
}
|
||||
|
||||
inline static std::wstring StringifyValueList(const KatanaArray* oValues)
|
||||
{
|
||||
if (NULL == oValues)
|
||||
@ -797,11 +910,4 @@ inline static std::wstring StringifyValue(const KatanaValue* oValue)
|
||||
return str;
|
||||
}
|
||||
|
||||
inline static bool IsTableElement(const std::wstring& wsNameTag)
|
||||
{
|
||||
return L"td" == wsNameTag || L"tr" == wsNameTag || L"table" == wsNameTag ||
|
||||
L"tbody" == wsNameTag || L"thead" == wsNameTag || L"tfoot" == wsNameTag ||
|
||||
L"th" == wsNameTag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,11 +3,9 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include <set>
|
||||
#include "CElement.h"
|
||||
#include "ConstValues.h"
|
||||
#include "CUnitMeasureConverter.h"
|
||||
#include "StyleProperties.h"
|
||||
#include "../../katana-parser/src/katana.h"
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
@ -16,16 +14,43 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
class CCssCalculator_Private
|
||||
class CStyleStorage
|
||||
{
|
||||
unsigned short int m_nDpi;
|
||||
unsigned short int m_nCountNodes;
|
||||
UnitMeasure m_UnitMeasure;
|
||||
public:
|
||||
CStyleStorage();
|
||||
~CStyleStorage();
|
||||
|
||||
std::list<std::wstring> m_arFiles;
|
||||
void Clear();
|
||||
|
||||
std::map<std::wstring, CElement*> m_mData;
|
||||
void AddStyles(const std::string& sStyle);
|
||||
void AddStyles(const std::wstring& wsStyle);
|
||||
void AddStylesFromFile(const std::wstring& wsFileName);
|
||||
|
||||
void ClearEmbeddedStyles();
|
||||
void ClearAllowedStyleFiles();
|
||||
void ClearStylesFromFile(const std::wstring& wsFileName);
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
void AddPageData(const std::wstring& wsPageName, const std::wstring& wsStyles);
|
||||
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);
|
||||
std::map<std::wstring, std::wstring> GetPageData(const std::wstring& wsPageName);
|
||||
void ClearPageData();
|
||||
#endif
|
||||
|
||||
const CElement* FindElement(const std::wstring& wsSelector);
|
||||
private:
|
||||
typedef struct
|
||||
{
|
||||
std::wstring m_wsStyleFilepath;
|
||||
std::map<std::wstring, CElement*> m_mStyleData;
|
||||
} TStyleFileData;
|
||||
|
||||
std::set<std::wstring> m_arEmptyStyleFiles;
|
||||
std::set<std::wstring> m_arAllowedStyleFiles;
|
||||
std::vector<TStyleFileData*> m_arStyleFiles;
|
||||
std::map<std::wstring, CElement*> m_mEmbeddedStyleData;
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
typedef struct
|
||||
{
|
||||
std::vector<std::wstring> m_wsNames;
|
||||
@ -33,29 +58,14 @@ namespace NSCSS
|
||||
} TPageData;
|
||||
|
||||
std::vector<TPageData> m_arPageDatas;
|
||||
|
||||
std::map<StatistickElement, unsigned int> *m_mStatictics; // Количество повторений свойств id и style у селекторов
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
std::map<std::vector<CNode>, CCompiledStyle> m_mUsedStyles;
|
||||
|
||||
std::map<std::wstring, std::wstring> GetPageData(const std::wstring& wsPageName);
|
||||
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);
|
||||
|
||||
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors);
|
||||
|
||||
void FindPrevAndKindElements(const CElement* pElement, const std::vector<std::wstring>& arNextNodes, std::vector<CElement*>& arFindedElements, const std::wstring& wsName, const std::vector<std::wstring>& arClasses = {});
|
||||
std::vector<CElement*> FindElements(std::vector<std::wstring>& arNodes, std::vector<std::wstring>& arNextNodes, bool bIsSettings);
|
||||
#endif
|
||||
private:
|
||||
void AddStyles(const std::string& sStyle, std::map<std::wstring, CElement*>& mStyleData);
|
||||
|
||||
std::wstring m_sEncoding;
|
||||
void GetStylesheet(const KatanaStylesheet* oStylesheet, std::map<std::wstring, CElement*>& mStyleData);
|
||||
void GetRule(const KatanaRule* oRule, std::map<std::wstring, CElement*>& mStyleData);
|
||||
|
||||
void AddPageData(const std::wstring& wsPageName, const std::wstring& wsStyles);
|
||||
|
||||
void GetStylesheet(const KatanaStylesheet* oStylesheet);
|
||||
void GetRule(const KatanaRule* oRule);
|
||||
|
||||
void GetStyleRule(const KatanaStyleRule* oRule);
|
||||
void GetStyleRule(const KatanaStyleRule* oRule, std::map<std::wstring, CElement*>& mStyleData);
|
||||
|
||||
std::wstring GetValueList(const KatanaArray* oValues);
|
||||
|
||||
@ -65,36 +75,60 @@ namespace NSCSS
|
||||
std::map<std::wstring, std::wstring> GetDeclarationList(const KatanaArray* oDeclarations) const;
|
||||
std::pair<std::wstring, std::wstring> GetDeclaration(const KatanaDeclaration* oDecl) const;
|
||||
|
||||
void GetOutputData(KatanaOutput* oOutput);
|
||||
void GetOutputData(KatanaOutput* oOutput, std::map<std::wstring, CElement*>& mStyleData);
|
||||
|
||||
const CElement* FindSelectorFromStyleData(const std::wstring& wsSelector, const std::map<std::wstring, CElement*>& mStyleData);
|
||||
};
|
||||
|
||||
class CCssCalculator_Private
|
||||
{
|
||||
unsigned short int m_nDpi;
|
||||
unsigned short int m_nCountNodes;
|
||||
|
||||
CStyleStorage m_oStyleStorage;
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
std::map<std::vector<CNode>, CCompiledStyle> m_mUsedStyles;
|
||||
|
||||
void SetPageData(NSProperties::CPage& oPage, const std::map<std::wstring, std::wstring>& mData, unsigned int unLevel, bool bHardMode = false);
|
||||
std::map<std::wstring, std::wstring> GetPageData(const std::wstring &wsPageName);
|
||||
#endif
|
||||
|
||||
void FindPrevAndKindElements(const CElement* pElement, const std::vector<std::wstring>& arNextNodes, std::vector<const CElement*>& arFindedElements, const std::wstring& wsName, const std::vector<std::wstring>& arClasses = {});
|
||||
|
||||
std::wstring m_sEncoding;
|
||||
public:
|
||||
CCssCalculator_Private();
|
||||
~CCssCalculator_Private();
|
||||
|
||||
#ifdef CSS_CALCULATOR_WITH_XHTML
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point);
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors, const bool& bIsSettings = false, const UnitMeasure& unitMeasure = Point);
|
||||
CCompiledStyle GetCompiledStyle(const std::vector<CNode> &arSelectors);
|
||||
bool GetCompiledStyle(CCompiledStyle& oStyle, const std::vector<CNode> &arSelectors);
|
||||
|
||||
std::wstring CalculateStyleId(const CNode& oNode);
|
||||
bool CalculatePageStyle(NSProperties::CPage& oPageData, const std::vector<CNode> &arSelectors);
|
||||
|
||||
void ClearPageData();
|
||||
#endif
|
||||
|
||||
std::vector<std::wstring> CalculateAllNodes(const std::vector<CNode>& arSelectors);
|
||||
std::vector<const CElement*> FindElements(std::vector<std::wstring>& arNodes, std::vector<std::wstring>& arNextNodes);
|
||||
|
||||
void AddStyles(const std::string& sStyle);
|
||||
void AddStyles(const std::wstring& wsStyle);
|
||||
void AddStylesFromFile(const std::wstring& wsFileName);
|
||||
|
||||
void SetUnitMeasure(const UnitMeasure& nType);
|
||||
void SetDpi(unsigned short int nValue);
|
||||
void SetBodyTree(const CTree &oTree);
|
||||
|
||||
UnitMeasure GetUnitMeasure() const;
|
||||
std::wstring GetEncoding() const;
|
||||
unsigned short int GetDpi() const;
|
||||
|
||||
const std::map<std::wstring, CElement*>* GetData() const;
|
||||
|
||||
void ClearEmbeddedStyles();
|
||||
void ClearAllowedStyleFiles();
|
||||
void ClearStylesFromFile(const std::wstring& wsFilePath);
|
||||
void Clear();
|
||||
|
||||
};
|
||||
|
||||
inline bool IsTableElement(const std::wstring& wsNameTag);
|
||||
}
|
||||
#endif // CCSSCALCULATOR_PRIVATE_H
|
||||
|
||||
@ -40,6 +40,7 @@ namespace NSCSS
|
||||
{
|
||||
m_sSelector = sSelector;
|
||||
m_sFullSelector = m_sSelector;
|
||||
UpdateWeight();
|
||||
}
|
||||
|
||||
void NSCSS::CElement::AddPropertie(const std::wstring &sName, const std::wstring& sValue)
|
||||
@ -67,6 +68,7 @@ namespace NSCSS
|
||||
|
||||
m_arPrevElements.push_back(oPrevElement);
|
||||
oPrevElement->m_sFullSelector += L' ' + m_sFullSelector;
|
||||
UpdateWeight();
|
||||
}
|
||||
|
||||
void CElement::AddKinElement(CElement *oKinElement)
|
||||
@ -76,6 +78,7 @@ namespace NSCSS
|
||||
|
||||
m_arKinElements.push_back(oKinElement);
|
||||
oKinElement->m_sFullSelector += m_sFullSelector;
|
||||
oKinElement->UpdateWeight();
|
||||
}
|
||||
|
||||
std::map<std::wstring, std::wstring> CElement::GetStyle() const
|
||||
@ -230,11 +233,14 @@ namespace NSCSS
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::vector<unsigned short> CElement::GetWeight()
|
||||
void CElement::UpdateWeight()
|
||||
{
|
||||
if (m_arWeight.empty())
|
||||
m_arWeight = NS_STATIC_FUNCTIONS::GetWeightSelector(m_sFullSelector);
|
||||
}
|
||||
|
||||
std::vector<unsigned short> CElement::GetWeight() const
|
||||
{
|
||||
return m_arWeight;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@ namespace NSCSS
|
||||
|
||||
CElement *FindPrevElement(const std::wstring& sSelector) const;
|
||||
|
||||
std::vector<unsigned short int> GetWeight();
|
||||
void UpdateWeight();
|
||||
std::vector<unsigned short int> GetWeight() const;
|
||||
void IncreasedWeight();
|
||||
};
|
||||
}
|
||||
|
||||
@ -2,29 +2,6 @@
|
||||
|
||||
namespace NSCSS
|
||||
{
|
||||
bool StatistickElement::operator<(const StatistickElement &oStatistickElement) const
|
||||
{
|
||||
return sValue < oStatistickElement.sValue;
|
||||
}
|
||||
|
||||
void CTree::Clear()
|
||||
{
|
||||
m_arrChild.clear();
|
||||
m_oNode.Clear();
|
||||
}
|
||||
|
||||
void CTree::CountingNumberRepetitions(const CTree &oTree, std::map<StatistickElement, unsigned int> &mStatictics)
|
||||
{
|
||||
if (!oTree.m_oNode.m_wsId.empty())
|
||||
++mStatictics[StatistickElement{StatistickElement::IsId, L'#' + oTree.m_oNode.m_wsId}];
|
||||
if (!oTree.m_oNode.m_wsStyle.empty())
|
||||
++mStatictics[StatistickElement{StatistickElement::IsStyle, oTree.m_oNode.m_wsStyle}];
|
||||
|
||||
if (!oTree.m_arrChild.empty())
|
||||
for (const CTree& oChildren : oTree.m_arrChild)
|
||||
CountingNumberRepetitions(oChildren, mStatictics);
|
||||
}
|
||||
|
||||
namespace NSConstValues
|
||||
{
|
||||
const std::map<std::wstring, std::wstring> COLORS
|
||||
|
||||
@ -16,28 +16,6 @@ namespace NSCSS
|
||||
ScalingDirectionY = 2
|
||||
} ScalingDirection;
|
||||
|
||||
struct StatistickElement
|
||||
{
|
||||
enum TypeElement
|
||||
{
|
||||
IsStyle = 0,
|
||||
IsId
|
||||
} m_enType;
|
||||
std::wstring sValue;
|
||||
|
||||
bool operator<(const StatistickElement& oStatistickElement) const;
|
||||
};
|
||||
|
||||
struct CTree
|
||||
{
|
||||
NSCSS::CNode m_oNode;
|
||||
std::vector<CTree> m_arrChild;
|
||||
|
||||
void Clear();
|
||||
|
||||
static void CountingNumberRepetitions(const CTree &oTree, std::map<StatistickElement, unsigned int> &mStatictics);
|
||||
};
|
||||
|
||||
namespace NSConstValues
|
||||
{
|
||||
extern const std::map<std::wstring, std::wstring> COLORS;
|
||||
|
||||
@ -48,7 +48,6 @@ namespace NS_STATIC_FUNCTIONS
|
||||
if (sEncoding.empty())
|
||||
sEncoding = "utf-8";
|
||||
|
||||
|
||||
if (!sEncoding.empty() && sEncoding != "utf-8" && sEncoding != "UTF-8")
|
||||
{
|
||||
NSUnicodeConverter::CUnicodeConverter oConverter;
|
||||
|
||||
@ -513,6 +513,9 @@ namespace NSCSS
|
||||
return (*static_cast<std::wstring*>(m_oValue)) == (*static_cast<std::wstring*>(oColor.m_oValue));
|
||||
case ColorUrl:
|
||||
return (*static_cast<CURL*>(m_oValue)) == (*static_cast<CURL*>(oColor.m_oValue));
|
||||
case ColorContextStroke:
|
||||
case ColorContextFill:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,6 +535,9 @@ namespace NSCSS
|
||||
return (*static_cast<std::wstring*>(m_oValue)) != (*static_cast<std::wstring*>(oColor.m_oValue));
|
||||
case ColorUrl:
|
||||
return (*static_cast<CURL*>(m_oValue)) != (*static_cast<CURL*>(oColor.m_oValue));
|
||||
case ColorContextStroke:
|
||||
case ColorContextFill:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -561,6 +567,9 @@ namespace NSCSS
|
||||
m_oValue = new CURL(*static_cast<CURL*>(oColor.m_oValue));
|
||||
break;
|
||||
}
|
||||
case ColorContextStroke:
|
||||
case ColorContextFill:
|
||||
break;
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -580,6 +589,39 @@ namespace NSCSS
|
||||
: CValue(NULL, 0, false), m_oOpacity(1.), m_enType(ColorEmpty)
|
||||
{}
|
||||
|
||||
CColor::CColor(const CColor& oColor)
|
||||
: CValue(NULL, 0, false), m_oOpacity(oColor.m_oOpacity), m_enType(oColor.m_enType)
|
||||
{
|
||||
switch (m_enType)
|
||||
{
|
||||
case ColorRGB:
|
||||
{
|
||||
TRGB *pRGB = static_cast<TRGB*>(oColor.m_oValue);
|
||||
m_oValue = new TRGB(*pRGB);
|
||||
break;
|
||||
}
|
||||
case ColorHEX:
|
||||
{
|
||||
std::wstring* pValue = static_cast<std::wstring*>(oColor.m_oValue);
|
||||
m_oValue = new std::wstring(*pValue);
|
||||
break;
|
||||
}
|
||||
case ColorUrl:
|
||||
{
|
||||
CURL *pURL = static_cast<CURL*>(oColor.m_oValue);
|
||||
m_oValue = new CURL(*pURL);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CColor::~CColor()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void CColor::SetEmpty(unsigned int unLevel)
|
||||
{
|
||||
Clear();
|
||||
@ -875,6 +917,25 @@ namespace NSCSS
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring CColor::ToHEX() const
|
||||
{
|
||||
switch(m_enType)
|
||||
{
|
||||
case ColorRGB:
|
||||
{
|
||||
TRGB* pRGB = static_cast<TRGB*>(m_oValue);
|
||||
return ConvertRGBtoHEX(*pRGB);
|
||||
}
|
||||
case ColorHEX:
|
||||
{
|
||||
std::wstring *pValue = static_cast<std::wstring*>(m_oValue);
|
||||
return *pValue;
|
||||
}
|
||||
default:
|
||||
return std::wstring();
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring CColor::EquateToColor(const std::vector<std::pair<TRGB, std::wstring>> &arColors) const
|
||||
{
|
||||
if (arColors.empty())
|
||||
|
||||
@ -224,6 +224,8 @@ namespace NSCSS
|
||||
{
|
||||
public:
|
||||
CColor();
|
||||
CColor(const CColor& oColor);
|
||||
~CColor();
|
||||
|
||||
bool SetValue(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true) override;
|
||||
bool SetOpacity(const std::wstring& wsValue, unsigned int unLevel = 0, bool bHardMode = true);
|
||||
@ -240,6 +242,7 @@ namespace NSCSS
|
||||
int ToInt() const override;
|
||||
double ToDouble() const override;
|
||||
std::wstring ToWString() const override;
|
||||
std::wstring ToHEX() const;
|
||||
std::wstring EquateToColor(const std::vector<std::pair<TRGB, std::wstring>>& arColors) const;
|
||||
TRGB ToRGB() const;
|
||||
|
||||
|
||||
@ -316,7 +316,7 @@ namespace NSCSS
|
||||
|
||||
std::wstring wsTextAlign{oStyle.m_oText.GetAlign().ToWString()};
|
||||
|
||||
if (wsTextAlign.empty() && bInTable)
|
||||
if (wsTextAlign.empty())
|
||||
wsTextAlign = oStyle.m_oDisplay.GetHAlign().ToWString();
|
||||
|
||||
oXmlElement.AddPropertiesInP(PProperties::P_Jc, wsTextAlign);
|
||||
@ -485,7 +485,7 @@ namespace NSCSS
|
||||
return;
|
||||
|
||||
if (!oStyle.m_oFont.GetSize().Empty())
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_Sz, std::to_wstring(static_cast<int>(oStyle.m_oFont.GetSize().ToDouble(NSCSS::Point) * 2. + 0.5))); // Значения шрифта увеличивает на 2
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_Sz, std::to_wstring(static_cast<int>(oStyle.m_oFont.GetSize().ToDouble(NSCSS::Point) * 2. * oStyle.m_oTransform.GetMatrix().GetFinalValue().sy() + 0.5))); // Значения шрифта увеличивает на 2
|
||||
|
||||
if (oStyle.m_oText.GetDecoration().m_oLine.Underline())
|
||||
oXmlElement.AddPropertiesInR(RProperties::R_U, (!oStyle.m_oText.GetDecoration().m_oStyle.Empty()) ? oStyle.m_oText.GetDecoration().m_oStyle.ToWString() : L"single");
|
||||
|
||||
@ -68,6 +68,7 @@ public:
|
||||
bool isOOXFormatFile(const std::wstring& fileName, bool unpacked = false);
|
||||
bool isOpenOfficeFormatFile(const std::wstring& fileName, std::wstring& documentID);
|
||||
bool isOnlyOfficeFormatFile(const std::wstring& fileName);
|
||||
bool isMacFormatFile(const std::wstring& fileName);
|
||||
|
||||
bool isDocFormatFile(const std::wstring& fileName);
|
||||
bool isXlsFormatFile(const std::wstring& fileName);
|
||||
@ -80,6 +81,7 @@ public:
|
||||
bool isMS_MITCRYPTOFormatFile(POLE::Storage* storage, std::wstring& documentID);
|
||||
bool isVbaProjectFile(POLE::Storage* storage);
|
||||
bool isMS_OFFCRYPTOFormatFile(const std::wstring& fileName, std::wstring& documentID);
|
||||
bool isHwpFile(POLE::Storage* storage);
|
||||
|
||||
bool iXmlFile(const std::wstring& fileName);
|
||||
|
||||
|
||||
@ -451,6 +451,20 @@ bool COfficeFileFormatChecker::isVbaProjectFile(POLE::Storage *storage)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool COfficeFileFormatChecker::isHwpFile(POLE::Storage* storage)
|
||||
{
|
||||
if (storage == NULL)
|
||||
return false;
|
||||
|
||||
unsigned char buffer[10];
|
||||
|
||||
POLE::Stream stream(storage, L"BodyText/Section0");
|
||||
if (stream.read(buffer, 10) < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool COfficeFileFormatChecker::isXlsFormatFile(POLE::Storage *storage)
|
||||
{
|
||||
if (storage == NULL)
|
||||
@ -721,6 +735,11 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_OTHER_MS_VBAPROJECT;
|
||||
return true;
|
||||
}
|
||||
else if (isHwpFile(&storage))
|
||||
{
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HWP;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
NSFile::CFileBinary file;
|
||||
if (!file.OpenFile(fileName))
|
||||
@ -767,6 +786,13 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
|
||||
bufferDetect = NULL;
|
||||
return true;
|
||||
}
|
||||
else if (isMacFormatFile(fileName))
|
||||
{
|
||||
if (bufferDetect)
|
||||
delete[] bufferDetect;
|
||||
bufferDetect = NULL;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
@ -905,6 +931,10 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS;
|
||||
else if (0 == sExt.compare(L".key"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY;
|
||||
else if (0 == sExt.compare(L".hwp"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HWP;
|
||||
else if (0 == sExt.compare(L".hwpx"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HWPX;
|
||||
|
||||
if (nFileType != AVS_OFFICESTUDIO_FILE_UNKNOWN)
|
||||
return true;
|
||||
@ -1129,6 +1159,58 @@ bool COfficeFileFormatChecker::isOnlyOfficeFormatFile(const std::wstring &fileNa
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool COfficeFileFormatChecker::isMacFormatFile(const std::wstring& fileName)
|
||||
{
|
||||
COfficeUtils OfficeUtils(NULL);
|
||||
|
||||
ULONG nBufferSize = 0;
|
||||
BYTE* pBuffer = NULL;
|
||||
|
||||
HRESULT hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Document.iwa", &pBuffer, nBufferSize);
|
||||
if (hresult == S_OK && pBuffer != NULL)
|
||||
{
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES;
|
||||
|
||||
delete[] pBuffer;
|
||||
pBuffer = NULL;
|
||||
|
||||
hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Slide.iwa", &pBuffer, nBufferSize);
|
||||
if (hresult == S_OK && pBuffer != NULL)
|
||||
{
|
||||
delete[] pBuffer;
|
||||
pBuffer = NULL;
|
||||
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY;
|
||||
return true;
|
||||
}
|
||||
hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Tables/DataList.iwa", &pBuffer, nBufferSize);
|
||||
if (hresult == S_OK && pBuffer != NULL)
|
||||
{
|
||||
delete[] pBuffer;
|
||||
pBuffer = NULL;
|
||||
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS;
|
||||
return true;
|
||||
}
|
||||
std::wstring::size_type nExtPos = fileName.rfind(L'.');
|
||||
std::wstring sExt = L"unknown";
|
||||
|
||||
if (nExtPos != std::wstring::npos)
|
||||
sExt = fileName.substr(nExtPos);
|
||||
|
||||
std::transform(sExt.begin(), sExt.end(), sExt.begin(), tolower);
|
||||
|
||||
if (0 == sExt.compare(L".pages"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES;
|
||||
else if (0 == sExt.compare(L".numbers"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS;
|
||||
else if (0 == sExt.compare(L".key"))
|
||||
nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool COfficeFileFormatChecker::isOpenOfficeFormatFile(const std::wstring &fileName, std::wstring &documentID)
|
||||
{
|
||||
documentID.clear();
|
||||
@ -1371,6 +1453,7 @@ std::wstring COfficeFileFormatChecker::GetExtensionByType(int type)
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM:
|
||||
return L".dotm";
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC:
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC_FLAT:
|
||||
return L".doc";
|
||||
case AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT:
|
||||
return L".odt";
|
||||
|
||||
@ -57,6 +57,8 @@
|
||||
#define AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCXF AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0016
|
||||
#define AVS_OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0017
|
||||
#define AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0018
|
||||
#define AVS_OFFICESTUDIO_FILE_DOCUMENT_HWP AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0019
|
||||
#define AVS_OFFICESTUDIO_FILE_DOCUMENT_HWPX AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0020
|
||||
|
||||
#define AVS_OFFICESTUDIO_FILE_DOCUMENT_XML AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0030
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#define LOG_BUFFER_SIZE 1000
|
||||
|
||||
// not intended for use in production. only for testing/debugging purposes
|
||||
namespace Logging
|
||||
{
|
||||
void logBytes(char* name, unsigned char* str, int len)
|
||||
|
||||
@ -207,9 +207,9 @@ namespace agg
|
||||
}
|
||||
|
||||
p[Order::A] = (value_type)((alpha + a) - ((alpha * a + base_mask) >> base_shift));
|
||||
p[Order::R] = (value_type)((alpha * cr + a * r - ((a * r * alpha + base_mask) >> base_shift)) / p[Order::A]);
|
||||
p[Order::G] = (value_type)((alpha * cg + a * g - ((a * g * alpha + base_mask) >> base_shift)) / p[Order::A]);
|
||||
p[Order::B] = (value_type)((alpha * cb + a * b - ((a * b * alpha + base_mask) >> base_shift)) / p[Order::A]);
|
||||
if (r != cr) p[Order::R] = (value_type)((alpha * cr + a * r - ((a * r * alpha + base_mask) >> base_shift)) / p[Order::A]);
|
||||
if (g != cg) p[Order::G] = (value_type)((alpha * cg + a * g - ((a * g * alpha + base_mask) >> base_shift)) / p[Order::A]);
|
||||
if (b != cb) p[Order::B] = (value_type)((alpha * cb + a * b - ((a * b * alpha + base_mask) >> base_shift)) / p[Order::A]);
|
||||
}
|
||||
|
||||
static AGG_INLINE void blend_pix_subpix(value_type* p,
|
||||
|
||||
61
DesktopEditor/doctrenderer/addon/docbuilder_addon.h
Normal file
61
DesktopEditor/doctrenderer/addon/docbuilder_addon.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#ifndef DOC_BUILDER_ADDON_PRIVATE
|
||||
#define DOC_BUILDER_ADDON_PRIVATE
|
||||
|
||||
#include <string>
|
||||
#include "../docbuilder.h"
|
||||
|
||||
namespace NSDoctRenderer
|
||||
{
|
||||
class CDocBuilderAddon
|
||||
{
|
||||
private:
|
||||
std::wstring m_sWorkDirectory;
|
||||
public:
|
||||
CDocBuilderAddon(const std::wstring& sWorkDir)
|
||||
{
|
||||
m_sWorkDirectory = sWorkDir;
|
||||
}
|
||||
public:
|
||||
std::wstring GetX2tSaveAddon(NSDoctRenderer::CDocBuilder* builder, const int& filetype)
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
int GetX2tPreSaveError(NSDoctRenderer::CDocBuilder* builder, const int& filetype)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // DOC_BUILDER_ADDON_PRIVATE
|
||||
@ -33,6 +33,7 @@
|
||||
#include "./../common_deploy.h"
|
||||
#include "../docbuilder.h"
|
||||
#include "../../common/File.h"
|
||||
#include "../../common/SystemUtils.h"
|
||||
|
||||
#ifdef LINUX
|
||||
#include "../../../DesktopEditor/common/File.h"
|
||||
@ -78,6 +79,13 @@ void parse_args(NSDoctRenderer::CDocBuilder* builder, int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckLicense(const std::wstring& sSrc, const std::wstring& sDst)
|
||||
{
|
||||
NSFile::CFileBinary::Remove(sDst);
|
||||
NSFile::CFileBinary::Copy(sSrc, sDst);
|
||||
return NSFile::CFileBinary::Exists(sDst);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int wmain(int argc, wchar_t *argv[])
|
||||
#else
|
||||
@ -89,6 +97,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
bool bIsHelp = false;
|
||||
bool bIsFonts = false;
|
||||
bool bIsLicense = false;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
#ifdef WIN32
|
||||
@ -121,6 +130,33 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
bIsFonts = true;
|
||||
}
|
||||
else if (sParam == "-register")
|
||||
{
|
||||
bIsLicense = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bIsLicense)
|
||||
{
|
||||
std::wstring sLicensePathSrc = UTF8_TO_U(sParam);
|
||||
if (!NSFile::CFileBinary::Exists(sLicensePathSrc))
|
||||
return 1;
|
||||
|
||||
std::wstring sLicensePath = NSSystemUtils::GetEnvVariable(L"ONLYOFFICE_BUILDER_LICENSE");
|
||||
if (CheckLicense(sLicensePathSrc, sLicensePath))
|
||||
return 0;
|
||||
|
||||
sLicensePath = NSFile::GetProcessDirectory() + L"/license.xml";
|
||||
if (CheckLicense(sLicensePathSrc, sLicensePath))
|
||||
return 0;
|
||||
|
||||
sLicensePath = NSSystemUtils::GetAppDataDir() + L"/docbuilder/license.xml";
|
||||
if (CheckLicense(sLicensePathSrc, sLicensePath))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bIsFonts)
|
||||
|
||||
@ -38,6 +38,9 @@
|
||||
#include "../xml/include/xmlutils.h"
|
||||
#include "../fontengine/TextHyphen.h"
|
||||
|
||||
#define VALUE_TO_STRING(x) #x
|
||||
#define VALUE(x) VALUE_TO_STRING(x)
|
||||
|
||||
namespace NSDoctRenderer
|
||||
{
|
||||
class CAdditionalData
|
||||
@ -188,7 +191,7 @@ namespace NSDoctRenderer
|
||||
m_strSdkPath = oNode.ReadNodeText(L"sdkjs");
|
||||
if (!m_strSdkPath.empty())
|
||||
{
|
||||
if (!NSDirectory::Exists(m_strSdkPath))
|
||||
if (0 == m_strSdkPath.find(L"./") || !NSDirectory::Exists(m_strSdkPath))
|
||||
m_strSdkPath = sConfigDir + m_strSdkPath;
|
||||
}
|
||||
|
||||
@ -203,28 +206,14 @@ namespace NSDoctRenderer
|
||||
|
||||
char* GetVersion()
|
||||
{
|
||||
std::wstring sFile = m_strSdkPath + L"/word/sdk-all-min.js";
|
||||
std::string sVersion = VALUE(INTVER);
|
||||
|
||||
std::string sData;
|
||||
if (!NSFile::CFileBinary::ReadAllTextUtf8A(sFile, sData))
|
||||
return NULL;
|
||||
|
||||
std::string::size_type startPos = sData.find("Version:");
|
||||
if (std::string::npos == startPos)
|
||||
return NULL;
|
||||
|
||||
startPos += 8;
|
||||
|
||||
std::string::size_type endPos = sData.find(')', startPos);
|
||||
if (std::string::npos == endPos)
|
||||
return NULL;
|
||||
|
||||
size_t sSrcLen = endPos - startPos + 1;
|
||||
size_t sSrcLen = sVersion.size();
|
||||
if (sSrcLen == 0)
|
||||
return NULL;
|
||||
|
||||
char* sRet = new char[sSrcLen + 1];
|
||||
memcpy(sRet, sData.c_str() + startPos, sSrcLen);
|
||||
memcpy(sRet, sVersion.c_str(), sSrcLen);
|
||||
sRet[sSrcLen] = '\0';
|
||||
return sRet;
|
||||
}
|
||||
|
||||
@ -47,14 +47,6 @@ namespace NSDoctRenderer
|
||||
RELEASEOBJECT(m_pInternal);
|
||||
}
|
||||
|
||||
int CDocBuilder::OpenFile(const wchar_t* path, const wchar_t* params)
|
||||
{
|
||||
m_pInternal->m_nFileType = -1;
|
||||
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
|
||||
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
|
||||
|
||||
return m_pInternal->OpenFile(path, params);
|
||||
}
|
||||
int CDocBuilder::SaveFile(const int& type, const wchar_t* path, const wchar_t* params)
|
||||
{
|
||||
return m_pInternal->SaveFile(type, path, params);
|
||||
|
||||
@ -475,6 +475,13 @@ namespace NSDoctRenderer
|
||||
*/
|
||||
void SetPropertyW(const wchar_t* param, const wchar_t* value);
|
||||
|
||||
/**
|
||||
* GetProperty method.
|
||||
* @param param The parameter name in the Unicode format, the value is always --argument.
|
||||
* @return int value for property
|
||||
*/
|
||||
int GetPropertyInt(const wchar_t* param);
|
||||
|
||||
/**
|
||||
* Writes data to the log file. It is used for logs in JS code.
|
||||
* @param path The path to the file where all the logs will be written.
|
||||
@ -526,6 +533,7 @@ namespace NSDoctRenderer
|
||||
CDocBuilder_Private* m_pInternal;
|
||||
|
||||
friend class CBuilderDocumentEmbed;
|
||||
friend class CBuilderEmbed;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -2,6 +2,7 @@ import ctypes
|
||||
import os
|
||||
import platform
|
||||
import atexit
|
||||
import subprocess
|
||||
|
||||
OBJECT_HANDLE = ctypes.c_void_p
|
||||
STRING_HANDLE = ctypes.c_void_p
|
||||
@ -608,8 +609,14 @@ class FileTypes:
|
||||
PNG = _IMAGE_MASK + 0x0005
|
||||
BMP = _IMAGE_MASK + 0x0008
|
||||
|
||||
builder_path = os.path.dirname(os.path.realpath(__file__))
|
||||
builder_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib')
|
||||
_loadLibrary(builder_path)
|
||||
CDocBuilder.Initialize(builder_path)
|
||||
|
||||
def registerLibrary(license_path):
|
||||
docbuilder_bin = os.path.dirname(os.path.realpath(__file__)) + "/lib/docbuilder"
|
||||
if ("windows" == platform.system().lower()):
|
||||
docbuilder_bin += ".exe"
|
||||
return subprocess.call([docbuilder_bin, "-register", license_path], stderr=subprocess.STDOUT, shell=True)
|
||||
|
||||
atexit.register(CDocBuilder.Dispose)
|
||||
|
||||
@ -82,7 +82,7 @@ CV8RealTimeWorker::~CV8RealTimeWorker()
|
||||
m_context->Dispose();
|
||||
}
|
||||
|
||||
bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue)
|
||||
bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue, const bool& isEnterContext)
|
||||
{
|
||||
LOGGER_SPEED_START();
|
||||
|
||||
@ -92,14 +92,20 @@ bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRender
|
||||
std::string commandA = U_TO_UTF8(command);
|
||||
//commandA = "Api." + commandA;
|
||||
|
||||
CJSContextScope scope(m_context);
|
||||
if (isEnterContext)
|
||||
m_context->Enter();
|
||||
|
||||
JSSmart<CJSTryCatch> try_catch = m_context->GetExceptions();
|
||||
|
||||
LOGGER_SPEED_LAP("compile_command");
|
||||
|
||||
JSSmart<CJSValue> retNativeVal = m_context->runScript(commandA, try_catch);
|
||||
if(try_catch->Check())
|
||||
{
|
||||
if (isEnterContext)
|
||||
m_context->Exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (retValue)
|
||||
{
|
||||
@ -110,6 +116,9 @@ bool CV8RealTimeWorker::ExecuteCommand(const std::wstring& command, NSDoctRender
|
||||
|
||||
LOGGER_SPEED_LAP("run_command");
|
||||
|
||||
if (isEnterContext)
|
||||
m_context->Exit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -240,6 +249,14 @@ bool CV8RealTimeWorker::InitVariables()
|
||||
if (try_catch->Check())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_sJSCodeStart.empty())
|
||||
{
|
||||
m_context->runScript(m_sJSCodeStart, try_catch);
|
||||
if (try_catch->Check())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -296,7 +313,7 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
|
||||
else if (1 == m_nFileType)
|
||||
pNative->m_strEditorType = L"presentation";
|
||||
else if (7 == m_nFileType)
|
||||
pNative->m_strEditorType = L"draw";
|
||||
pNative->m_strEditorType = L"visio";
|
||||
else
|
||||
pNative->m_strEditorType = L"spreadsheet";
|
||||
|
||||
@ -336,7 +353,17 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
|
||||
return !bIsBreak;
|
||||
}
|
||||
|
||||
bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams)
|
||||
bool CV8RealTimeWorker::NewSimpleJSInstance()
|
||||
{
|
||||
return InitVariables();
|
||||
}
|
||||
|
||||
bool CV8RealTimeWorker::IsSimpleJSInstance()
|
||||
{
|
||||
return (-1 == m_nFileType);
|
||||
}
|
||||
|
||||
bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams, const bool& isEnterContext)
|
||||
{
|
||||
NSDoctRenderer::DoctRendererFormat::FormatFile _formatDst = NSDoctRenderer::DoctRendererFormat::DOCT;
|
||||
if (type & AVS_OFFICESTUDIO_FILE_PRESENTATION)
|
||||
@ -362,7 +389,9 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
|
||||
}
|
||||
}
|
||||
|
||||
CJSContextScope scope(m_context);
|
||||
if (isEnterContext)
|
||||
m_context->Enter();
|
||||
|
||||
JSSmart<CJSTryCatch> try_catch = m_context->GetExceptions();
|
||||
|
||||
NSNativeControl::CNativeControl* pNative = NULL;
|
||||
@ -391,7 +420,7 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
|
||||
bIsSilentMode = true;
|
||||
|
||||
if (bIsSilentMode)
|
||||
this->ExecuteCommand(L"Api.asc_SetSilentMode(false);");
|
||||
this->ExecuteCommand(L"Api.asc_SetSilentMode(false);", NULL, isEnterContext);
|
||||
|
||||
std::wstring strError;
|
||||
bool bIsError = Doct_renderer_SaveFile_ForBuilder(_formatDst,
|
||||
@ -403,7 +432,10 @@ bool CV8RealTimeWorker::SaveFileWithChanges(int type, const std::wstring& _path,
|
||||
sJsonParams);
|
||||
|
||||
if (bIsSilentMode)
|
||||
this->ExecuteCommand(L"Api.asc_SetSilentMode(true);");
|
||||
this->ExecuteCommand(L"Api.asc_SetSilentMode(true);", NULL, isEnterContext);
|
||||
|
||||
if (isEnterContext)
|
||||
m_context->Exit();
|
||||
|
||||
return bIsError;
|
||||
}
|
||||
@ -1231,8 +1263,29 @@ namespace NSDoctRenderer
|
||||
nCount = nIndex;
|
||||
}
|
||||
|
||||
int CDocBuilder::OpenFile(const wchar_t* path, const wchar_t* params)
|
||||
{
|
||||
if (m_pInternal->m_nFileType != -1 && m_pInternal->m_bIsOpenedFromSimpleJS)
|
||||
{
|
||||
m_pInternal->m_bIsOpenedFromSimpleJS = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
m_pInternal->m_nFileType = -1;
|
||||
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
|
||||
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
|
||||
|
||||
return m_pInternal->OpenFile(path, params);
|
||||
}
|
||||
|
||||
bool CDocBuilder::CreateFile(const int& type)
|
||||
{
|
||||
if (m_pInternal->m_nFileType != -1 && m_pInternal->m_bIsOpenedFromSimpleJS)
|
||||
{
|
||||
m_pInternal->m_bIsOpenedFromSimpleJS = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
m_pInternal->m_nFileType = -1;
|
||||
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
|
||||
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
|
||||
@ -1391,7 +1444,7 @@ namespace NSDoctRenderer
|
||||
if (!sJsCommands.empty())
|
||||
{
|
||||
std::wstring sUnicodeCommand = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sJsCommands.c_str(), (LONG)sJsCommands.length());
|
||||
bIsNoError = this->ExecuteCommand(sUnicodeCommand.c_str());
|
||||
bIsNoError = this->m_pInternal->ExecuteCommand(sUnicodeCommand.c_str(), NULL, bIsBuilderJSCloseFile);
|
||||
sJsCommands = "";
|
||||
if (!bIsNoError)
|
||||
return false;
|
||||
@ -1413,6 +1466,10 @@ namespace NSDoctRenderer
|
||||
if (0 == _builder_params[nCheckParam].find(L"jsValue(") && _builder_params[nCheckParam].length() > 9)
|
||||
{
|
||||
std::wstring sParam = _builder_params[nCheckParam].substr(8, _builder_params[nCheckParam].length() - 9);
|
||||
|
||||
if (NULL == m_pInternal->m_pWorker)
|
||||
m_pInternal->CheckWorker();
|
||||
|
||||
_builder_params[nCheckParam] = m_pInternal->m_pWorker->GetJSVariable(sParam);
|
||||
}
|
||||
}
|
||||
@ -1478,7 +1535,7 @@ namespace NSDoctRenderer
|
||||
{
|
||||
// Такого быть не должно!!! Так как результат никуда не сохранится. пустое действие.
|
||||
std::wstring sUnicodeCommand = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)sJsCommands.c_str(), (LONG)sJsCommands.length());
|
||||
bool bIsNoError = this->ExecuteCommand(sUnicodeCommand.c_str());
|
||||
bool bIsNoError = this->m_pInternal->ExecuteCommand(sUnicodeCommand.c_str(), NULL, true);
|
||||
sJsCommands = "";
|
||||
if (!bIsNoError)
|
||||
return false;
|
||||
@ -1539,6 +1596,15 @@ namespace NSDoctRenderer
|
||||
return this->SetProperty(sA.c_str(), value);
|
||||
}
|
||||
|
||||
int CDocBuilder::GetPropertyInt(const wchar_t* param)
|
||||
{
|
||||
std::wstring sParam = std::wstring(param);
|
||||
std::string sParamA = U_TO_UTF8(sParam);
|
||||
if ("--save-use-only-names" == sParamA)
|
||||
return m_pInternal->m_bIsServerSafeVersion ? 1 : 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CDocBuilder::Initialize(const wchar_t* directory)
|
||||
{
|
||||
std::wstring sDirectory = L"";
|
||||
|
||||
@ -63,6 +63,8 @@
|
||||
|
||||
#include "../common/ProcessEnv.h"
|
||||
|
||||
#include "docbuilder_addon.h"
|
||||
|
||||
#ifdef CreateFile
|
||||
#undef CreateFile
|
||||
#endif
|
||||
@ -422,6 +424,7 @@ public:
|
||||
int m_nFileType;
|
||||
std::string m_sUtf8ArgumentJSON;
|
||||
std::string m_sGlobalVariable;
|
||||
std::string m_sJSCodeStart;
|
||||
|
||||
CJSContextData m_oContextData;
|
||||
|
||||
@ -434,14 +437,17 @@ public:
|
||||
|
||||
static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError);
|
||||
|
||||
bool ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue = NULL);
|
||||
bool ExecuteCommand(const std::wstring& command, NSDoctRenderer::CDocBuilderValue* retValue = NULL, const bool& isEnterContext = true);
|
||||
|
||||
std::string GetGlobalVariable();
|
||||
std::wstring GetJSVariable(std::wstring sParam);
|
||||
|
||||
bool OpenFile(const std::wstring& sBasePath, const std::wstring& path, const NSDoctRenderer::DoctRendererEditorType& editorType, NSDoctRenderer::CDoctRendererConfig* config, CV8Params* pParams = NULL);
|
||||
bool SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams = L"");
|
||||
bool SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams = L"", const bool& isEnterContext = true);
|
||||
bool InitVariables();
|
||||
|
||||
bool NewSimpleJSInstance();
|
||||
bool IsSimpleJSInstance();
|
||||
};
|
||||
|
||||
namespace NSDoctRenderer
|
||||
@ -455,7 +461,8 @@ namespace NSDoctRenderer
|
||||
std::wstring m_sTmpFolder;
|
||||
std::wstring m_sFileDir;
|
||||
int m_nFileType;
|
||||
bool m_bJavascriptBeforeEditor;
|
||||
|
||||
std::wstring m_sCommandsBeforeContextCreated;
|
||||
|
||||
std::wstring m_sX2tPath;
|
||||
|
||||
@ -474,11 +481,13 @@ namespace NSDoctRenderer
|
||||
|
||||
NSDoctRenderer::CDocBuilder* m_pParent;
|
||||
|
||||
bool m_bIsOpenedFromSimpleJS;
|
||||
|
||||
static std::wstring m_sExternalDirectory;
|
||||
public:
|
||||
CDocBuilder_Private() : CDoctRendererConfig(), m_sTmpFolder(NSFile::CFileBinary::GetTempPath()), m_nFileType(-1),
|
||||
m_pWorker(NULL), m_pAdditionalData(NULL), m_bIsInit(false), m_bIsServerSafeVersion(false),
|
||||
m_sGlobalVariable(""), m_bIsGlobalVariableUse(false), m_pParent(NULL), m_bJavascriptBeforeEditor(false)
|
||||
m_sGlobalVariable(""), m_bIsGlobalVariableUse(false), m_pParent(NULL), m_sCommandsBeforeContextCreated(L""), m_bIsOpenedFromSimpleJS(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -637,10 +646,14 @@ namespace NSDoctRenderer
|
||||
{
|
||||
NSDirectory::CreateDirectory(m_sFileDir + L"/media");
|
||||
NSDirectory::CreateDirectory(m_sFileDir + L"/changes");
|
||||
}
|
||||
|
||||
if (m_bJavascriptBeforeEditor)
|
||||
CheckWorkerAfterOpen();
|
||||
if (m_pWorker && m_pWorker->IsSimpleJSInstance() && !m_bIsOpenedFromSimpleJS)
|
||||
{
|
||||
RELEASEOBJECT(m_pWorker);
|
||||
CheckWorker();
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
return bRet;
|
||||
#else
|
||||
@ -931,8 +944,11 @@ namespace NSDoctRenderer
|
||||
|
||||
if (0 == nReturnCode)
|
||||
{
|
||||
if (m_bJavascriptBeforeEditor)
|
||||
CheckWorkerAfterOpen();
|
||||
if (m_pWorker && m_pWorker->IsSimpleJSInstance() && !m_bIsOpenedFromSimpleJS)
|
||||
{
|
||||
RELEASEOBJECT(m_pWorker);
|
||||
CheckWorker();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -981,10 +997,16 @@ namespace NSDoctRenderer
|
||||
return _path;
|
||||
}
|
||||
|
||||
int SaveFile(const int& type, const std::wstring& path, const wchar_t* params = NULL)
|
||||
int SaveFile(const int& type, const std::wstring& path, const wchar_t* params = NULL, const bool& isEnterContext = true)
|
||||
{
|
||||
Init();
|
||||
|
||||
CDocBuilderAddon oSaveAddon(m_sX2tPath);
|
||||
|
||||
int nPreSaveError = oSaveAddon.GetX2tPreSaveError(m_pParent, m_nFileType);
|
||||
if (0 != nPreSaveError)
|
||||
return nPreSaveError;
|
||||
|
||||
if (-1 == m_nFileType)
|
||||
{
|
||||
CV8RealTimeWorker::_LOGGING_ERROR_(L"error (save)", L"file not opened!");
|
||||
@ -1023,7 +1045,7 @@ namespace NSDoctRenderer
|
||||
}
|
||||
}
|
||||
|
||||
this->m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin", sJsonParams);
|
||||
this->m_pWorker->SaveFileWithChanges(type, m_sFileDir + L"/Editor2.bin", sJsonParams, isEnterContext);
|
||||
sFileBin = L"/Editor2.bin";
|
||||
}
|
||||
|
||||
@ -1068,6 +1090,8 @@ namespace NSDoctRenderer
|
||||
if (!sOptions.empty())
|
||||
oBuilder.WriteString(UTF8_TO_U(sOptions));
|
||||
|
||||
oBuilder.WriteString(oSaveAddon.GetX2tSaveAddon(m_pParent, m_nFileType));
|
||||
|
||||
oBuilder.WriteString(L"</TaskQueueDataConvert>");
|
||||
|
||||
std::wstring sXmlConvert = oBuilder.GetData();
|
||||
@ -1220,62 +1244,75 @@ namespace NSDoctRenderer
|
||||
{
|
||||
if (NULL == m_pWorker)
|
||||
{
|
||||
m_pWorker = new CV8RealTimeWorker(m_pParent, GetEditorType(), this);
|
||||
NSDoctRenderer::DoctRendererEditorType editorType = GetEditorType();
|
||||
m_pWorker = new CV8RealTimeWorker(m_pParent, editorType, this);
|
||||
m_pWorker->m_sUtf8ArgumentJSON = m_oParams.m_sArgumentJSON;
|
||||
m_pWorker->m_sGlobalVariable = m_sGlobalVariable;
|
||||
m_pWorker->m_sJSCodeStart = U_TO_UTF8(m_sCommandsBeforeContextCreated);
|
||||
|
||||
return CheckWorkerAfterOpen();
|
||||
m_pWorker->m_nFileType = m_nFileType;
|
||||
|
||||
if (-1 != m_nFileType)
|
||||
m_sCommandsBeforeContextCreated = L"";
|
||||
else
|
||||
{
|
||||
m_pWorker->NewSimpleJSInstance();
|
||||
return true;
|
||||
}
|
||||
|
||||
CV8Params oParams;
|
||||
oParams.IsServerSaveVersion = m_bIsServerSafeVersion;
|
||||
oParams.DocumentDirectory = m_sFileDir;
|
||||
|
||||
return m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, editorType, this, &oParams);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckWorkerAfterOpen()
|
||||
{
|
||||
if (!m_pWorker)
|
||||
return false;
|
||||
|
||||
m_pWorker->m_nFileType = m_nFileType;
|
||||
if (-1 == m_nFileType)
|
||||
{
|
||||
m_bJavascriptBeforeEditor = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bJavascriptBeforeEditor = false;
|
||||
|
||||
CV8Params oParams;
|
||||
oParams.IsServerSaveVersion = m_bIsServerSafeVersion;
|
||||
oParams.DocumentDirectory = m_sFileDir;
|
||||
|
||||
return m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, GetEditorType(), this, &oParams);
|
||||
}
|
||||
|
||||
int SaveFile(const std::wstring& ext, const std::wstring& path, const wchar_t* params = NULL)
|
||||
{
|
||||
int nType = GetFormatByTexExtention(ext);
|
||||
return SaveFile(nType, path, params);
|
||||
}
|
||||
|
||||
bool ExecuteCommand(const std::wstring& command, CDocBuilderValue* retValue = NULL)
|
||||
bool ExecuteCommand(const std::wstring& command, CDocBuilderValue* retValue = NULL, const bool& forceExecute = false)
|
||||
{
|
||||
if (command.length() < 7 && !retValue) // minimum command (!!!)
|
||||
return true;
|
||||
|
||||
if (m_nFileType == -1 && !forceExecute)
|
||||
{
|
||||
m_sCommandsBeforeContextCreated += command;
|
||||
return true;
|
||||
}
|
||||
|
||||
Init();
|
||||
|
||||
bool bRes = CheckWorker();
|
||||
if (CheckWorker())
|
||||
{
|
||||
bool bIsOpenedFromSimpleJSOld = m_bIsOpenedFromSimpleJS;
|
||||
bool bResult = m_pWorker->ExecuteCommand(command, retValue);
|
||||
if (!bResult && !bIsOpenedFromSimpleJSOld && m_bIsOpenedFromSimpleJS)
|
||||
{
|
||||
RELEASEOBJECT(m_pWorker);
|
||||
CheckWorker();
|
||||
return m_pWorker->ExecuteCommand(command, retValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return bResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bRes && m_pWorker && m_bJavascriptBeforeEditor)
|
||||
m_pWorker->InitVariables();
|
||||
|
||||
return m_pWorker->ExecuteCommand(command, retValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
CDocBuilderContext GetContext(bool enterContext)
|
||||
{
|
||||
CDocBuilderContext ctx;
|
||||
|
||||
CheckWorker();
|
||||
if (!CheckWorker())
|
||||
return ctx;
|
||||
|
||||
ctx.m_internal->m_context = m_pWorker->m_context;
|
||||
ctx.m_internal->m_context_data = &m_pWorker->m_oContextData;
|
||||
|
||||
@ -986,7 +986,7 @@ namespace NSDoctRenderer
|
||||
case DoctRendererFormat::IMAGE:
|
||||
{
|
||||
editorType = NSDoctRenderer::DoctRendererEditorType::VISIO;
|
||||
m_pInternal->m_strEditorType = L"draw";
|
||||
m_pInternal->m_strEditorType = L"visio";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
130
DesktopEditor/doctrenderer/doctrenderer.pri
Normal file
130
DesktopEditor/doctrenderer/doctrenderer.pri
Normal file
@ -0,0 +1,130 @@
|
||||
QT -= core
|
||||
QT -= gui
|
||||
|
||||
VERSION = 1.0.0.3
|
||||
TARGET = doctrenderer
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += shared
|
||||
CONFIG += plugin
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
|
||||
PWD_CUR = $$PWD
|
||||
include($$PWD_CUR/../../Common/base.pri)
|
||||
|
||||
DEFINES += DOCTRENDERER_USE_DYNAMIC_LIBRARY_BUILDING
|
||||
DEFINES += JSBASE_USE_DYNAMIC_LIBRARY_BUILDING
|
||||
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network)
|
||||
|
||||
#CONFIG += build_xp
|
||||
#CONFIG += v8_version_60
|
||||
core_android:DEFINES += DISABLE_MEMORY_LIMITATION
|
||||
|
||||
HEADERS += \
|
||||
$$PWD_CUR/config.h \
|
||||
$$PWD_CUR/editors.h \
|
||||
$$PWD_CUR/doctrenderer.h \
|
||||
$$PWD_CUR/docbuilder.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD_CUR/editors.cpp \
|
||||
$$PWD_CUR/nativecontrol.cpp \
|
||||
$$PWD_CUR/doctrenderer.cpp \
|
||||
$$PWD_CUR/docbuilder.cpp \
|
||||
$$PWD_CUR/docbuilder_p.cpp \
|
||||
$$PWD_CUR/graphics.cpp \
|
||||
$$PWD_CUR/hash.cpp
|
||||
|
||||
SOURCES += \
|
||||
$$PWD_CUR/../../Common/OfficeFileFormatChecker2.cpp \
|
||||
$$PWD_CUR/../../Common/3dParty/pole/pole.cpp \
|
||||
$$PWD_CUR/../../OOXML/Base/unicode_util.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD_CUR/docbuilder_p.h \
|
||||
$$PWD_CUR/nativecontrol.h \
|
||||
$$PWD_CUR/graphics.h \
|
||||
$$PWD_CUR/hash.h \
|
||||
$$PWD_CUR/server.h
|
||||
|
||||
HEADERS += \
|
||||
$$PWD_CUR/embed/PointerEmbed.h \
|
||||
$$PWD_CUR/embed/ZipEmbed.h \
|
||||
$$PWD_CUR/embed/GraphicsEmbed.h \
|
||||
$$PWD_CUR/embed/MemoryStreamEmbed.h \
|
||||
$$PWD_CUR/embed/NativeControlEmbed.h \
|
||||
$$PWD_CUR/embed/NativeBuilderEmbed.h \
|
||||
$$PWD_CUR/embed/NativeBuilderDocumentEmbed.h \
|
||||
$$PWD_CUR/embed/TextMeasurerEmbed.h \
|
||||
$$PWD_CUR/embed/HashEmbed.h \
|
||||
$$PWD_CUR/embed/Default.h \
|
||||
$$PWD_CUR/js_internal/js_base.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD_CUR/embed/PointerEmbed.cpp \
|
||||
$$PWD_CUR/embed/ZipEmbed.cpp \
|
||||
$$PWD_CUR/embed/GraphicsEmbed.cpp \
|
||||
$$PWD_CUR/embed/MemoryStreamEmbed.cpp \
|
||||
$$PWD_CUR/embed/NativeControlEmbed.cpp \
|
||||
$$PWD_CUR/embed/NativeBuilderEmbed.cpp \
|
||||
$$PWD_CUR/embed/NativeBuilderDocumentEmbed.cpp \
|
||||
$$PWD_CUR/embed/TextMeasurerEmbed.cpp \
|
||||
$$PWD_CUR/embed/HashEmbed.cpp \
|
||||
$$PWD_CUR/embed/Default.cpp
|
||||
|
||||
# Serialize objects to JS
|
||||
HEADERS += \
|
||||
$$PWD_CUR/json/json.h \
|
||||
$$PWD_CUR/json/json_p.h \
|
||||
$$PWD_CUR/json/json_values.h \
|
||||
$$PWD_CUR/json/serialization.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD_CUR/json/json.cpp \
|
||||
$$PWD_CUR/json/json_values.cpp
|
||||
|
||||
include($$PWD_CUR/js_internal/js_base.pri)
|
||||
|
||||
!use_javascript_core {
|
||||
build_xp:DESTDIR=$$DESTDIR/xp
|
||||
}
|
||||
|
||||
use_javascript_core {
|
||||
OBJECTIVE_SOURCES += $$PWD_CUR/../common/Mac/NSString+StringUtils.mm
|
||||
}
|
||||
|
||||
# files for embedded classes
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/GraphicsEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/HashEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/MemoryStreamEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/NativeBuilderEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/NativeBuilderDocumentEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/NativeControlEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/PointerEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/TextMeasurerEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/ZipEmbed.h)
|
||||
|
||||
include($$PWD_CUR/../graphics/pro/textshaper.pri)
|
||||
include($$PWD_CUR/../../Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
# downloader
|
||||
DEFINES += BUIDLER_OPEN_DOWNLOAD_ENABLED
|
||||
DEFINES += BUIDLER_OPEN_BASE64_ENABLED
|
||||
|
||||
CONFIG += drawingfile_support
|
||||
drawingfile_support {
|
||||
DEFINES += WASM_SERIALIZER_USE_ALLOCATOR
|
||||
ADD_DEPENDENCY(PdfFile, XpsFile, DjVuFile, DocxRenderer)
|
||||
|
||||
HEADERS += \
|
||||
$$PWD_CUR/drawingfile.h \
|
||||
$$PWD_CUR/embed/DrawingFileEmbed.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD_CUR/../graphics/pro/js/wasm/src/HTMLRendererText.cpp \
|
||||
$$PWD_CUR/embed/DrawingFileEmbed.cpp
|
||||
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER($$PWD_CUR/embed/DrawingFileEmbed.h)
|
||||
}
|
||||
@ -1,128 +1,3 @@
|
||||
QT -= core
|
||||
QT -= gui
|
||||
INCLUDEPATH += $$PWD/addon
|
||||
|
||||
VERSION = 1.0.0.3
|
||||
TARGET = doctrenderer
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += shared
|
||||
CONFIG += plugin
|
||||
|
||||
CORE_ROOT_DIR = $$PWD/../..
|
||||
PWD_ROOT_DIR = $$PWD
|
||||
include(../../Common/base.pri)
|
||||
|
||||
DEFINES += DOCTRENDERER_USE_DYNAMIC_LIBRARY_BUILDING
|
||||
DEFINES += JSBASE_USE_DYNAMIC_LIBRARY_BUILDING
|
||||
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network)
|
||||
|
||||
#CONFIG += build_xp
|
||||
#CONFIG += v8_version_60
|
||||
core_android:DEFINES += DISABLE_MEMORY_LIMITATION
|
||||
|
||||
HEADERS += \
|
||||
config.h \
|
||||
editors.h \
|
||||
doctrenderer.h \
|
||||
docbuilder.h
|
||||
|
||||
SOURCES += \
|
||||
editors.cpp \
|
||||
nativecontrol.cpp \
|
||||
doctrenderer.cpp \
|
||||
docbuilder.cpp \
|
||||
docbuilder_p.cpp \
|
||||
graphics.cpp \
|
||||
hash.cpp
|
||||
|
||||
SOURCES += \
|
||||
../../Common/OfficeFileFormatChecker2.cpp \
|
||||
../../Common/3dParty/pole/pole.cpp \
|
||||
../../OOXML/Base/unicode_util.cpp
|
||||
|
||||
HEADERS += \
|
||||
docbuilder_p.h \
|
||||
nativecontrol.h \
|
||||
graphics.h \
|
||||
hash.h \
|
||||
server.h
|
||||
|
||||
HEADERS += \
|
||||
embed/PointerEmbed.h \
|
||||
embed/ZipEmbed.h \
|
||||
embed/GraphicsEmbed.h \
|
||||
embed/MemoryStreamEmbed.h \
|
||||
embed/NativeControlEmbed.h \
|
||||
embed/NativeBuilderEmbed.h \
|
||||
embed/NativeBuilderDocumentEmbed.h \
|
||||
embed/TextMeasurerEmbed.h \
|
||||
embed/HashEmbed.h \
|
||||
embed/Default.h \
|
||||
js_internal/js_base.h
|
||||
|
||||
SOURCES += \
|
||||
embed/PointerEmbed.cpp \
|
||||
embed/ZipEmbed.cpp \
|
||||
embed/GraphicsEmbed.cpp \
|
||||
embed/MemoryStreamEmbed.cpp \
|
||||
embed/NativeControlEmbed.cpp \
|
||||
embed/NativeBuilderEmbed.cpp \
|
||||
embed/NativeBuilderDocumentEmbed.cpp \
|
||||
embed/TextMeasurerEmbed.cpp \
|
||||
embed/HashEmbed.cpp \
|
||||
embed/Default.cpp
|
||||
|
||||
# Serialize objects to JS
|
||||
HEADERS += \
|
||||
json/json.h \
|
||||
json/json_p.h \
|
||||
json/json_values.h \
|
||||
json/serialization.h
|
||||
|
||||
SOURCES += \
|
||||
json/json.cpp \
|
||||
json/json_values.cpp
|
||||
|
||||
include($$PWD/js_internal/js_base.pri)
|
||||
|
||||
!use_javascript_core {
|
||||
build_xp:DESTDIR=$$DESTDIR/xp
|
||||
}
|
||||
|
||||
use_javascript_core {
|
||||
OBJECTIVE_SOURCES += ../common/Mac/NSString+StringUtils.mm
|
||||
}
|
||||
|
||||
# files for embedded classes
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/GraphicsEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/HashEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/MemoryStreamEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/NativeBuilderEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/NativeBuilderDocumentEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/NativeControlEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/PointerEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/TextMeasurerEmbed.h)
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/ZipEmbed.h)
|
||||
|
||||
include(../graphics/pro/textshaper.pri)
|
||||
include(../../Common/3dParty/openssl/openssl.pri)
|
||||
|
||||
# downloader
|
||||
DEFINES += BUIDLER_OPEN_DOWNLOAD_ENABLED
|
||||
DEFINES += BUIDLER_OPEN_BASE64_ENABLED
|
||||
|
||||
CONFIG += drawingfile_support
|
||||
drawingfile_support {
|
||||
DEFINES += WASM_SERIALIZER_USE_ALLOCATOR
|
||||
ADD_DEPENDENCY(PdfFile, XpsFile, DjVuFile, DocxRenderer)
|
||||
|
||||
HEADERS += \
|
||||
drawingfile.h \
|
||||
embed/DrawingFileEmbed.h
|
||||
|
||||
SOURCES += \
|
||||
../graphics/pro/js/wasm/src/HTMLRendererText.cpp \
|
||||
embed/DrawingFileEmbed.cpp
|
||||
|
||||
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/DrawingFileEmbed.h)
|
||||
}
|
||||
include(doctrenderer.pri)
|
||||
|
||||
@ -6,16 +6,16 @@ namespace NSDoctRenderer
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void AppendScript(NSStringUtils::CStringBuilderA* builder, const std::wstring& path)
|
||||
bool AppendScript(NSStringUtils::CStringBuilderA* builder, const std::wstring& path, const std::string& header = "", const std::string& footer = "")
|
||||
{
|
||||
NSFile::CFileBinary oFile;
|
||||
|
||||
if (!oFile.OpenFile(path))
|
||||
return;
|
||||
return false;
|
||||
|
||||
int size = (int)oFile.GetFileSize();
|
||||
if (size < 3)
|
||||
return;
|
||||
return false;
|
||||
|
||||
BYTE* pData = new BYTE[size];
|
||||
DWORD dwReadSize = 0;
|
||||
@ -26,9 +26,18 @@ namespace NSDoctRenderer
|
||||
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
|
||||
nOffset = 3;
|
||||
|
||||
if (!header.empty())
|
||||
builder->WriteString(header);
|
||||
|
||||
builder->WriteString((char*)(pData + nOffset), size - nOffset);
|
||||
|
||||
if (!footer.empty())
|
||||
builder->WriteString(footer);
|
||||
|
||||
builder->WriteString("\n\n");
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RunScript(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, const std::wstring& path)
|
||||
@ -114,6 +123,7 @@ namespace NSDoctRenderer
|
||||
AppendScript(builder, sFontsPath);
|
||||
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
|
||||
AppendScript(builder, config->m_strSdkPath + L"/pdf/src/engine/drawingfile_native.js");
|
||||
AppendScript(builder, config->m_strSdkPath + L"/pdf/src/annotations/stamps.json", "window[\"native_pdf_stamps\"]=", ";");
|
||||
sCachePath = config->m_strSdkPath + L"/pdf/sdk-all";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "DrawingFileEmbed.h"
|
||||
#include "../drawingfile.h"
|
||||
#include "../../raster/BgraFrame.h"
|
||||
|
||||
JSSmart<CJSValue> WasmMemoryToJS(BYTE* pWasmData)
|
||||
{
|
||||
|
||||
@ -160,16 +160,30 @@ void CGraphicsEmbed::SetAppImage(CGraphicsAppImage* appImage)
|
||||
|
||||
JSSmart<CJSValue> CGraphicsEmbed::create(JSSmart<CJSValue> Native, JSSmart<CJSValue> width_px, JSSmart<CJSValue> height_px, JSSmart<CJSValue> width_mm, JSSmart<CJSValue> height_mm)
|
||||
{
|
||||
NSNativeControl::CNativeControl* pControl = NULL;
|
||||
if (!Native->isNull())
|
||||
{
|
||||
pControl = (NSNativeControl::CNativeControl*)Native->toObject()->getNative()->getObject();
|
||||
JSSmart<CJSObject> pNativeObject = Native->toObject();
|
||||
CJSEmbedObject* pNativeEmbedObject = pNativeObject->getNative();
|
||||
|
||||
if (m_pInternal->m_pAppImage)
|
||||
delete m_pInternal->m_pAppImage;
|
||||
m_pInternal->m_pAppImage = new CGraphicsAppImage();
|
||||
m_pInternal->m_pAppImage->SetFontsDirectory(pControl->m_strFontsDirectory);
|
||||
m_pInternal->m_pAppImage->SetImagesDirectory(pControl->m_strImagesDirectory);
|
||||
|
||||
if (pNativeEmbedObject)
|
||||
{
|
||||
NSNativeControl::CNativeControl* pControl = (NSNativeControl::CNativeControl*)pNativeEmbedObject->getObject();
|
||||
m_pInternal->m_pAppImage->SetFontsDirectory(pControl->m_strFontsDirectory);
|
||||
m_pInternal->m_pAppImage->SetImagesDirectory(pControl->m_strImagesDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
JSSmart<CJSValue> checkResources = pNativeObject->get("isResourcesObject");
|
||||
if (checkResources->isBool() && true == checkResources->toBool())
|
||||
{
|
||||
m_pInternal->m_pAppImage->SetFontsDirectory(pNativeObject->get("fontsDirectory")->toStringW());
|
||||
m_pInternal->m_pAppImage->SetImagesDirectory(pNativeObject->get("imagesDirectory")->toStringW());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_pInternal->init(width_px->toDouble(), height_px->toDouble(), width_mm->toDouble(), height_mm->toDouble());
|
||||
|
||||
@ -8,7 +8,22 @@ JSSmart<CJSValue> CBuilderEmbed::OpenFile(JSSmart<CJSValue> sPath, JSSmart<CJSVa
|
||||
{
|
||||
std::wstring Path = sPath->toStringW();
|
||||
std::wstring Params = sParams->toStringW();
|
||||
|
||||
// Since we now use snapshots, and we can't always determine which editor is needed
|
||||
// (since the code may be BEFORE opening the file). And if the opening came from
|
||||
// builderJS.OpenFile - in this case we skip reopening.
|
||||
NSDoctRenderer::CDocBuilder_Private* pPrivate = GetPrivate();
|
||||
if (pPrivate->m_pWorker->IsSimpleJSInstance())
|
||||
pPrivate->m_bIsOpenedFromSimpleJS = true;
|
||||
|
||||
int ret = m_pBuilder->OpenFile(Path.c_str(), Params.c_str());
|
||||
|
||||
if (pPrivate->m_pWorker->IsSimpleJSInstance())
|
||||
{
|
||||
JSSmart<CJSContext> current = CJSContext::GetCurrent();
|
||||
current->runScript("throw 0;");
|
||||
}
|
||||
|
||||
return CJSContext::createInt(ret);
|
||||
}
|
||||
|
||||
@ -20,7 +35,21 @@ JSSmart<CJSValue> CBuilderEmbed::CreateFile(JSSmart<CJSValue> type)
|
||||
else
|
||||
nFormat = type->toInt32();
|
||||
|
||||
// Since we now use snapshots, and we can't always determine which editor is needed
|
||||
// (since the code may be BEFORE opening the file). And if the opening came from
|
||||
// builderJS.OpenFile - in this case we skip reopening.
|
||||
NSDoctRenderer::CDocBuilder_Private* pPrivate = GetPrivate();
|
||||
if (pPrivate->m_pWorker->IsSimpleJSInstance())
|
||||
pPrivate->m_bIsOpenedFromSimpleJS = true;
|
||||
|
||||
bool ret = m_pBuilder->CreateFile(nFormat);
|
||||
|
||||
if (pPrivate->m_pWorker->IsSimpleJSInstance())
|
||||
{
|
||||
JSSmart<CJSContext> current = CJSContext::GetCurrent();
|
||||
current->runScript("throw 0;");
|
||||
}
|
||||
|
||||
return CJSContext::createBool(ret);
|
||||
}
|
||||
|
||||
@ -41,7 +70,7 @@ JSSmart<CJSValue> CBuilderEmbed::SaveFile(JSSmart<CJSValue> type, JSSmart<CJSVal
|
||||
|
||||
std::wstring sPath = path->toStringW();
|
||||
std::wstring sParams = params->toStringW();
|
||||
int ret = m_pBuilder->SaveFile(nFormat, sPath.c_str(), sParams.empty() ? NULL : sParams.c_str());
|
||||
int ret = GetPrivate()->SaveFile(nFormat, sPath.c_str(), sParams.empty() ? NULL : sParams.c_str(), false);
|
||||
return CJSContext::createInt(ret);
|
||||
}
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ public:
|
||||
~CBuilderEmbed() { if(m_pBuilder) RELEASEOBJECT(m_pBuilder); }
|
||||
|
||||
virtual void* getObject() { return (void*)m_pBuilder; }
|
||||
NSDoctRenderer::CDocBuilder_Private* GetPrivate() { return m_pBuilder->GetPrivate(); }
|
||||
|
||||
public:
|
||||
JSSmart<CJSValue> OpenFile(JSSmart<CJSValue> sPath, JSSmart<CJSValue> sParams);
|
||||
|
||||
@ -258,3 +258,64 @@ JSSmart<CJSValue> CZipEmbed::getImageType(JSSmart<CJSValue> typedArray)
|
||||
oBuffer.Free();
|
||||
return CJSContext::createInt(bIsImageFile ? oChecker.eFileType : 0);
|
||||
}
|
||||
|
||||
JSSmart<CJSValue> CZipEmbed::getImageBuffer(JSSmart<CJSValue> filePath)
|
||||
{
|
||||
if (!m_pFolder || !filePath->isString())
|
||||
return CJSContext::createNull();
|
||||
|
||||
std::wstring sFilePath = filePath->toStringW();
|
||||
IFolder::CBuffer* pBuffer;
|
||||
if (!m_pFolder->read(sFilePath, pBuffer))
|
||||
return CJSContext::createNull();
|
||||
|
||||
size_t nBufferSize = (size_t)pBuffer->Size;
|
||||
|
||||
CImageFileFormatChecker oChecker;
|
||||
bool bIsImageFile = oChecker.isImageFile(pBuffer->Buffer, (DWORD)pBuffer->Size);
|
||||
|
||||
if (!bIsImageFile)
|
||||
{
|
||||
RELEASEOBJECT(pBuffer);
|
||||
return CJSContext::createNull();
|
||||
}
|
||||
|
||||
bool bIsNeedConvertMetfileToSvg = false;
|
||||
|
||||
// Make as wasm module
|
||||
if (oChecker.eFileType == _CXIMAGE_FORMAT_WMF || oChecker.eFileType == _CXIMAGE_FORMAT_EMF)
|
||||
oChecker.eFileType = _CXIMAGE_FORMAT_SVG;
|
||||
else
|
||||
bIsNeedConvertMetfileToSvg = false;
|
||||
|
||||
if (!bIsNeedConvertMetfileToSvg)
|
||||
{
|
||||
BYTE* pMemory = NSJSBase::NSAllocator::Alloc(nBufferSize);
|
||||
memcpy(pMemory, pBuffer->Buffer, nBufferSize);
|
||||
RELEASEOBJECT(pBuffer);
|
||||
|
||||
JSSmart<CJSObject> retObject = CJSContext::createObject();
|
||||
retObject->set("type", CJSContext::createInt(oChecker.eFileType));
|
||||
retObject->set("data", NSJSBase::CJSContext::createUint8Array(pMemory, (int)nBufferSize, false));
|
||||
return retObject->toValue();
|
||||
}
|
||||
|
||||
#ifndef GRAPHICS_DISABLE_METAFILE
|
||||
MetaFile::IMetaFile* pMetaFile = MetaFile::Create(NULL);
|
||||
pMetaFile->LoadFromBuffer(pBuffer->Buffer, (unsigned int)pBuffer->Size);
|
||||
std::wstring wsSvg = pMetaFile->ConvertToSvg();
|
||||
std::string sSvg = U_TO_UTF8(wsSvg);
|
||||
pMetaFile->Release();
|
||||
RELEASEOBJECT(pBuffer);
|
||||
|
||||
BYTE* pData = NSAllocator::Alloc(sSvg.length());
|
||||
memcpy(pData, sSvg.c_str(), sSvg.length());
|
||||
|
||||
JSSmart<CJSObject> retObject = CJSContext::createObject();
|
||||
retObject->set("type", CJSContext::createInt(24));
|
||||
retObject->set("data", NSJSBase::CJSContext::createUint8Array(pData, sSvg.length(), false));
|
||||
return retObject->toValue();
|
||||
#else
|
||||
return CJSContext::createNull();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ public:
|
||||
JSSmart<CJSValue> encodeImageData(JSSmart<CJSValue> typedArray, JSSmart<CJSValue> w, JSSmart<CJSValue> h, JSSmart<CJSValue> stride, JSSmart<CJSValue> format, JSSmart<CJSValue> isRgba);
|
||||
JSSmart<CJSValue> encodeImage(JSSmart<CJSValue> typedArray, JSSmart<CJSValue> format);
|
||||
JSSmart<CJSValue> getImageType(JSSmart<CJSValue> typedArray);
|
||||
JSSmart<CJSValue> getImageBuffer(JSSmart<CJSValue> path);
|
||||
|
||||
DECLARE_EMBED_METHODS
|
||||
};
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
-(JSValue*) encodeImageData : (JSValue*)typedArray : (JSValue*)w : (JSValue*)h : (JSValue*)stride : (JSValue*)format : (JSValue*)isRgba;
|
||||
-(JSValue*) encodeImage : (JSValue*)typedArray : (JSValue*)format;
|
||||
-(JSValue*) getImageType : (JSValue*)typedArray;
|
||||
-(JSValue*) getImageBuffer : (JSValue*)path;
|
||||
@end
|
||||
|
||||
@interface CJSCZipEmbed : NSObject<IJSCZipEmbed, JSEmbedObjectProtocol>
|
||||
@ -41,6 +42,7 @@ FUNCTION_WRAPPER_JS_2(decodeImage, decodeImage)
|
||||
FUNCTION_WRAPPER_JS_6(encodeImageData, encodeImageData)
|
||||
FUNCTION_WRAPPER_JS_2(encodeImage, encodeImage)
|
||||
FUNCTION_WRAPPER_JS_1(getImageType, getImageType)
|
||||
FUNCTION_WRAPPER_JS_1(getImageBuffer, getImageBuffer)
|
||||
@end
|
||||
|
||||
class CZipEmbedAdapter : public CJSEmbedObjectAdapterJSC
|
||||
|
||||
@ -20,6 +20,7 @@ namespace NSZipEmbed
|
||||
FUNCTION_WRAPPER_V8_6(_encodeImageData, encodeImageData)
|
||||
FUNCTION_WRAPPER_V8_2(_encodeImage, encodeImage)
|
||||
FUNCTION_WRAPPER_V8_1(_getImageType, getImageType)
|
||||
FUNCTION_WRAPPER_V8_1(_getImageBuffer, getImageBuffer)
|
||||
|
||||
v8::Handle<v8::ObjectTemplate> CreateTemplate(v8::Isolate* isolate)
|
||||
{
|
||||
@ -39,6 +40,7 @@ namespace NSZipEmbed
|
||||
NSV8Objects::Template_Set(result, "encodeImageData", _encodeImageData);
|
||||
NSV8Objects::Template_Set(result, "encodeImage", _encodeImage);
|
||||
NSV8Objects::Template_Set(result, "getImageType", _getImageType);
|
||||
NSV8Objects::Template_Set(result, "getImageBuffer", _getImageBuffer);
|
||||
|
||||
return handle_scope.Escape(result);
|
||||
}
|
||||
|
||||
@ -374,7 +374,7 @@ namespace NSJSBase
|
||||
|
||||
JSSmart<CJSContext> CJSContext::GetCurrent()
|
||||
{
|
||||
CJSContext* ret = new CJSContext();
|
||||
CJSContext* ret = new CJSContext(false);
|
||||
ret->m_internal->context = NSJSBase::CJSContextPrivate::GetCurrentContext();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -356,6 +356,8 @@ public:
|
||||
|
||||
virtual void Check(const int& nCode, const unsigned int& nIndex)
|
||||
{
|
||||
if (nCode > m_nMaxSymbols)
|
||||
return;
|
||||
if (nCode > m_nMax)
|
||||
m_nMax = nCode;
|
||||
if (nCode < m_nMin)
|
||||
@ -794,6 +796,8 @@ public:
|
||||
std::wstring sNameCorrect = pPair->second.m_sName;
|
||||
NSStringUtils::string_replace(sNameCorrect, L"\\", L"\\\\");
|
||||
NSStringUtils::string_replace(sNameCorrect, L"\"", L"\\\"");
|
||||
NSStringUtils::string_replace(sNameCorrect, L"\n", L"");
|
||||
NSStringUtils::string_replace(sNameCorrect, L"\r", L"");
|
||||
oWriterJS += sNameCorrect;
|
||||
|
||||
oWriterJS.AddSize(120);
|
||||
|
||||
@ -693,6 +693,13 @@ namespace NSShaper
|
||||
g_userfeatures_init = true;
|
||||
}
|
||||
|
||||
// Turn on ligatures on arabic script
|
||||
if (nScript == HB_SCRIPT_ARABIC ||
|
||||
nScript == HB_SCRIPT_SYRIAC)
|
||||
{
|
||||
nFeatures |= 1;
|
||||
}
|
||||
|
||||
// font
|
||||
hb_font_t* pFont;
|
||||
if (NULL == font)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
* (c) Copyright Ascensio System SIA 2010-2024
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
* (c) Copyright Ascensio System SIA 2010-2024
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
@ -594,6 +594,13 @@ WASM_EXPORT unsigned char* ASC_HB_ShapeText(FT_Face pFace, hb_font_t* pFont, cha
|
||||
g_userfeatures_init = true;
|
||||
}
|
||||
|
||||
// Turn on ligatures on arabic script
|
||||
if (nScript == HB_SCRIPT_ARABIC ||
|
||||
nScript == HB_SCRIPT_SYRIAC)
|
||||
{
|
||||
nFeatures |= 1;
|
||||
}
|
||||
|
||||
// font
|
||||
if (NULL == pFont)
|
||||
{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
* (c) Copyright Ascensio System SIA 2010-2024
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
@ -531,6 +531,45 @@ ZLib.prototype.getImageAsSvg = function(path)
|
||||
|
||||
return string;
|
||||
};
|
||||
/**
|
||||
* Get image file raw data. this memory was copied and detach from archive.
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
ZLib.prototype.getImageBuffer = function(path)
|
||||
{
|
||||
let result = {
|
||||
type : 0,
|
||||
data : null
|
||||
};
|
||||
result.type = this.getImageType(path);
|
||||
if (result.type === 0)
|
||||
return null;
|
||||
|
||||
let fileData = this.getFile(path);
|
||||
result.data = new Uint8Array(fileData.length);
|
||||
result.data.set(fileData);
|
||||
|
||||
if (result.type != 10 &&
|
||||
result.type != 21)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result.type = 24;
|
||||
// Source was saved as result.data for using original image in native convertations.
|
||||
// But for js we need svg for metafiles.
|
||||
|
||||
let encodedData = Module["_Raster_Encode"](this.files[path].p + 4, fileData.length, 24);
|
||||
let encodedSize = Module["_Raster_GetEncodedSize"](encodedData);
|
||||
let encodedBuffer = Module["_Raster_GetEncodedBuffer"](encodedData);
|
||||
|
||||
let fileDataEnc = new Uint8Array(Module["HEAP8"].buffer, encodedBuffer, encodedSize);
|
||||
result.dataBlob = new Uint8Array(fileDataEnc.length);
|
||||
result.dataBlob.set(fileDataEnc);
|
||||
|
||||
Module["_Raster_DestroyEncodedData"](encodedData);
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* Get image blob for browser
|
||||
* @returns {Blob}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
* (c) Copyright Ascensio System SIA 2010-2024
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
@ -35,7 +35,7 @@
|
||||
window['AscFonts'] = window['AscFonts'] || {};
|
||||
var AscFonts = window['AscFonts'];
|
||||
|
||||
var g_native_engine = CreateEmbedObject("CTextMeasurerEmbed");
|
||||
var g_native_engine = null;
|
||||
|
||||
function CReturnObject()
|
||||
{
|
||||
@ -236,4 +236,6 @@ AscFonts.Hyphen_Word = function(lang, word)
|
||||
AscFonts.onLoadModule();
|
||||
AscFonts.onLoadModule();
|
||||
|
||||
window["InitNativeTextMeasurer"] = function() { g_native_engine = CreateEmbedObject("CTextMeasurerEmbed"); };
|
||||
|
||||
})(window, undefined);
|
||||
|
||||
@ -100,6 +100,7 @@
|
||||
"FT_CONFIG_OPTION_SYSTEM_ZLIB",
|
||||
"GRAPHICS_NO_USE_DYNAMIC_LIBRARY",
|
||||
"HYPHEN_ENGINE_DISABLE_FILESYSTEM",
|
||||
"METAFILE_DISABLE_FILESYSTEM",
|
||||
|
||||
"HAVE_UNISTD_H", "HAVE_FCNTL_H", "_ARM_ALIGN_",
|
||||
"METAFILE_SUPPORT_WMF_EMF",
|
||||
@ -259,10 +260,13 @@
|
||||
"folder": "../../../OfficeUtils/js",
|
||||
"files": ["../src/ZipBuffer.cpp", "wasm/src/base.cpp", "../src/zlib_addon.c"]
|
||||
},
|
||||
|
||||
{
|
||||
"folder": "../../",
|
||||
"files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp"]
|
||||
"files": ["graphics/Image.cpp", "raster/BgraFrame.cpp", "raster/ImageFileFormatChecker.cpp", "graphics/Matrix.cpp"]
|
||||
},
|
||||
{
|
||||
"folder": "../../agg-2.4/src/",
|
||||
"files": ["agg_trans_affine.cpp"]
|
||||
},
|
||||
{
|
||||
"folder": "../../raster/",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
* (c) Copyright Ascensio System SIA 2010-2024
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
@ -761,6 +761,14 @@ function onLoadFontsModule(window, undefined)
|
||||
{
|
||||
return this.engine["getImageBlob"](path);
|
||||
};
|
||||
/**
|
||||
* Get image file raw data. this memory was copied and detach from archive.
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
ZLib.prototype.getImageBuffer = function(path)
|
||||
{
|
||||
return this.engine["getImageBuffer"](path);
|
||||
};
|
||||
/**
|
||||
* Get all file paths in archive
|
||||
* @returns {Array}
|
||||
@ -772,10 +780,84 @@ function onLoadFontsModule(window, undefined)
|
||||
|
||||
AscCommon.ZLib = ZLib;
|
||||
|
||||
function ZlibImageBlobs()
|
||||
{
|
||||
this.url2BlobUrl = {};
|
||||
this.blobUrl2Data = {};
|
||||
this.url2Base64 = {};
|
||||
|
||||
this.nativeBlobCounter = 1;
|
||||
}
|
||||
ZlibImageBlobs.prototype.getBlobUrl = function(path, zip)
|
||||
{
|
||||
if (this.url2BlobUrl[path])
|
||||
return this.url2BlobUrl[path];
|
||||
|
||||
let result = zip.getImageBuffer(path);
|
||||
if (result == null)
|
||||
return "";
|
||||
|
||||
let blobUrl = "";
|
||||
let blobType = AscCommon.openXml.GetMimeType((24 !== result["type"]) ? AscCommon.GetFileExtension(path) : "svg");
|
||||
|
||||
if (window["NATIVE_EDITOR_ENJINE"])
|
||||
{
|
||||
blobUrl = "blob:internal-image" + this.nativeBlobCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
let blob = new Blob([result["dataBlob"] ? result["dataBlob"] : result["data"]], {type: blobType});
|
||||
blobUrl = window.URL.createObjectURL(blob);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
blobUrl = "error";
|
||||
AscCommon.consoleLog("ERROR: Image blob was not loaded");
|
||||
}
|
||||
}
|
||||
|
||||
this.blobUrl2Data[blobUrl] = result;
|
||||
this.url2BlobUrl[path] = blobUrl;
|
||||
return blobUrl;
|
||||
};
|
||||
ZlibImageBlobs.prototype.getImageBase64 = function(url)
|
||||
{
|
||||
if (this.url2Base64[url])
|
||||
return this.url2Base64[url];
|
||||
|
||||
let obj = this.blobUrl2Data[url];
|
||||
if (!obj)
|
||||
return url;
|
||||
|
||||
let header = "";
|
||||
switch (obj.type)
|
||||
{
|
||||
case 3:
|
||||
header = "data:image/jpeg;base64,";
|
||||
break;
|
||||
case 24:
|
||||
header = "data:image/svg+xml;base64,";
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
header = "data:image/png;base64,";
|
||||
}
|
||||
|
||||
this.url2Base64[url] = header + AscCommon.Base64.encode(obj.data);
|
||||
return this.url2Base64[url];
|
||||
};
|
||||
|
||||
window["AscCommon"].g_oDocumentBlobUrls = new ZlibImageBlobs();
|
||||
|
||||
if (AscCommon["CZLibEngineJS"])
|
||||
AscCommon["CZLibEngineJS"].prototype["isModuleInit"] = true;
|
||||
|
||||
window.nativeZlibEngine = new ZLib();
|
||||
if (window["NATIVE_EDITOR_ENJINE"])
|
||||
window["InitNativeZLib"] = function() { window.nativeZlibEngine = new ZLib(); };
|
||||
else
|
||||
window.nativeZlibEngine = new ZLib();
|
||||
|
||||
function Hyphenation()
|
||||
{
|
||||
|
||||
@ -191,6 +191,16 @@ namespace Aggplus
|
||||
{
|
||||
}
|
||||
|
||||
CClipMulti::clip_rasterizer* CClipMulti::GetRasterizer()
|
||||
{
|
||||
if (!m_bIsClip)
|
||||
{
|
||||
m_rasterizer.reset();
|
||||
return &m_rasterizer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CClipMulti::Create(LONG width, LONG height)
|
||||
{
|
||||
m_lWidth = width;
|
||||
@ -212,62 +222,52 @@ namespace Aggplus
|
||||
|
||||
typedef agg::conv_curve<trans_type> conv_crv_type;
|
||||
conv_crv_type c_c_path(trans);
|
||||
|
||||
|
||||
m_rasterizer.add_path(c_c_path);
|
||||
m_rasterizer.filling_rule(pPath->m_internal->m_bEvenOdd ? agg::fill_even_odd : agg::fill_non_zero);
|
||||
|
||||
GenerateClip2(pPath->m_internal->m_bEvenOdd);
|
||||
}
|
||||
|
||||
void CClipMulti::GenerateClip2(bool bEvenOdd)
|
||||
{
|
||||
m_rasterizer.filling_rule(bEvenOdd ? agg::fill_even_odd : agg::fill_non_zero);
|
||||
|
||||
m_bIsClip = true;
|
||||
m_bIsClip2 = false;
|
||||
}
|
||||
|
||||
void CClipMulti::Combine(CGraphicsPath* pPath, CMatrix* pMatrix, agg::sbool_op_e op)
|
||||
void CClipMulti::Combine(bool bEvenOdd, agg::sbool_op_e op, clip_rasterizer* pRasterizer)
|
||||
{
|
||||
if (!pRasterizer)
|
||||
return;
|
||||
|
||||
if (!m_bIsClip)
|
||||
return GenerateClip(pPath, pMatrix);
|
||||
return GenerateClip2(bEvenOdd);
|
||||
|
||||
if (!m_bIsClip2)
|
||||
{
|
||||
// смешивать надо с растерайзером
|
||||
agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> rasterizer;
|
||||
rasterizer.clip_box(0, 0, m_lWidth, m_lHeight);
|
||||
|
||||
typedef agg::conv_transform<agg::path_storage> trans_type;
|
||||
trans_type trans(pPath->m_internal->m_agg_ps, pMatrix->m_internal->m_agg_mtx);
|
||||
|
||||
typedef agg::conv_curve<trans_type> conv_crv_type;
|
||||
conv_crv_type c_c_path(trans);
|
||||
|
||||
rasterizer.add_path(c_c_path);
|
||||
rasterizer.filling_rule(pPath->m_internal->m_bEvenOdd ? agg::fill_even_odd : agg::fill_non_zero);
|
||||
pRasterizer->filling_rule(bEvenOdd ? agg::fill_even_odd : agg::fill_non_zero);
|
||||
|
||||
scanline_type sl1;
|
||||
scanline_type sl2;
|
||||
scanline_type sl;
|
||||
|
||||
agg::sbool_combine_shapes_aa(op, m_rasterizer, rasterizer, sl1, sl2, sl, m_storage1);
|
||||
agg::sbool_combine_shapes_aa(op, m_rasterizer, *pRasterizer, sl1, sl2, sl, m_storage1);
|
||||
|
||||
m_lCurStorage = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// надо смешивать со стораджем
|
||||
agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> rasterizer;
|
||||
rasterizer.clip_box(0, 0, m_lWidth, m_lHeight);
|
||||
|
||||
typedef agg::conv_transform<agg::path_storage> trans_type;
|
||||
trans_type trans(pPath->m_internal->m_agg_ps, pMatrix->m_internal->m_agg_mtx);
|
||||
|
||||
typedef agg::conv_curve<trans_type> conv_crv_type;
|
||||
conv_crv_type c_c_path(trans);
|
||||
|
||||
rasterizer.add_path(c_c_path);
|
||||
rasterizer.filling_rule(pPath->m_internal->m_bEvenOdd ? agg::fill_even_odd : agg::fill_non_zero);
|
||||
pRasterizer->filling_rule(op ? agg::fill_even_odd : agg::fill_non_zero);
|
||||
|
||||
scanline_type sl1;
|
||||
scanline_type sl2;
|
||||
scanline_type sl;
|
||||
|
||||
agg::sbool_combine_shapes_aa(op, rasterizer, (m_lCurStorage == 1) ? m_storage1 : m_storage2, sl1, sl2, sl,
|
||||
agg::sbool_combine_shapes_aa(op, *pRasterizer, (m_lCurStorage == 1) ? m_storage1 : m_storage2, sl1, sl2, sl,
|
||||
(m_lCurStorage == 1) ? m_storage2 : m_storage1);
|
||||
|
||||
if (1 == m_lCurStorage)
|
||||
|
||||
@ -138,10 +138,11 @@ public:
|
||||
|
||||
class CClipMulti
|
||||
{
|
||||
typedef agg::scanline_p8 scanline_type;
|
||||
|
||||
public:
|
||||
agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> m_rasterizer;
|
||||
typedef agg::scanline_p8 scanline_type;
|
||||
typedef agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> clip_rasterizer;
|
||||
|
||||
clip_rasterizer m_rasterizer;
|
||||
|
||||
agg::scanline_storage_aa8 m_storage1;
|
||||
agg::scanline_storage_aa8 m_storage2;
|
||||
@ -158,10 +159,13 @@ public:
|
||||
CClipMulti();
|
||||
~CClipMulti();
|
||||
|
||||
clip_rasterizer* GetRasterizer();
|
||||
|
||||
void Create(LONG width, LONG height);
|
||||
void GenerateClip(CGraphicsPath* pPath, CMatrix* pMatrix);
|
||||
void GenerateClip2(bool bEvenOdd);
|
||||
|
||||
void Combine(CGraphicsPath* pPath, CMatrix* pMatrix, agg::sbool_op_e op);
|
||||
void Combine(bool bEvenOdd, agg::sbool_op_e op, clip_rasterizer* pRasterizer);
|
||||
|
||||
bool IsClip();
|
||||
bool IsClip2();
|
||||
|
||||
@ -502,18 +502,41 @@ namespace Aggplus
|
||||
return Ok;
|
||||
}
|
||||
|
||||
Status CGraphics::CombineClip(CGraphicsPath* pPath, agg::sbool_op_e op)
|
||||
Status CGraphics::CombineClip(CGraphicsPath* pPath, agg::sbool_op_e op, NSStructures::CPen* pPen)
|
||||
{
|
||||
Aggplus::CMatrix m;
|
||||
return InternalClip(pPath, (m_bIntegerGrid || pPath->m_internal->m_pTransform != NULL) ? &m : &m_oFullTransform, op);
|
||||
return InternalClip(pPath, (m_bIntegerGrid || pPath->m_internal->m_pTransform != NULL) ? &m : &m_oFullTransform, op, pPen);
|
||||
}
|
||||
|
||||
Status CGraphics::InternalClip(CGraphicsPath* pPath, CMatrix* pTransform, agg::sbool_op_e op)
|
||||
Status CGraphics::InternalClip(CGraphicsPath* pPath, CMatrix* pTransform, agg::sbool_op_e op, NSStructures::CPen* pPen)
|
||||
{
|
||||
if (NULL == pPath)
|
||||
return InvalidParameter;
|
||||
|
||||
m_oClip.Combine(pPath, pTransform, op);
|
||||
bool bTempRasterizer = false;
|
||||
CClipMulti::clip_rasterizer* pRasterizer = m_oClip.GetRasterizer();
|
||||
if (!pRasterizer)
|
||||
{
|
||||
pRasterizer = new CClipMulti::clip_rasterizer();
|
||||
pRasterizer->clip_box(0, 0, m_oClip.m_lWidth, m_oClip.m_lHeight);
|
||||
bTempRasterizer = true;
|
||||
}
|
||||
|
||||
agg::trans_affine* pAffine = NULL;
|
||||
if (pPen)
|
||||
pAffine = DoStrokePath(pPen, pPath, pRasterizer);
|
||||
else
|
||||
{
|
||||
typedef agg::conv_transform<agg::path_storage> trans_type;
|
||||
trans_type trans(pPath->m_internal->m_agg_ps, pTransform->m_internal->m_agg_mtx);
|
||||
|
||||
typedef agg::conv_curve<trans_type> conv_crv_type;
|
||||
conv_crv_type c_c_path(trans);
|
||||
|
||||
pRasterizer->add_path(c_c_path);
|
||||
}
|
||||
|
||||
m_oClip.Combine(pPath->m_internal->m_bEvenOdd, op, pRasterizer);
|
||||
|
||||
// write to clips history
|
||||
CGraphics_ClipStateRecord* pRecord = new CGraphics_ClipStateRecord();
|
||||
@ -522,6 +545,11 @@ namespace Aggplus
|
||||
pRecord->Operation = op;
|
||||
m_oClipState.AddRecord(pRecord);
|
||||
|
||||
if (pAffine)
|
||||
delete pAffine;
|
||||
if (bTempRasterizer)
|
||||
delete pRasterizer;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
@ -610,180 +638,7 @@ namespace Aggplus
|
||||
|
||||
m_rasterizer.get_rasterizer().reset();
|
||||
|
||||
agg::line_join_e LineJoin = agg::round_join;
|
||||
switch(pPen->LineJoin)
|
||||
{
|
||||
case LineJoinMiter : LineJoin = agg::miter_join_revert; break;
|
||||
case LineJoinBevel : LineJoin = agg::bevel_join; break;
|
||||
case LineJoinRound : LineJoin = agg::round_join; break;
|
||||
case LineJoinMiterClipped : LineJoin = agg::miter_join_revert; break;
|
||||
default: break;
|
||||
}
|
||||
agg::line_cap_e LineCap = agg::round_cap;
|
||||
switch(pPen->LineStartCap)
|
||||
{
|
||||
case LineCapFlat : LineCap = agg::butt_cap; break;
|
||||
case LineCapRound : LineCap = agg::round_cap; break;
|
||||
case LineCapSquare : LineCap = agg::square_cap; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
double dWidth = pPen->Size;
|
||||
if (!m_bIntegerGrid && m_bIs0PenWidthAs1px)
|
||||
{
|
||||
double dWidthMinSize, dSqrtDet = sqrt(abs(m_oFullTransform.m_internal->m_agg_mtx.determinant()));
|
||||
if (0 == dWidth)
|
||||
{
|
||||
double dX = 0.72, dY = 0.72;
|
||||
agg::trans_affine invert = ~m_oFullTransform.m_internal->m_agg_mtx;
|
||||
invert.transform_2x2(&dX, &dY);
|
||||
dWidth = std::min(abs(dX), abs(dY));
|
||||
}
|
||||
else if (0 != dSqrtDet && dWidth < (dWidthMinSize = 1.0 / dSqrtDet))
|
||||
dWidth = dWidthMinSize;
|
||||
}
|
||||
|
||||
double dblMiterLimit = pPen->MiterLimit;
|
||||
|
||||
agg::path_storage path_copy(pPath->m_internal->m_agg_ps);
|
||||
bool bIsUseIdentity = m_bIntegerGrid;
|
||||
if (!bIsUseIdentity)
|
||||
{
|
||||
agg::trans_affine* full_trans = &m_oFullTransform.m_internal->m_agg_mtx;
|
||||
double dDet = full_trans->determinant();
|
||||
|
||||
if (fabs(dDet) < 0.0001)
|
||||
{
|
||||
path_copy.transform_all_paths(m_oFullTransform.m_internal->m_agg_mtx);
|
||||
dWidth *= sqrt(fabs(dDet));
|
||||
|
||||
bIsUseIdentity = true;
|
||||
}
|
||||
}
|
||||
|
||||
typedef agg::conv_curve<agg::path_storage> conv_crv_type;
|
||||
|
||||
conv_crv_type c_c_path(path_copy);
|
||||
c_c_path.approximation_scale(25.0);
|
||||
c_c_path.approximation_method(agg::curve_inc);
|
||||
DashStyle eStyle = (DashStyle)pPen->DashStyle;
|
||||
|
||||
if (DashStyleCustom == eStyle)
|
||||
{
|
||||
if (0 == pPen->Count || NULL == pPen->DashPattern)
|
||||
{
|
||||
eStyle = DashStyleSolid;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool bFoundNormal = false;
|
||||
for (int i = 0; i < pPen->Count; i++)
|
||||
{
|
||||
if (fabs(pPen->DashPattern[i]) > 0.0001)
|
||||
{
|
||||
bFoundNormal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bFoundNormal)
|
||||
eStyle = DashStyleSolid;
|
||||
}
|
||||
}
|
||||
|
||||
agg::trans_affine* pAffine = &m_oFullTransform.m_internal->m_agg_mtx;
|
||||
if (bIsUseIdentity)
|
||||
pAffine = new agg::trans_affine();
|
||||
|
||||
if (DashStyleSolid == eStyle)
|
||||
{
|
||||
typedef agg::conv_stroke<conv_crv_type> Path_Conv_StrokeN;
|
||||
Path_Conv_StrokeN pgN(c_c_path);
|
||||
|
||||
//pgN.line_join(agg::miter_join_revert);
|
||||
|
||||
pgN.line_cap(LineCap);
|
||||
|
||||
pgN.line_join(LineJoin);
|
||||
pgN.inner_join(agg::inner_round);
|
||||
|
||||
pgN.miter_limit(dblMiterLimit);
|
||||
pgN.width(dWidth);
|
||||
|
||||
pgN.approximation_scale(25.0);
|
||||
|
||||
typedef agg::conv_transform<Path_Conv_StrokeN> transStroke;
|
||||
|
||||
transStroke trans(pgN, *pAffine);
|
||||
m_rasterizer.get_rasterizer().add_path(trans);
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef agg::conv_dash<conv_crv_type> Path_Conv_Dash;
|
||||
Path_Conv_Dash poly2_dash(c_c_path);
|
||||
|
||||
typedef agg::conv_stroke<Path_Conv_Dash> Path_Conv_StrokeD;
|
||||
Path_Conv_StrokeD pgD(poly2_dash);
|
||||
|
||||
switch (eStyle)
|
||||
{
|
||||
case DashStyleDash:
|
||||
poly2_dash.add_dash(3.00*dWidth, dWidth);
|
||||
break;
|
||||
case DashStyleDot:
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
break;
|
||||
case DashStyleDashDot:
|
||||
poly2_dash.add_dash(3.00*dWidth, dWidth);
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
break;
|
||||
case DashStyleDashDotDot:
|
||||
poly2_dash.add_dash(3.00*dWidth, dWidth);
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
break;
|
||||
default:
|
||||
case DashStyleCustom:
|
||||
{
|
||||
double offset = pPen->DashOffset;
|
||||
double* params = pPen->DashPattern;
|
||||
LONG lCount = pPen->Count;
|
||||
LONG lCount2 = lCount / 2;
|
||||
|
||||
double dKoef = 1.0;
|
||||
|
||||
for (LONG i = 0; i < lCount2; ++i)
|
||||
{
|
||||
if (0 == i)
|
||||
{
|
||||
poly2_dash.add_dash((params[i * 2]) * dKoef, params[i * 2 + 1] * dKoef);
|
||||
}
|
||||
else
|
||||
{
|
||||
poly2_dash.add_dash(params[i * 2] * dKoef, params[i * 2 + 1] * dKoef);
|
||||
}
|
||||
}
|
||||
if (1 == (lCount % 2))
|
||||
{
|
||||
poly2_dash.add_dash(params[lCount - 1] * dKoef, 0);
|
||||
}
|
||||
poly2_dash.dash_start(offset * dKoef);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double dWidthMinSize = 1.0 / sqrt(abs(m_oCoordTransform.m_internal->m_agg_mtx.determinant()));
|
||||
if ((0 == dWidth && !m_bIntegerGrid) || dWidth < dWidthMinSize)
|
||||
dWidth = dWidthMinSize;
|
||||
|
||||
pgD.line_cap(LineCap);
|
||||
pgD.line_join(LineJoin);
|
||||
pgD.miter_limit(dblMiterLimit);
|
||||
pgD.width(dWidth);
|
||||
|
||||
agg::conv_transform<Path_Conv_StrokeD> trans(pgD, *pAffine);
|
||||
m_rasterizer.get_rasterizer().add_path(trans);
|
||||
}
|
||||
agg::trans_affine* pAffine = DoStrokePath(pPen, pPath, &m_rasterizer.get_rasterizer());
|
||||
|
||||
CColor oColor((BYTE)(pPen->Alpha * m_dGlobalAlpha), pPen->Color, m_bSwapRGB);
|
||||
CBrushSolid oBrush(oColor);
|
||||
@ -798,8 +653,7 @@ namespace Aggplus
|
||||
if (gamma >= 0)
|
||||
m_rasterizer.gamma(1.0);
|
||||
|
||||
if (bIsUseIdentity)
|
||||
RELEASEOBJECT(pAffine);
|
||||
RELEASEOBJECT(pAffine);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
@ -2243,6 +2097,186 @@ namespace Aggplus
|
||||
break;
|
||||
}
|
||||
}
|
||||
template<class Rasterizer>
|
||||
agg::trans_affine* CGraphics::DoStrokePath(NSStructures::CPen* pPen, CGraphicsPath* pPath, Rasterizer* pRasterizer)
|
||||
{
|
||||
agg::line_join_e LineJoin = agg::round_join;
|
||||
switch(pPen->LineJoin)
|
||||
{
|
||||
case LineJoinMiter : LineJoin = agg::miter_join_revert; break;
|
||||
case LineJoinBevel : LineJoin = agg::bevel_join; break;
|
||||
case LineJoinRound : LineJoin = agg::round_join; break;
|
||||
case LineJoinMiterClipped : LineJoin = agg::miter_join_revert; break;
|
||||
default: break;
|
||||
}
|
||||
agg::line_cap_e LineCap = agg::round_cap;
|
||||
switch(pPen->LineStartCap)
|
||||
{
|
||||
case LineCapFlat : LineCap = agg::butt_cap; break;
|
||||
case LineCapRound : LineCap = agg::round_cap; break;
|
||||
case LineCapSquare : LineCap = agg::square_cap; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
double dWidth = pPen->Size;
|
||||
if (!m_bIntegerGrid && m_bIs0PenWidthAs1px)
|
||||
{
|
||||
double dWidthMinSize, dSqrtDet = sqrt(abs(m_oFullTransform.m_internal->m_agg_mtx.determinant()));
|
||||
if (0 == dWidth)
|
||||
{
|
||||
double dX = 0.72, dY = 0.72;
|
||||
agg::trans_affine invert = ~m_oFullTransform.m_internal->m_agg_mtx;
|
||||
invert.transform_2x2(&dX, &dY);
|
||||
dWidth = std::min(abs(dX), abs(dY));
|
||||
}
|
||||
else if (0 != dSqrtDet && dWidth < (dWidthMinSize = 1.0 / dSqrtDet))
|
||||
dWidth = dWidthMinSize;
|
||||
}
|
||||
|
||||
double dblMiterLimit = pPen->MiterLimit;
|
||||
|
||||
agg::path_storage path_copy(pPath->m_internal->m_agg_ps);
|
||||
bool bIsUseIdentity = m_bIntegerGrid;
|
||||
if (!bIsUseIdentity)
|
||||
{
|
||||
agg::trans_affine* full_trans = &m_oFullTransform.m_internal->m_agg_mtx;
|
||||
double dDet = full_trans->determinant();
|
||||
|
||||
if (fabs(dDet) < 0.0001)
|
||||
{
|
||||
path_copy.transform_all_paths(m_oFullTransform.m_internal->m_agg_mtx);
|
||||
dWidth *= sqrt(fabs(dDet));
|
||||
|
||||
bIsUseIdentity = true;
|
||||
}
|
||||
}
|
||||
|
||||
typedef agg::conv_curve<agg::path_storage> conv_crv_type;
|
||||
|
||||
conv_crv_type c_c_path(path_copy);
|
||||
c_c_path.approximation_scale(25.0);
|
||||
c_c_path.approximation_method(agg::curve_inc);
|
||||
DashStyle eStyle = (DashStyle)pPen->DashStyle;
|
||||
|
||||
if (DashStyleCustom == eStyle)
|
||||
{
|
||||
if (0 == pPen->Count || NULL == pPen->DashPattern)
|
||||
{
|
||||
eStyle = DashStyleSolid;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool bFoundNormal = false;
|
||||
for (int i = 0; i < pPen->Count; i++)
|
||||
{
|
||||
if (fabs(pPen->DashPattern[i]) > 0.0001)
|
||||
{
|
||||
bFoundNormal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bFoundNormal)
|
||||
eStyle = DashStyleSolid;
|
||||
}
|
||||
}
|
||||
|
||||
agg::trans_affine* pAffine = &m_oFullTransform.m_internal->m_agg_mtx;
|
||||
if (bIsUseIdentity)
|
||||
pAffine = new agg::trans_affine();
|
||||
|
||||
if (DashStyleSolid == eStyle)
|
||||
{
|
||||
typedef agg::conv_stroke<conv_crv_type> Path_Conv_StrokeN;
|
||||
Path_Conv_StrokeN pgN(c_c_path);
|
||||
|
||||
//pgN.line_join(agg::miter_join_revert);
|
||||
|
||||
pgN.line_cap(LineCap);
|
||||
|
||||
pgN.line_join(LineJoin);
|
||||
pgN.inner_join(agg::inner_round);
|
||||
|
||||
pgN.miter_limit(dblMiterLimit);
|
||||
pgN.width(dWidth);
|
||||
|
||||
pgN.approximation_scale(25.0);
|
||||
|
||||
typedef agg::conv_transform<Path_Conv_StrokeN> transStroke;
|
||||
|
||||
transStroke trans(pgN, *pAffine);
|
||||
pRasterizer->add_path(trans);
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef agg::conv_dash<conv_crv_type> Path_Conv_Dash;
|
||||
Path_Conv_Dash poly2_dash(c_c_path);
|
||||
|
||||
typedef agg::conv_stroke<Path_Conv_Dash> Path_Conv_StrokeD;
|
||||
Path_Conv_StrokeD pgD(poly2_dash);
|
||||
|
||||
switch (eStyle)
|
||||
{
|
||||
case DashStyleDash:
|
||||
poly2_dash.add_dash(3.00*dWidth, dWidth);
|
||||
break;
|
||||
case DashStyleDot:
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
break;
|
||||
case DashStyleDashDot:
|
||||
poly2_dash.add_dash(3.00*dWidth, dWidth);
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
break;
|
||||
case DashStyleDashDotDot:
|
||||
poly2_dash.add_dash(3.00*dWidth, dWidth);
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
poly2_dash.add_dash(dWidth, dWidth);
|
||||
break;
|
||||
default:
|
||||
case DashStyleCustom:
|
||||
{
|
||||
double offset = pPen->DashOffset;
|
||||
double* params = pPen->DashPattern;
|
||||
LONG lCount = pPen->Count;
|
||||
LONG lCount2 = lCount / 2;
|
||||
|
||||
double dKoef = 1.0;
|
||||
|
||||
for (LONG i = 0; i < lCount2; ++i)
|
||||
{
|
||||
if (0 == i)
|
||||
{
|
||||
poly2_dash.add_dash((params[i * 2]) * dKoef, params[i * 2 + 1] * dKoef);
|
||||
}
|
||||
else
|
||||
{
|
||||
poly2_dash.add_dash(params[i * 2] * dKoef, params[i * 2 + 1] * dKoef);
|
||||
}
|
||||
}
|
||||
if (1 == (lCount % 2))
|
||||
{
|
||||
poly2_dash.add_dash(params[lCount - 1] * dKoef, 0);
|
||||
}
|
||||
poly2_dash.dash_start(offset * dKoef);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
double dWidthMinSize = 1.0 / sqrt(abs(m_oCoordTransform.m_internal->m_agg_mtx.determinant()));
|
||||
if ((0 == dWidth && !m_bIntegerGrid) || dWidth < dWidthMinSize)
|
||||
dWidth = dWidthMinSize;
|
||||
|
||||
pgD.line_cap(LineCap);
|
||||
pgD.line_join(LineJoin);
|
||||
pgD.miter_limit(dblMiterLimit);
|
||||
pgD.width(dWidth);
|
||||
|
||||
agg::conv_transform<Path_Conv_StrokeD> trans(pgD, *pAffine);
|
||||
pRasterizer->add_path(trans);
|
||||
}
|
||||
|
||||
return bIsUseIdentity ? pAffine : NULL;
|
||||
}
|
||||
// text methods
|
||||
int CGraphics::FillGlyph2(int nX, int nY, TGlyph* pGlyph, Aggplus::CBrush* pBrush)
|
||||
{
|
||||
|
||||
@ -360,8 +360,8 @@ public:
|
||||
Status SetClip(CGraphicsPath* pPath);
|
||||
Status ResetClip();
|
||||
Status ExclugeClip(CGraphicsPath* pPath);
|
||||
Status CombineClip(CGraphicsPath* pPath, agg::sbool_op_e op);
|
||||
Status InternalClip(CGraphicsPath* pPath, CMatrix* pTransform, agg::sbool_op_e op);
|
||||
Status CombineClip(CGraphicsPath* pPath, agg::sbool_op_e op, NSStructures::CPen* pPen = NULL);
|
||||
Status InternalClip(CGraphicsPath* pPath, CMatrix* pTransform, agg::sbool_op_e op, NSStructures::CPen* pPen = NULL);
|
||||
|
||||
// измерение текста
|
||||
INT MeasureString(const std::wstring& strText, CFontManager* pManager, double* lWidth, double* lHeight);
|
||||
@ -453,6 +453,8 @@ protected:
|
||||
void DoFillPathTextureClampSz3(const CMatrix &mImgMtx, const void *pImgBuff, DWORD dwImgWidth, DWORD dwImgHeight, int nImgStride, Aggplus::WrapMode wrapmode, BYTE Alpha = 255);
|
||||
|
||||
void DoFillPath(const CBrush* Brush);
|
||||
template<class Rasterizer>
|
||||
agg::trans_affine* DoStrokePath(NSStructures::CPen* pPen, CGraphicsPath* pPath, Rasterizer* ras);
|
||||
|
||||
// text methods
|
||||
int FillGlyph2(int nX, int nY, TGlyph* pGlyph, Aggplus::CBrush* pBrush);
|
||||
|
||||
@ -822,7 +822,8 @@ HRESULT CGraphicsRenderer::EndCommand(const DWORD& lType)
|
||||
m_pPath->SetRuler(bIsIn ? false : true);
|
||||
|
||||
INT bIsIntersect = (c_nClipRegionIntersect == (0x0100 & m_lCurrentClipMode));
|
||||
m_pRenderer->CombineClip(m_pPath, bIsIntersect ? agg::sbool_and : agg::sbool_or);
|
||||
INT bIsStrokePath = (c_nClipToStrokePath == (0x0010 & m_lCurrentClipMode));
|
||||
m_pRenderer->CombineClip(m_pPath, bIsIntersect ? agg::sbool_and : agg::sbool_or, bIsStrokePath ? &m_oPen : NULL);
|
||||
|
||||
//m_pRenderer->SetClip(m_pPath);
|
||||
break;
|
||||
|
||||
@ -96,6 +96,9 @@ const long c_nBaselineShift = 0xa041;
|
||||
// типы клипа
|
||||
const long c_nClipRegionTypeWinding = 0x0000;
|
||||
const long c_nClipRegionTypeEvenOdd = 0x0001;
|
||||
// тип преобразования пути для клипов
|
||||
const long c_nClipToPath = 0x0000;
|
||||
const long c_nClipToStrokePath = 0x0010;
|
||||
// тип объединения клипов
|
||||
const long c_nClipRegionIntersect = 0x0000;
|
||||
const long c_nClipRegionUnion = 0x0100;
|
||||
|
||||
@ -153,13 +153,6 @@ IMetafileToRenderter::IMetafileToRenderter(IRenderer* pRenderer)
|
||||
}
|
||||
IMetafileToRenderter::~IMetafileToRenderter()
|
||||
{
|
||||
for (std::vector<std::wstring>::iterator i = m_arTempFiles.begin(); i != m_arTempFiles.end(); i++)
|
||||
{
|
||||
std::wstring sPath = *i;
|
||||
if (NSFile::CFileBinary::Exists(sPath))
|
||||
NSFile::CFileBinary::Remove(sPath);
|
||||
}
|
||||
|
||||
if (m_pPicker)
|
||||
{
|
||||
CMetafileFontPicker* pPicker = (CMetafileFontPicker*)m_pPicker;
|
||||
@ -234,8 +227,6 @@ std::wstring IMetafileToRenderter::GetImagePath(const std::wstring& sPath)
|
||||
oFrame.put_Data(NULL);
|
||||
sImagePath = sTempFile;
|
||||
}
|
||||
|
||||
m_arTempFiles.push_back(sTempFile);
|
||||
}
|
||||
|
||||
RELEASEARRAYOBJECTS(pImageBuffer);
|
||||
|
||||
@ -49,7 +49,6 @@ public:
|
||||
|
||||
protected:
|
||||
std::wstring m_sTempDir;
|
||||
std::vector<std::wstring> m_arTempFiles;
|
||||
|
||||
std::wstring m_sThemesDir;
|
||||
std::wstring m_sMediaDir;
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
|
||||
CAnnotFieldInfo::CAnnotFieldInfo() : IAdvancedCommand(AdvancedCommandType::Annotaion)
|
||||
{
|
||||
m_nType = -1;
|
||||
m_nType = EAnnotType::Unknown;
|
||||
|
||||
m_nFlag = 0;
|
||||
m_nID = 0;
|
||||
@ -94,118 +94,108 @@ CAnnotFieldInfo::~CAnnotFieldInfo()
|
||||
RELEASEOBJECT(m_pWidgetPr);
|
||||
}
|
||||
|
||||
void CAnnotFieldInfo::CreateMarkup()
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
}
|
||||
void CAnnotFieldInfo::SetType(int nType)
|
||||
{
|
||||
m_nType = nType;
|
||||
switch (nType)
|
||||
m_nType = static_cast<EAnnotType>(nType);
|
||||
switch (m_nType)
|
||||
{
|
||||
case 0:
|
||||
case EAnnotType::Text:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pTextPr);
|
||||
m_pTextPr = new CAnnotFieldInfo::CTextAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case EAnnotType::FreeText:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pFreeTextPr);
|
||||
m_pFreeTextPr = new CAnnotFieldInfo::CFreeTextAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
case EAnnotType::Line:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pLinePr);
|
||||
m_pLinePr = new CAnnotFieldInfo::CLineAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
case 5:
|
||||
case EAnnotType::Square:
|
||||
case EAnnotType::Circle:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pSquareCirclePr);
|
||||
m_pSquareCirclePr = new CAnnotFieldInfo::CSquareCircleAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
case 7:
|
||||
case EAnnotType::PolygonLine:
|
||||
case EAnnotType::PolyLine:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pPolygonLinePr);
|
||||
m_pPolygonLinePr = new CAnnotFieldInfo::CPolygonLineAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case EAnnotType::Highlight:
|
||||
case EAnnotType::Underline:
|
||||
case EAnnotType::Squiggly:
|
||||
case EAnnotType::Strikeout:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pTextMarkupPr);
|
||||
m_pTextMarkupPr = new CAnnotFieldInfo::CTextMarkupAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 12:
|
||||
case EAnnotType::Stamp:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pStampPr);
|
||||
m_pStampPr = new CAnnotFieldInfo::CStampAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 13:
|
||||
case EAnnotType::Caret:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pCaretPr);
|
||||
m_pCaretPr = new CAnnotFieldInfo::CCaretAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 14:
|
||||
case EAnnotType::Ink:
|
||||
{
|
||||
RELEASEOBJECT(m_pMarkupPr);
|
||||
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
|
||||
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pInkPr);
|
||||
m_pInkPr = new CAnnotFieldInfo::CInkAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 15:
|
||||
case EAnnotType::Popup:
|
||||
{
|
||||
RELEASEOBJECT(m_pPopupPr);
|
||||
m_pPopupPr = new CAnnotFieldInfo::CPopupAnnotPr();
|
||||
break;
|
||||
}
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case EAnnotType::Widget:
|
||||
case EAnnotType::WidgetPushButton:
|
||||
case EAnnotType::WidgetRadioButton:
|
||||
case EAnnotType::WidgetCheckBox:
|
||||
case EAnnotType::WidgetText:
|
||||
case EAnnotType::WidgetCombobox:
|
||||
case EAnnotType::WidgetListbox:
|
||||
case EAnnotType::WidgetSignature:
|
||||
{
|
||||
RELEASEOBJECT(m_pWidgetPr);
|
||||
m_pWidgetPr = new CAnnotFieldInfo::CWidgetAnnotPr(nType);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
CAnnotFieldInfo::EAnnotType CAnnotFieldInfo::GetType() { return m_nType; }
|
||||
|
||||
void CAnnotFieldInfo::GetBounds(double& dX1, double& dY1, double& dX2, double& dY2)
|
||||
{
|
||||
@ -343,6 +333,7 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
|
||||
if (nFlags & (1 << 3))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrC.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -353,6 +344,7 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
|
||||
if (m_oBorder.nType == 2)
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_oBorder.arrDash.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_oBorder.arrDash.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -428,6 +420,7 @@ void CAnnotFieldInfo::CMarkupAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
|
||||
if (nFlags & (1 << 3))
|
||||
{
|
||||
int nFont = pReader->ReadInt();
|
||||
m_arrRC.reserve(nFont);
|
||||
for (int i = 0; i < nFont; ++i)
|
||||
{
|
||||
CFontData* pFont = new CFontData();
|
||||
@ -480,6 +473,7 @@ void CAnnotFieldInfo::CInkAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* p
|
||||
{
|
||||
std::vector<double> arrLine;
|
||||
int m = pReader->ReadInt();
|
||||
arrLine.reserve(m);
|
||||
for (int j = 0; j < m; ++j)
|
||||
arrLine.push_back(pReader->ReadDouble());
|
||||
if (!arrLine.empty())
|
||||
@ -512,6 +506,7 @@ void CAnnotFieldInfo::CLineAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader*
|
||||
if (nFlags & (1 << 16))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrIC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrIC.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -539,6 +534,7 @@ void CAnnotFieldInfo::CTextMarkupAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferRe
|
||||
{
|
||||
m_nSubtype = nType;
|
||||
int n = pReader->ReadInt();
|
||||
m_arrQuadPoints.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrQuadPoints.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -559,6 +555,7 @@ void CAnnotFieldInfo::CSquareCircleAnnotPr::Read(NSOnlineOfficeBinToPdf::CBuffer
|
||||
if (nFlags & (1 << 16))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrIC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrIC.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -572,6 +569,7 @@ const std::vector<double>& CAnnotFieldInfo::CPolygonLineAnnotPr::GetVertices() {
|
||||
void CAnnotFieldInfo::CPolygonLineAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, BYTE nType, int nFlags)
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrVertices.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrVertices.push_back(pReader->ReadDouble());
|
||||
|
||||
@ -584,6 +582,7 @@ void CAnnotFieldInfo::CPolygonLineAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferR
|
||||
if (nFlags & (1 << 16))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrIC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrIC.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -613,6 +612,7 @@ void CAnnotFieldInfo::CFreeTextAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferRead
|
||||
if (nFlags & (1 << 16))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrCL.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrCL.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -625,6 +625,7 @@ void CAnnotFieldInfo::CFreeTextAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferRead
|
||||
if (nFlags & (1 << 21))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrIC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrIC.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -645,12 +646,17 @@ void CAnnotFieldInfo::CCaretAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader*
|
||||
m_nSy = pReader->ReadByte();
|
||||
}
|
||||
|
||||
int CAnnotFieldInfo::CStampAnnotPr::GetRotate() { return m_nRotate; }
|
||||
double CAnnotFieldInfo::CStampAnnotPr::GetRotate() { return m_nRotate; }
|
||||
const std::wstring& CAnnotFieldInfo::CStampAnnotPr::GetName() { return m_wsName; }
|
||||
void CAnnotFieldInfo::CStampAnnotPr::GetInRect(double& dRD1, double& dRD2, double& dRD3, double& dRD4) { dRD1 = m_dInRect[0]; dRD2 = m_dInRect[1]; dRD3 = m_dInRect[2]; dRD4 = m_dInRect[3]; }
|
||||
void CAnnotFieldInfo::CStampAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags)
|
||||
{
|
||||
m_wsName = pReader->ReadString();
|
||||
m_nRotate = pReader->ReadInt();
|
||||
m_nRotate = pReader->ReadDouble();
|
||||
m_dInRect[0] = pReader->ReadDouble();
|
||||
m_dInRect[1] = pReader->ReadDouble();
|
||||
m_dInRect[2] = pReader->ReadDouble();
|
||||
m_dInRect[3] = pReader->ReadDouble();
|
||||
}
|
||||
|
||||
bool CAnnotFieldInfo::CPopupAnnotPr::IsOpen() const { return m_bOpen; }
|
||||
@ -809,6 +815,7 @@ CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* ReadAction(NSOnlineOfficeBinToPd
|
||||
{
|
||||
pRes->nKind = pReader->ReadByte();
|
||||
int n = pReader->ReadInt();
|
||||
pRes->arrStr.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pRes->arrStr.push_back(pReader->ReadString());
|
||||
break;
|
||||
@ -817,6 +824,7 @@ CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* ReadAction(NSOnlineOfficeBinToPd
|
||||
{
|
||||
pRes->nInt1 = pReader->ReadInt();
|
||||
int n = pReader->ReadInt();
|
||||
pRes->arrStr.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pRes->arrStr.push_back(pReader->ReadString());
|
||||
break;
|
||||
@ -836,6 +844,7 @@ void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
|
||||
m_nFontStyle = pReader->ReadInt();
|
||||
|
||||
int n = pReader->ReadInt();
|
||||
m_arrTC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrTC.push_back(pReader->ReadDouble());
|
||||
|
||||
@ -858,6 +867,7 @@ void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
|
||||
if (nFlags & (1 << 5))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrBC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrBC.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -866,6 +876,7 @@ void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
|
||||
if (nFlags & (1 << 7))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrBG.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrBG.push_back(pReader->ReadDouble());
|
||||
}
|
||||
@ -1001,6 +1012,7 @@ void CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::Read(NSOnlineOfficeBinToP
|
||||
if (nFlags & (1 << 10))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrOpt.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
std::wstring s1 = pReader->ReadString();
|
||||
@ -1015,12 +1027,14 @@ void CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::Read(NSOnlineOfficeBinToP
|
||||
if (nFlags & (1 << 13))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrV.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrV.push_back(pReader->ReadString());
|
||||
}
|
||||
if (nFlags & (1 << 14))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrI.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrI.push_back(pReader->ReadInt());
|
||||
}
|
||||
@ -1053,10 +1067,12 @@ const std::vector<CWidgetsInfo::CParent*>& CWidgetsInfo::GetParents() { return m
|
||||
bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector)
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrCO.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrCO.push_back(pReader->ReadInt());
|
||||
|
||||
n = pReader->ReadInt();
|
||||
m_arrParents.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
CParent* pParent = new CParent();
|
||||
@ -1072,6 +1088,7 @@ bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafil
|
||||
if (nFlags & (1 << 3))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
pParent->arrI.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pParent->arrI.push_back(pReader->ReadInt());
|
||||
}
|
||||
@ -1080,6 +1097,7 @@ bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafil
|
||||
if (nFlags & (1 << 5))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
pParent->arrV.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
pParent->arrV.push_back(pReader->ReadString());
|
||||
}
|
||||
@ -1087,6 +1105,7 @@ bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafil
|
||||
}
|
||||
|
||||
n = pReader->ReadInt();
|
||||
m_arrButtonImg.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
std::string sImagePath = pReader->ReadStringA();
|
||||
|
||||
@ -39,6 +39,36 @@ class IMetafileToRenderter;
|
||||
class GRAPHICS_DECL CAnnotFieldInfo : public IAdvancedCommand
|
||||
{
|
||||
public:
|
||||
enum EAnnotType
|
||||
{
|
||||
Unknown = -1,
|
||||
Text = 0,
|
||||
Link = 1,
|
||||
FreeText = 2,
|
||||
Line = 3,
|
||||
Square = 4,
|
||||
Circle = 5,
|
||||
PolygonLine = 6,
|
||||
PolyLine = 7,
|
||||
Highlight = 8,
|
||||
Underline = 9,
|
||||
Squiggly = 10,
|
||||
Strikeout = 11,
|
||||
Stamp = 12,
|
||||
Caret = 13,
|
||||
Ink = 14,
|
||||
Popup = 15,
|
||||
FileAttachment = 16,
|
||||
Widget = 26,
|
||||
WidgetPushButton = 27,
|
||||
WidgetRadioButton = 28,
|
||||
WidgetCheckBox = 29,
|
||||
WidgetText = 30,
|
||||
WidgetCombobox = 31,
|
||||
WidgetListbox = 32,
|
||||
WidgetSignature = 33
|
||||
};
|
||||
|
||||
class GRAPHICS_DECL CWidgetAnnotPr
|
||||
{
|
||||
public:
|
||||
@ -408,20 +438,24 @@ public:
|
||||
class GRAPHICS_DECL CStampAnnotPr
|
||||
{
|
||||
public:
|
||||
int GetRotate();
|
||||
double GetRotate();
|
||||
const std::wstring& GetName();
|
||||
void GetInRect(double& dRD1, double& dRD2, double& dRD3, double& dRD4);
|
||||
|
||||
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags);
|
||||
|
||||
private:
|
||||
int m_nRotate;
|
||||
double m_nRotate;
|
||||
std::wstring m_wsName;
|
||||
double m_dInRect[4]{};
|
||||
};
|
||||
|
||||
CAnnotFieldInfo();
|
||||
virtual ~CAnnotFieldInfo();
|
||||
|
||||
void CreateMarkup();
|
||||
void SetType(int nType);
|
||||
EAnnotType GetType();
|
||||
|
||||
void GetBounds(double& dX1, double& dY1, double& dX2, double& dY2);
|
||||
void GetBorder(BYTE& nType, double& dWidth, std::vector<double>& arrDash);
|
||||
@ -477,7 +511,7 @@ private:
|
||||
std::vector<double> arrDash;
|
||||
};
|
||||
|
||||
int m_nType;
|
||||
EAnnotType m_nType;
|
||||
double m_dX1;
|
||||
double m_dY1;
|
||||
double m_dX2;
|
||||
|
||||
@ -123,6 +123,7 @@ namespace MetaFile
|
||||
|
||||
virtual bool LoadFromFile(const wchar_t* wsFilePath) = 0;
|
||||
virtual bool LoadFromBuffer(BYTE* pBuffer, unsigned int unSize) = 0;
|
||||
virtual bool LoadFromString(const std::wstring& data) = 0;
|
||||
virtual bool DrawOnRenderer(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight) = 0;
|
||||
virtual void Close() = 0;
|
||||
virtual void GetBounds(double* pdX, double* pdY, double* pdW, double* pdH) = 0;
|
||||
@ -131,6 +132,7 @@ namespace MetaFile
|
||||
virtual NSFonts::IFontManager* get_FontManager() = 0;
|
||||
|
||||
virtual std::wstring ConvertToSvg(unsigned int unWidth = 0, unsigned int unHeight = 0) = 0;
|
||||
virtual void SetTempDirectory(const std::wstring& dir) = 0;
|
||||
|
||||
//Для тестов
|
||||
#ifdef METAFILE_SUPPORT_WMF_EMF
|
||||
|
||||
@ -223,7 +223,7 @@
|
||||
},
|
||||
{
|
||||
"folder": "../../../../DocxRenderer/src/logic/elements",
|
||||
"files": ["BaseItem.cpp", "ContText.cpp", "Paragraph.cpp", "Shape.cpp", "TextLine.cpp"]
|
||||
"files": ["BaseItem.cpp", "ContText.cpp", "Paragraph.cpp", "Shape.cpp", "TextLine.cpp", "Table.cpp"]
|
||||
},
|
||||
{
|
||||
"folder": "../../../common",
|
||||
|
||||
@ -682,6 +682,7 @@ HEADERS += \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/DropCap.h \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Paragraph.h \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Shape.h \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Table.h \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/TextLine.h \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/ExternalImageStorage.h \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontStyleManager.h \
|
||||
@ -706,6 +707,7 @@ SOURCES += \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/ContText.cpp \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Paragraph.cpp \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Shape.cpp \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/Table.cpp \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/elements/TextLine.cpp \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontManager.cpp \
|
||||
$$DOCX_RENDERER_ROOT_DIR/src/logic/managers/FontStyleManager.cpp \
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
* (c) Copyright Ascensio System SIA 2010-2024
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
* (c) Copyright Ascensio System SIA 2010-2024
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
|
||||
@ -1279,7 +1279,7 @@ CFile.prototype["getAnnotationsInfo"] = function(pageIndex)
|
||||
else if (rec["Type"] == 12)
|
||||
{
|
||||
rec["Icon"] = reader.readString();
|
||||
rec["Rotate"] = reader.readInt();
|
||||
rec["Rotate"] = reader.readDouble2();
|
||||
rec["InRect"] = [];
|
||||
for (let i = 0; i < 8; ++i)
|
||||
rec["InRect"].push(reader.readDouble2());
|
||||
|
||||
@ -1280,7 +1280,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// ANNOTS
|
||||
if (false)
|
||||
if (true)
|
||||
{
|
||||
BYTE* pAnnots = GetAnnotationsInfo(pGrFile, -1);
|
||||
nLength = READ_INT(pAnnots);
|
||||
@ -1870,7 +1870,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
nPathLength = READ_INT(pAnnots + i);
|
||||
i += 4;
|
||||
std::cout << "Rotate " << nPathLength << ", ";
|
||||
std::cout << "Rotate " << nPathLength / 10000.0 << ", ";
|
||||
|
||||
nPathLength = READ_INT(pAnnots + i);
|
||||
i += 4;
|
||||
|
||||
@ -42,6 +42,7 @@ namespace MetaFile
|
||||
virtual void SetImageSize(int nWidth, int nHeight) {}
|
||||
virtual bool LoadFromFile(const wchar_t* wsFilePath) { return false; }
|
||||
virtual bool LoadFromBuffer(BYTE* pBuffer, unsigned int unSize) { return false; }
|
||||
virtual bool LoadFromString(const std::wstring& data) { return false; }
|
||||
virtual bool DrawOnRenderer(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight) { return false; }
|
||||
virtual void Close() {}
|
||||
virtual void GetBounds(double* pdX, double* pdY, double* pdW, double* pdH) {}
|
||||
@ -50,6 +51,7 @@ namespace MetaFile
|
||||
virtual NSFonts::IFontManager* get_FontManager() { return NULL; }
|
||||
|
||||
virtual std::wstring ConvertToSvg(unsigned int unWidth = 0, unsigned int unHeight = 0) { return L""; }
|
||||
virtual void SetTempDirectory(const std::wstring& dir) {}
|
||||
|
||||
virtual void ConvertToXml(const wchar_t* wsFilePath) {}
|
||||
virtual void ConvertToXmlAndRaster(const wchar_t *wsXmlFilePath, const wchar_t* wsOutFilePath, unsigned int unFileType, int nWidth, int nHeight = -1) {}
|
||||
|
||||
@ -19,6 +19,7 @@ METAFILE_PATH = $$PWD/../../raster/Metafile
|
||||
\
|
||||
$$METAFILE_PATH/Emf/EmfTypes.h \
|
||||
$$METAFILE_PATH/Emf/EmfObjects.h \
|
||||
$$METAFILE_PATH/Emf/EmfPlusObjects.h \
|
||||
$$METAFILE_PATH/Emf/EmfPlayer.h \
|
||||
$$METAFILE_PATH/Emf/EmfFile.h \
|
||||
$$METAFILE_PATH/Wmf/WmfObjects.h \
|
||||
|
||||
@ -327,6 +327,13 @@ namespace MetaFile
|
||||
if (NULL == pCommand)
|
||||
return false;
|
||||
|
||||
if (PATH_COMMAND_MOVETO == pCommand->GetType() && !m_arCommands.empty() && PATH_COMMAND_MOVETO == m_arCommands.back()->GetType())
|
||||
{
|
||||
CPathCommandBase* pLastCommand = m_arCommands.back();
|
||||
m_arCommands.pop_back();
|
||||
delete pLastCommand;
|
||||
}
|
||||
|
||||
m_arCommands.push_back(pCommand);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ namespace MetaFile
|
||||
{
|
||||
CPathCommandArcTo *pCommandArcTo = (CPathCommandArcTo*)pCommand;
|
||||
|
||||
oNewPath.ArcTo(pCommandArcTo->GetLeft(), pCommandArcTo->GetTop(),
|
||||
oNewPath.ArcTo(pCommandArcTo->GetLeft(), pCommandArcTo->GetTop(),
|
||||
pCommandArcTo->GetRight(), pCommandArcTo->GetBottom(),
|
||||
pCommandArcTo->GetStartAngle(), pCommandArcTo->GetSweepAngle());
|
||||
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
#define _METAFILE_COMMON_METAFILEOBJECTS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
@ -70,22 +71,33 @@ namespace MetaFile
|
||||
virtual void GetBounds(double& left, double& top, double& width, double& height) const = 0;
|
||||
virtual void GetCenterPoint(double& dX, double& dY) const = 0;
|
||||
|
||||
virtual void GetGradientColors(std::vector<long>& arColors, std::vector<double>& arPositions) const = 0;
|
||||
|
||||
virtual void GetDibPattern(unsigned char** pBuffer, unsigned int &unWidth, unsigned int &unHeight) const = 0;
|
||||
};
|
||||
|
||||
class ILineCap
|
||||
{
|
||||
public:
|
||||
ILineCap(){}
|
||||
virtual ~ILineCap(){}
|
||||
};
|
||||
|
||||
class IPen
|
||||
{
|
||||
public:
|
||||
IPen(){}
|
||||
virtual ~IPen(){}
|
||||
|
||||
virtual int GetColor() const = 0;
|
||||
virtual unsigned int GetStyle() const = 0;
|
||||
virtual double GetWidth() const = 0;
|
||||
virtual unsigned int GetAlpha() const = 0;
|
||||
virtual double GetMiterLimit() const = 0;
|
||||
virtual double GetDashOffset() const = 0;
|
||||
virtual void GetDashData(double*&, unsigned int&) const = 0;
|
||||
virtual int GetColor() const = 0;
|
||||
virtual unsigned int GetStyle() const = 0;
|
||||
virtual double GetWidth() const = 0;
|
||||
virtual unsigned int GetAlpha() const = 0;
|
||||
virtual double GetMiterLimit() const = 0;
|
||||
virtual double GetDashOffset() const = 0;
|
||||
virtual void GetDashData(double*&, unsigned int&) const = 0;
|
||||
virtual const ILineCap* GetStartLineCap() const = 0;
|
||||
virtual const ILineCap* GetEndLineCap() const = 0;
|
||||
};
|
||||
|
||||
class IRegion
|
||||
|
||||
@ -1107,12 +1107,11 @@ namespace MetaFile
|
||||
|
||||
m_pRenderer->put_BrushLinearAngle(pBrush->GetStyleEx());
|
||||
|
||||
long Colors[2];
|
||||
Colors[0] = pBrush->GetColor() + (pBrush->GetAlpha() << 24);
|
||||
Colors[1] = pBrush->GetColor2() + (pBrush->GetAlpha2() << 24);
|
||||
double Position[2] = {0, 1};
|
||||
std::vector<long> arColors;
|
||||
std::vector<double> arPositions;
|
||||
|
||||
m_pRenderer->put_BrushGradientColors(Colors,Position,2);
|
||||
pBrush->GetGradientColors(arColors, arPositions);
|
||||
m_pRenderer->put_BrushGradientColors(arColors.data(), arPositions.data(), arColors.size());
|
||||
|
||||
}
|
||||
else if ( BS_RADIALGRADIENT == unBrushStyle ||
|
||||
@ -1180,7 +1179,6 @@ namespace MetaFile
|
||||
return false;
|
||||
|
||||
unsigned int unMetaPenStyle = pPen->GetStyle();
|
||||
|
||||
unsigned int ulPenStyle = unMetaPenStyle & PS_STYLE_MASK;
|
||||
|
||||
if (PS_NULL == ulPenStyle)
|
||||
@ -1220,20 +1218,40 @@ namespace MetaFile
|
||||
|
||||
double dWidth = pPen->GetWidth();
|
||||
|
||||
if (Equals(0, dWidth) || (Equals(1, dWidth) && PS_COSMETIC == ulPenType))
|
||||
// Повторение кода из Graphics для вычисления минимальной ширины пера
|
||||
double dM11, dM12, dM21, dM22, dDx, dDy;
|
||||
m_pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dDx, &dDy);
|
||||
|
||||
Aggplus::CMatrix oMatrix;
|
||||
|
||||
oMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy);
|
||||
oMatrix.Scale(1. / m_dScaleX, 1. / m_dScaleY);
|
||||
|
||||
// Вычисление минимально возможной ширины пера
|
||||
// # Код явялется дублированным из Graphics
|
||||
const double dSqrtDet = sqrt(abs(oMatrix.Determinant()));
|
||||
const double dWidthMinSize = (dSqrtDet != 0) ? (1.0 / dSqrtDet) : dWidth;
|
||||
|
||||
if (0 == pPen->GetWidth())
|
||||
{
|
||||
double dRendererDpiX;
|
||||
m_pRenderer->get_DpiX(&dRendererDpiX);
|
||||
double dX = 0.72, dY = 0.72;
|
||||
|
||||
dWidth = 25.4 / 96. * m_pFile->GetDpi() / dRendererDpiX;
|
||||
|
||||
nStartCapStyle = nEndCapStyle = Aggplus::LineCapFlat;
|
||||
nJoinStyle = Aggplus::LineJoinMiter;
|
||||
oMatrix.Invert();
|
||||
oMatrix.TransformPoint(dX, dY);
|
||||
dX -= oMatrix.OffsetX();
|
||||
dY -= oMatrix.OffsetY();
|
||||
dWidth = std::min(abs(dX), abs(dY));
|
||||
}
|
||||
//------------------------
|
||||
else
|
||||
{
|
||||
dWidth *= m_dScaleX;
|
||||
|
||||
double dMiterLimit = (0 != pPen->GetMiterLimit()) ? pPen->GetMiterLimit() : m_pFile->GetMiterLimit() * m_dScaleX;
|
||||
if (dWidth < dWidthMinSize)
|
||||
dWidth = dWidthMinSize;
|
||||
}
|
||||
|
||||
const double dMiterLimit = (0 != pPen->GetMiterLimit()) ? pPen->GetMiterLimit() : m_pFile->GetMiterLimit() * m_dScaleX;
|
||||
|
||||
BYTE nDashStyle = Aggplus::DashStyleSolid;
|
||||
|
||||
@ -1242,67 +1260,83 @@ namespace MetaFile
|
||||
|
||||
pPen->GetDashData(pDataDash, unSizeDash);
|
||||
|
||||
if (NULL != pDataDash && 0 != unSizeDash)
|
||||
if ((NULL != pDataDash && 0 != unSizeDash) || PS_SOLID != ulPenStyle)
|
||||
{
|
||||
m_pRenderer->put_PenDashOffset(pPen->GetDashOffset());
|
||||
// Дублированный код из Graphics
|
||||
// Без этого используется оригинальный код в Graphics, который отрисовывает уже неверно
|
||||
double dDashWidth{dWidth};
|
||||
|
||||
std::vector<double> arDashes(unSizeDash);
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex)
|
||||
arDashes[unIndex] = pDataDash[unIndex] * dWidth;
|
||||
|
||||
m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash);
|
||||
|
||||
nDashStyle = Aggplus::DashStyleCustom;
|
||||
}
|
||||
else if (PS_SOLID != ulPenStyle)
|
||||
{
|
||||
std::vector<double> arDashPattern;
|
||||
|
||||
switch (ulPenStyle)
|
||||
if (!Equals(dWidthMinSize, dWidth))
|
||||
{
|
||||
case PS_DASH:
|
||||
{
|
||||
arDashPattern.push_back(9 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
double dDet = oMatrix.Determinant();
|
||||
|
||||
break;
|
||||
}
|
||||
case PS_DOT:
|
||||
{
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
|
||||
break;
|
||||
}
|
||||
case PS_DASHDOT:
|
||||
{
|
||||
arDashPattern.push_back(9 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
|
||||
break;
|
||||
}
|
||||
case PS_DASHDOTDOT:
|
||||
{
|
||||
arDashPattern.push_back(9 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
arDashPattern.push_back(3 * dWidth);
|
||||
|
||||
break;
|
||||
}
|
||||
if (fabs(dDet) < 0.0001)
|
||||
dDashWidth *= dSqrtDet;
|
||||
}
|
||||
// -----------------------------
|
||||
|
||||
if (!arDashPattern.empty())
|
||||
if (NULL != pDataDash && 0 != unSizeDash)
|
||||
{
|
||||
m_pRenderer->PenDashPattern(arDashPattern.data(), arDashPattern.size());
|
||||
m_pRenderer->put_PenDashOffset(pPen->GetDashOffset());
|
||||
|
||||
std::vector<double> arDashes(unSizeDash);
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex)
|
||||
arDashes[unIndex] = pDataDash[unIndex] * dDashWidth;
|
||||
|
||||
m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash);
|
||||
|
||||
nDashStyle = Aggplus::DashStyleCustom;
|
||||
nStartCapStyle = nEndCapStyle = Aggplus::LineCapFlat;
|
||||
nJoinStyle = Aggplus::LineJoinMiter;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<double> arDashPattern;
|
||||
|
||||
switch (ulPenStyle)
|
||||
{
|
||||
case PS_DASH:
|
||||
{
|
||||
arDashPattern.push_back(9 * dDashWidth);
|
||||
arDashPattern.push_back(3 * dDashWidth);
|
||||
|
||||
break;
|
||||
}
|
||||
case PS_DOT:
|
||||
{
|
||||
arDashPattern.push_back(3 * dDashWidth);
|
||||
arDashPattern.push_back(3 * dDashWidth);
|
||||
|
||||
break;
|
||||
}
|
||||
case PS_DASHDOT:
|
||||
{
|
||||
arDashPattern.push_back(9 * dDashWidth);
|
||||
arDashPattern.push_back(6 * dDashWidth);
|
||||
arDashPattern.push_back(3 * dDashWidth);
|
||||
arDashPattern.push_back(6 * dDashWidth);
|
||||
|
||||
break;
|
||||
}
|
||||
case PS_DASHDOTDOT:
|
||||
{
|
||||
arDashPattern.push_back(9 * dDashWidth);
|
||||
arDashPattern.push_back(6 * dDashWidth);
|
||||
arDashPattern.push_back(3 * dDashWidth);
|
||||
arDashPattern.push_back(6 * dDashWidth);
|
||||
arDashPattern.push_back(3 * dDashWidth);
|
||||
arDashPattern.push_back(6 * dDashWidth);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!arDashPattern.empty())
|
||||
{
|
||||
m_pRenderer->PenDashPattern(arDashPattern.data(), arDashPattern.size());
|
||||
nDashStyle = Aggplus::DashStyleCustom;
|
||||
nStartCapStyle = nEndCapStyle = Aggplus::LineCapFlat;
|
||||
nJoinStyle = Aggplus::LineJoinMiter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@ namespace MetaFile
|
||||
: r(_r), g(_g), b(_b), a(_a)
|
||||
{}
|
||||
|
||||
TRGBA::TRGBA(int nValue) : r((nValue >> 0) & 0xFF), g((nValue >> 8) & 0xFF), b((nValue >> 16) & 0xFF), a((nValue >> 24) & 0xFF)
|
||||
TRGBA::TRGBA(int nValue)
|
||||
: r((nValue >> 0) & 0xFF), g((nValue >> 8) & 0xFF), b((nValue >> 16) & 0xFF), a((nValue >> 24) & 0xFF)
|
||||
{}
|
||||
|
||||
void TRGBA::Set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
|
||||
@ -94,7 +95,18 @@ namespace MetaFile
|
||||
return a;
|
||||
}
|
||||
|
||||
TXForm::TXForm() : M11(1), M12(0), M21(0), M22(1), Dx(0), Dy(0)
|
||||
TRGBA& TRGBA::operator=(const TRGBA& oRGBA)
|
||||
{
|
||||
r = oRGBA.r;
|
||||
g = oRGBA.g;
|
||||
b = oRGBA.b;
|
||||
a = oRGBA.a;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
TXForm::TXForm()
|
||||
: M11(1), M12(0), M21(0), M22(1), Dx(0), Dy(0)
|
||||
{}
|
||||
|
||||
TXForm::TXForm(const TXForm &oXForm)
|
||||
|
||||
@ -349,6 +349,8 @@ typedef unsigned char BYTE;
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
#define DEFAULT_FONT_SIZE 14
|
||||
|
||||
enum InterpretatorType
|
||||
{
|
||||
Emf,
|
||||
@ -556,6 +558,8 @@ namespace MetaFile
|
||||
unsigned char GetGreen() const;
|
||||
unsigned char GetBlue() const;
|
||||
unsigned char GetAlpha() const;
|
||||
|
||||
TRGBA& operator=(const TRGBA& oRGBA);
|
||||
};
|
||||
|
||||
struct TXForm
|
||||
|
||||
@ -147,6 +147,10 @@ namespace MetaFile
|
||||
if (BI_JPEG != unCompression || BI_PNG != unCompression)
|
||||
return false;
|
||||
|
||||
#ifdef METAFILE_DISABLE_FILESYSTEM
|
||||
return false;
|
||||
#endif
|
||||
|
||||
std::wstring wsTempFileName = GetTempFilename();
|
||||
if (wsTempFileName.empty())
|
||||
return false;
|
||||
@ -233,7 +237,9 @@ namespace MetaFile
|
||||
}
|
||||
for (int nAddIndex = 0; nAddIndex < nAdditBytes; nAddIndex++)
|
||||
{
|
||||
int nByte = *pBuffer; pBuffer++; lBufLen--;
|
||||
// int nByte = *pBuffer;
|
||||
++pBuffer;
|
||||
--lBufLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -267,7 +273,9 @@ namespace MetaFile
|
||||
}
|
||||
for (int nAddIndex = 0; nAddIndex < nAdditBytes; nAddIndex++)
|
||||
{
|
||||
int nByte = *pBuffer; pBuffer++; lBufLen--;
|
||||
// int nByte = *pBuffer;
|
||||
++pBuffer;
|
||||
--lBufLen;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -486,7 +494,12 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
if (lBufLen < (nWidth + nAdd) * abs(nHeight))
|
||||
{
|
||||
if (pUncompressedBuffer)
|
||||
delete[] pUncompressedBuffer;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
|
||||
if (NULL == pBgraBuffer)
|
||||
@ -639,7 +652,7 @@ namespace MetaFile
|
||||
*pulWidth = ulWidth;
|
||||
*pulHeight = ulHeight;
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
else if (BI_BITCOUNT_5 == ushBitCount)
|
||||
{
|
||||
@ -986,29 +999,6 @@ namespace MetaFile
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring ascii_to_unicode(const char *src)
|
||||
{
|
||||
size_t nSize = mbstowcs(0, src, 0);
|
||||
wchar_t* pBuffer = new wchar_t[nSize];
|
||||
nSize = mbstowcs(pBuffer, src, nSize);
|
||||
std::wstring sRes;
|
||||
if (nSize != (size_t)-1)
|
||||
sRes = std::wstring(pBuffer, nSize);
|
||||
delete[] pBuffer;
|
||||
return sRes;
|
||||
}
|
||||
std::string unicode_to_ascii(const wchar_t *src)
|
||||
{
|
||||
size_t nSize = wcstombs(0, src, 0);
|
||||
char* pBuffer = new char[nSize];
|
||||
nSize = wcstombs(pBuffer, src, nSize);
|
||||
std::string sRes;
|
||||
if (nSize != (size_t)-1)
|
||||
sRes = std::string(pBuffer, nSize);
|
||||
delete[] pBuffer;
|
||||
return sRes;
|
||||
}
|
||||
|
||||
std::wstring GetTempFilename(const std::wstring& sFolder)
|
||||
{
|
||||
std::wstring sTmpFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(sFolder.empty() ? NSFile::CFileBinary::GetTempPath() : sFolder, L"wmf");
|
||||
|
||||
@ -48,6 +48,8 @@ namespace MetaFile
|
||||
{
|
||||
bool Equals(double dFirst, double dSecond, double dEpsilon = DBL_EPSILON);
|
||||
std::wstring ConvertToUnicode(const unsigned char* pText, unsigned long unLength, unsigned short uchCharSet);
|
||||
std::wstring ConvertToWString(double dValue, int nAccuracy = -1);
|
||||
std::wstring ConvertToWString(const std::vector<double>& arValues, int nAccuracy = -1);
|
||||
|
||||
struct TRgbQuad
|
||||
{
|
||||
@ -88,13 +90,34 @@ namespace MetaFile
|
||||
};
|
||||
|
||||
typedef std::pair<const std::wstring, std::wstring> NodeAttribute;
|
||||
typedef std::vector<NodeAttribute> NodeAttributes;
|
||||
// typedef std::vector<NodeAttribute> NodeAttributes;
|
||||
|
||||
class NodeAttributes : public std::vector<NodeAttribute>
|
||||
{
|
||||
public:
|
||||
using std::vector<NodeAttribute>::vector;
|
||||
|
||||
void Add(const std::wstring& wsNameArgument, const std::wstring& wsValueArgument)
|
||||
{
|
||||
emplace_back(NodeAttribute{wsNameArgument, wsValueArgument});
|
||||
}
|
||||
|
||||
void Add(const std::wstring& wsNameArgument, const double& dValueArgument, int nAccuracy = -1)
|
||||
{
|
||||
emplace_back(NodeAttribute{wsNameArgument, ConvertToWString(dValueArgument, nAccuracy)});
|
||||
}
|
||||
|
||||
void Add(const std::wstring& wsNameArgument, const int& nValueArgument)
|
||||
{
|
||||
emplace_back(NodeAttribute{wsNameArgument, std::to_wstring(nValueArgument)});
|
||||
}
|
||||
};
|
||||
|
||||
class CDataStream
|
||||
{
|
||||
public:
|
||||
|
||||
CDataStream() : pBuffer(NULL), pBufferEnd(NULL), pEnd(NULL), pCur(NULL)
|
||||
CDataStream() : pBuffer(NULL), pBufferEnd(NULL), pCur(NULL), pEnd(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1159,8 +1182,5 @@ namespace MetaFile
|
||||
|
||||
std::wstring StringNormalization(const std::wstring& wsString);
|
||||
bool StringEquals(const std::wstring& wsFirstString, const std::wstring& wsSecondString);
|
||||
|
||||
std::wstring ConvertToWString(double dValue, int nAccuracy = -1);
|
||||
std::wstring ConvertToWString(const std::vector<double>& arValues, int nAccuracy = -1);
|
||||
};
|
||||
#endif // _METAFILE_COMMON_METAFILEUTILS_H
|
||||
|
||||
@ -41,7 +41,7 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
void CEmfInterpretatorRender::DrawString(std::wstring &wsText, unsigned int unCharsCount, double dX, double dY, double *pDx,
|
||||
int iGraphicsMode, double dXScale, double dYScale)
|
||||
int iGraphicsMode, double dXScale, double dYScale)
|
||||
{
|
||||
if (NULL != m_pMetaFileRenderer)
|
||||
m_pMetaFileRenderer->DrawString(wsText, unCharsCount, dX, dY, pDx, iGraphicsMode, dXScale, dYScale);
|
||||
|
||||
@ -33,7 +33,8 @@ namespace MetaFile
|
||||
return;
|
||||
|
||||
std::swap(m_pParser, m_oSecondConditional.m_pParser);
|
||||
std::swap(m_oClip, m_oSecondConditional.m_oClip);
|
||||
|
||||
SwapClips(m_oClip, m_oSecondConditional.m_oClip);
|
||||
}
|
||||
|
||||
InterpretatorType CEmfInterpretatorSvg::GetType() const
|
||||
@ -107,7 +108,7 @@ namespace MetaFile
|
||||
|
||||
if (NULL == pPath)
|
||||
return;
|
||||
|
||||
|
||||
const std::wstring wsValue = CreatePath(*pPath);
|
||||
|
||||
if (wsValue.empty())
|
||||
@ -117,6 +118,7 @@ namespace MetaFile
|
||||
|
||||
AddClip();
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
|
||||
WriteNode(L"path" , arAttributes);
|
||||
@ -175,6 +177,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
|
||||
if (AD_COUNTERCLOCKWISE == m_pParser->GetArcDirection())
|
||||
{
|
||||
@ -238,6 +241,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
|
||||
if (AD_COUNTERCLOCKWISE == m_pParser->GetArcDirection())
|
||||
{
|
||||
@ -292,6 +296,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
|
||||
if (AD_COUNTERCLOCKWISE == m_pParser->GetArcDirection())
|
||||
{
|
||||
@ -325,6 +330,7 @@ namespace MetaFile
|
||||
{L"ry", ConvertToWString((oNewRect.Bottom - oNewRect.Top) / 2)}};
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -365,6 +371,7 @@ namespace MetaFile
|
||||
{L"y2", ConvertToWString(oPoint.Y)}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -373,21 +380,29 @@ namespace MetaFile
|
||||
|
||||
void CEmfInterpretatorSvg::HANDLE_EMR_PIE(const TRectL &oBox, const TPointL &oStart, const TPointL &oEnd)
|
||||
{
|
||||
short shCenterX = (oBox.Left + oBox.Right) / 2;
|
||||
short shCenterY = (oBox.Top + oBox.Bottom) / 2;
|
||||
int nCenterX = (oBox.Left + oBox.Right) / 2;
|
||||
int nCenterY = (oBox.Top + oBox.Bottom) / 2;
|
||||
|
||||
short shRadiusX = std::abs(oBox.Right - oBox.Left) / 2;
|
||||
short shRadiusY = std::abs(oBox.Bottom - oBox.Top) / 2;
|
||||
|
||||
std::wstring wsPath = L'M' + ConvertToWString(shCenterX) + L' ' + ConvertToWString(shCenterY) + L' ' +
|
||||
double dStartAngle = std::atan2(oStart.Y - nCenterY, oStart.X - nCenterX);
|
||||
double dEndAngle = std::atan2(oEnd.Y - nCenterY, oEnd.X - nCenterX);
|
||||
|
||||
if (dEndAngle > dStartAngle)
|
||||
dEndAngle -= 2 * M_PI;
|
||||
|
||||
std::wstring wsPath = L'M' + ConvertToWString(nCenterX) + L' ' + ConvertToWString(nCenterY) + L' ' +
|
||||
L'L' + ConvertToWString(oStart.X)+ L' ' + ConvertToWString(oStart.Y)+ L' ' +
|
||||
L'A' + ConvertToWString(shRadiusX) + L' ' + ConvertToWString(shRadiusY) + L" 0, 0, 0, " + ConvertToWString(oEnd.X) + L' ' + ConvertToWString(oEnd.Y) + L' ' +
|
||||
L'L' + ConvertToWString(shCenterX) + L' ' + ConvertToWString(shCenterY) + L" Z";
|
||||
L'A' + ConvertToWString(shRadiusX) + L' ' + ConvertToWString(shRadiusY) + L" 0 " +
|
||||
((std::abs(dEndAngle - dStartAngle) > M_PI) ? L'1' : L'0') + L" 0 " + ConvertToWString(oEnd.X) + L' ' + ConvertToWString(oEnd.Y) + L' ' +
|
||||
L'L' + ConvertToWString(nCenterX) + L' ' + ConvertToWString(nCenterY) + L" Z";
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsPath}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -402,14 +417,15 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(arPoints[0].X) + L' ' + ConvertToWString(arPoints[0].Y) + L" C ";
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -424,14 +440,15 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(arPoints[0].X) + L' ' + ConvertToWString(arPoints[0].Y) + L" C ";
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -446,14 +463,15 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(arPoints[0].X) + L' ' + ConvertToWString(arPoints[0].Y) + L" C ";
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -468,14 +486,15 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(arPoints[0].X) + L' ' + ConvertToWString(arPoints[0].Y) + L" C ";
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -509,9 +528,9 @@ namespace MetaFile
|
||||
wsValue += L" C ";
|
||||
oLastType = 0x04;
|
||||
}
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L',' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L',' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L',' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L',' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L',' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L',' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
|
||||
unIndex += 3;
|
||||
}
|
||||
@ -526,6 +545,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -559,9 +579,9 @@ namespace MetaFile
|
||||
wsValue += L" C ";
|
||||
oLastType = 0x04;
|
||||
}
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L',' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L',' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L',' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L',' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L',' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L',' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
|
||||
unIndex += 3;
|
||||
}
|
||||
@ -576,6 +596,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -596,6 +617,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -616,6 +638,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -636,6 +659,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -658,6 +682,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -680,6 +705,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -702,6 +728,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -729,10 +756,11 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
arAttributes.push_back({L"fill-rule", L"evenodd"});
|
||||
arAttributes.Add(L"fill-rule", L"evenodd");
|
||||
|
||||
WriteNode(L"path", arAttributes);
|
||||
}
|
||||
@ -758,10 +786,11 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
arAttributes.push_back({L"fill-rule", L"evenodd"});
|
||||
arAttributes.Add(L"fill-rule", L"evenodd");
|
||||
|
||||
WriteNode(L"path", arAttributes);
|
||||
}
|
||||
@ -787,10 +816,11 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
arAttributes.push_back({L"fill-rule", L"evenodd"});
|
||||
arAttributes.Add(L"fill-rule", L"evenodd");
|
||||
|
||||
WriteNode(L"path", arAttributes);
|
||||
}
|
||||
@ -816,10 +846,11 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
arAttributes.push_back({L"fill-rule", L"evenodd"});
|
||||
arAttributes.Add(L"fill-rule", L"evenodd");
|
||||
|
||||
WriteNode(L"path", arAttributes);
|
||||
}
|
||||
@ -828,13 +859,14 @@ namespace MetaFile
|
||||
{
|
||||
TRectD oNewRect = TranslateRect(oBox);
|
||||
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.Left)},
|
||||
{L"y", ConvertToWString(oNewRect.Top)},
|
||||
{L"width", ConvertToWString(oNewRect.Right - oNewRect.Left)},
|
||||
{L"height", ConvertToWString(oNewRect.Bottom - oNewRect.Top)}};
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.Left)},
|
||||
{L"y", ConvertToWString(oNewRect.Top)},
|
||||
{L"width", ConvertToWString(oNewRect.Right - oNewRect.Left)},
|
||||
{L"height", ConvertToWString(oNewRect.Bottom - oNewRect.Top)}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes, oNewRect.Right - oNewRect.Left, oNewRect.Bottom - oNewRect.Top);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -845,15 +877,16 @@ namespace MetaFile
|
||||
{
|
||||
TRectD oNewRect = TranslateRect(oBox);
|
||||
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.Left)},
|
||||
{L"y", ConvertToWString(oNewRect.Top)},
|
||||
{L"width", ConvertToWString(oNewRect.Right - oNewRect.Left)},
|
||||
{L"height", ConvertToWString(oNewRect.Bottom - oNewRect.Top)},
|
||||
{L"rx", ConvertToWString((double)oCorner.X / 2.)},
|
||||
{L"ry", ConvertToWString((double)oCorner.Y / 2.)}};
|
||||
NodeAttributes arAttributes = {{L"x", ConvertToWString(oNewRect.Left)},
|
||||
{L"y", ConvertToWString(oNewRect.Top)},
|
||||
{L"width", ConvertToWString(oNewRect.Right - oNewRect.Left)},
|
||||
{L"height", ConvertToWString(oNewRect.Bottom - oNewRect.Top)},
|
||||
{L"rx", ConvertToWString((double)oCorner.X / 2.)},
|
||||
{L"ry", ConvertToWString((double)oCorner.Y / 2.)}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -889,6 +922,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddFill(arAttributes, std::fabs(oBounds.Right - oBounds.Left), std::fabs(oBounds.Bottom - oBounds.Top));
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -914,6 +948,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -928,15 +963,16 @@ namespace MetaFile
|
||||
NodeAttributes arAttributes;
|
||||
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
if (4 == arVertex.size())
|
||||
{
|
||||
arAttributes.push_back({L"x", ConvertToWString(std::min(arVertex[0].nX, arVertex[1].nX))});
|
||||
arAttributes.push_back({L"y", ConvertToWString(std::min(arVertex[0].nY, arVertex[2].nY))});
|
||||
arAttributes.push_back({L"width", ConvertToWString(std::abs(arVertex[1].nX - arVertex[0].nX))});
|
||||
arAttributes.push_back({L"height", ConvertToWString(std::abs(arVertex[2].nY - arVertex[0].nY))});
|
||||
arAttributes.Add(L"x", std::min(arVertex[0].nX, arVertex[1].nX));
|
||||
arAttributes.Add(L"y", std::min(arVertex[0].nY, arVertex[2].nY));
|
||||
arAttributes.Add(L"width", std::abs(arVertex[1].nX - arVertex[0].nX));
|
||||
arAttributes.Add(L"height", std::abs(arVertex[2].nY - arVertex[0].nY));
|
||||
WriteNode(L"rect" , arAttributes);
|
||||
}
|
||||
else if (3 == arVertex.size())
|
||||
@ -950,7 +986,7 @@ namespace MetaFile
|
||||
std::wstring wsValue = CreatePath(oPath);
|
||||
|
||||
if (!wsValue.empty())
|
||||
arAttributes.push_back({L"d", wsValue});
|
||||
arAttributes.Add(L"d", wsValue);
|
||||
|
||||
WriteNode(L"path" , arAttributes);
|
||||
}
|
||||
@ -969,16 +1005,17 @@ namespace MetaFile
|
||||
{
|
||||
oTempRect = TranslateRect(oRect);
|
||||
|
||||
wsValue += L"M " + ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
L"L " + ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ';
|
||||
wsValue += L"M " + ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
L"L " + ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ';
|
||||
}
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -998,16 +1035,17 @@ namespace MetaFile
|
||||
{
|
||||
oTempRect = TranslateRect(oRect);
|
||||
|
||||
wsValue += L"M " + ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
L"L " + ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ';
|
||||
wsValue += L"M " + ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
L"L " + ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ';
|
||||
}
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1016,6 +1054,7 @@ namespace MetaFile
|
||||
|
||||
void CEmfInterpretatorSvg::HANDLE_EMR_FRAMERGN(const TRectL &oBounds, unsigned int unIhBrush, int nWidth, int nHeight, const TRegionDataHeader &oRegionDataHeader, const std::vector<TRectL> &arRects)
|
||||
{
|
||||
m_bUpdatedClip = false;
|
||||
}
|
||||
|
||||
void CEmfInterpretatorSvg::HANDLE_EMFPLUS_OFFSETCLIP(double dX, double dY)
|
||||
@ -1085,6 +1124,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
|
||||
if (AD_COUNTERCLOCKWISE == m_pParser->GetArcDirection())
|
||||
{
|
||||
@ -1111,14 +1151,15 @@ namespace MetaFile
|
||||
std::wstring wsValue = L"M " + ConvertToWString(arPoints[0].X) + L' ' + ConvertToWString(arPoints[0].Y) + L" C ";
|
||||
|
||||
for (unsigned int unIndex = 1; unIndex + 2 < arPoints.size(); unIndex += 3)
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
wsValue += ConvertToWString(arPoints[unIndex].X) + L' ' + ConvertToWString(arPoints[unIndex].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 1].X) + L' ' + ConvertToWString(arPoints[unIndex + 1].Y) + L' ' +
|
||||
ConvertToWString(arPoints[unIndex + 2].X) + L' ' + ConvertToWString(arPoints[unIndex + 2].Y) + L' ';
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1158,14 +1199,14 @@ namespace MetaFile
|
||||
int nColor = m_pParser->GetTextColor();
|
||||
|
||||
if (0 != nColor)
|
||||
arNodeAttributes.push_back({L"fill", CalculateColor(nColor, 255)});
|
||||
arNodeAttributes.Add(L"fill", CalculateColor(nColor, 255));
|
||||
|
||||
double dFontHeight = std::fabs(pFont->GetHeight());
|
||||
|
||||
if (dFontHeight < 0.01)
|
||||
dFontHeight = 18;
|
||||
|
||||
arNodeAttributes.push_back({L"font-size", ConvertToWString(dFontHeight)});
|
||||
arNodeAttributes.Add(L"font-size", dFontHeight);
|
||||
|
||||
NSStringUtils::CStringBuilder oFontName;
|
||||
oFontName.WriteEncodeXmlString(pFont->GetFaceName());
|
||||
@ -1188,21 +1229,21 @@ namespace MetaFile
|
||||
oFontName.WriteEncodeXmlString(L"\'");
|
||||
}
|
||||
#endif
|
||||
arNodeAttributes.push_back({L"font-family", oFontName.GetData()});
|
||||
arNodeAttributes.Add(L"font-family", oFontName.GetData());
|
||||
}
|
||||
|
||||
if (pFont->GetWeight() > 550)
|
||||
arNodeAttributes.push_back({L"font-weight", L"bold"});
|
||||
arNodeAttributes.Add(L"font-weight", L"bold");
|
||||
|
||||
if (pFont->IsItalic())
|
||||
arNodeAttributes.push_back({L"font-style", L"italic"});
|
||||
arNodeAttributes.Add(L"font-style", L"italic");
|
||||
|
||||
if (pFont->IsUnderline() && pFont->IsStrikeOut())
|
||||
arNodeAttributes.push_back({L"text-decoration", L"underline line-through"});
|
||||
arNodeAttributes.Add(L"text-decoration", L"underline line-through");
|
||||
else if (pFont->IsUnderline())
|
||||
arNodeAttributes.push_back({L"text-decoration", L"underline"});
|
||||
arNodeAttributes.Add(L"text-decoration", L"underline");
|
||||
else if (pFont->IsStrikeOut())
|
||||
arNodeAttributes.push_back({L"text-decoration", L"line-through"});
|
||||
arNodeAttributes.Add(L"text-decoration", L"line-through");
|
||||
|
||||
AddTransform(arNodeAttributes);
|
||||
AddClip();
|
||||
@ -1218,8 +1259,8 @@ namespace MetaFile
|
||||
wsX.pop_back();
|
||||
wsY.pop_back();
|
||||
|
||||
arNodeAttributes.push_back({L"x", wsX});
|
||||
arNodeAttributes.push_back({L"y", wsY});
|
||||
arNodeAttributes.Add(L"x", wsX);
|
||||
arNodeAttributes.Add(L"y", wsY);
|
||||
|
||||
WriteNode(L"text", arNodeAttributes, wsText);
|
||||
}
|
||||
@ -1234,6 +1275,7 @@ namespace MetaFile
|
||||
{L"ry", ConvertToWString((oNewRect.Bottom - oNewRect.Top) / 2)}};
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1254,6 +1296,7 @@ namespace MetaFile
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1273,7 +1316,9 @@ namespace MetaFile
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddLineCaps(arAttributes, pPath);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1295,17 +1340,18 @@ namespace MetaFile
|
||||
{
|
||||
oTempRect = oRect.ToRectD();
|
||||
|
||||
wsValue += L"M " + ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) +
|
||||
L" L " + ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ';
|
||||
wsValue += L"M " + ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) +
|
||||
L" L " + ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ';
|
||||
}
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddStroke(arAttributes);
|
||||
AddNoneFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1332,6 +1378,7 @@ namespace MetaFile
|
||||
{L"ry", ConvertToWString((oNewRect.Bottom - oNewRect.Top) / 2)}};
|
||||
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1353,6 +1400,7 @@ namespace MetaFile
|
||||
TRectD oPathRect = pPath->GetBounds();
|
||||
|
||||
AddFill(arAttributes, std::fabs(oPathRect.Right - oPathRect.Left), std::fabs(oPathRect.Bottom - oPathRect.Top));
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
AddClip();
|
||||
|
||||
@ -1377,6 +1425,7 @@ namespace MetaFile
|
||||
NodeAttributes arAttributes = {{L"points", wsValue}};
|
||||
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes);
|
||||
|
||||
NodeAttributes arGAttributes;
|
||||
@ -1387,17 +1436,18 @@ namespace MetaFile
|
||||
|
||||
void CEmfInterpretatorSvg::HANDLE_EMFPLUS_FILLRECTS(unsigned int unBrushId, const std::vector<TEmfPlusRectF> &arRects)
|
||||
{
|
||||
if (arRects.empty())
|
||||
return;
|
||||
|
||||
std::wstring wsValue;
|
||||
|
||||
TRectD oTempRect;
|
||||
TXForm oFileTransform(m_pParser->GetTransform());
|
||||
|
||||
for (const TEmfPlusRectF& oRect : arRects)
|
||||
{
|
||||
oTempRect = oRect.ToRectD();
|
||||
|
||||
m_pParser->GetTransform().Apply(oTempRect.Left, oTempRect.Top);
|
||||
m_pParser->GetTransform().Apply(oTempRect.Right, oTempRect.Bottom);
|
||||
|
||||
wsValue += L"M " + ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) +
|
||||
L" L " + ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Top) + L' ' +
|
||||
ConvertToWString(oTempRect.Right) + L',' + ConvertToWString(oTempRect.Bottom) + L' ' +
|
||||
@ -1405,9 +1455,13 @@ namespace MetaFile
|
||||
ConvertToWString(oTempRect.Left) + L',' + ConvertToWString(oTempRect.Top) + L' ';
|
||||
}
|
||||
|
||||
wsValue.pop_back();
|
||||
|
||||
NodeAttributes arAttributes = {{L"d", wsValue}};
|
||||
|
||||
AddTransform(arAttributes);
|
||||
AddFill(arAttributes);
|
||||
AddShapeRendering(arAttributes);
|
||||
AddClip();
|
||||
|
||||
WriteNode(L"path", arAttributes);
|
||||
@ -1448,25 +1502,15 @@ namespace MetaFile
|
||||
CInterpretatorSvgBase::PathClip(oPath, nClipMode, pTransform);
|
||||
}
|
||||
|
||||
TRectD CEmfInterpretatorSvg::TranslateRect(const TRectL &oRect) const
|
||||
void CEmfInterpretatorSvg::SwapClips(CSvgClip& oFirstClip, CSvgClip& oSecondClip)
|
||||
{
|
||||
TRectD oNewRect(oRect.Left, oRect.Top, oRect.Right, oRect.Bottom);
|
||||
if (oFirstClip.StartedClip())
|
||||
WriteNodeEnd(L"g");
|
||||
|
||||
if (oNewRect.Right < oNewRect.Left)
|
||||
{
|
||||
double dTempValue = oNewRect.Left;
|
||||
oNewRect.Left = oNewRect.Right;
|
||||
oNewRect.Right = dTempValue;
|
||||
}
|
||||
if (oSecondClip.StartedClip())
|
||||
WriteNodeBegin(L"g", {{L"clip-path", L"url(#" + oSecondClip.GetClipId() + L')'}});
|
||||
|
||||
if (oNewRect.Bottom < oNewRect.Top)
|
||||
{
|
||||
double dTempValue = oNewRect.Top;
|
||||
oNewRect.Top = oNewRect.Bottom;
|
||||
oNewRect.Bottom = dTempValue;
|
||||
}
|
||||
|
||||
return oNewRect;
|
||||
std::swap(oFirstClip, oSecondClip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -226,7 +226,7 @@ namespace MetaFile
|
||||
void SetTransform(double& dM11, double& dM12, double& dM21, double& dM22, double& dX, double& dY) override {};
|
||||
void GetTransform(double* pdM11, double* pdM12, double* pdM21, double* pdM22, double* pdX, double* pdY) override {};
|
||||
|
||||
TRectD TranslateRect(const TRectL &oRect) const;
|
||||
void SwapClips(CSvgClip& oFirstClip, CSvgClip& oSecondClip);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
*
|
||||
*/
|
||||
#include "../../../raster/ImageFileFormatChecker.h"
|
||||
#include "../../../graphics/Image.h"
|
||||
|
||||
#include "../Common/MetaFileUtils.h"
|
||||
|
||||
@ -155,9 +154,38 @@ namespace MetaFile
|
||||
unHeight = unDibHeigth;
|
||||
}
|
||||
|
||||
CEmfLogFont::CEmfLogFont(bool bFixedLength) : m_bFixedLength(bFixedLength)
|
||||
void CEmfLogBrushEx::GetGradientColors(std::vector<long>& arColors, std::vector<double>& arPositions) const
|
||||
{
|
||||
arColors = {(long)(GetColor() + (GetAlpha() << 24)), (long)(GetColor2() + (GetAlpha2() << 24))};
|
||||
arPositions = {0., 1.};
|
||||
}
|
||||
|
||||
CEmfLogFont::CEmfLogFont(bool bFixedLength)
|
||||
: m_bFixedLength(bFixedLength)
|
||||
{
|
||||
oDesignVector.pValues = NULL;
|
||||
|
||||
oLogFontEx.oLogFont.nHeight = DEFAULT_FONT_SIZE;
|
||||
oLogFontEx.oLogFont.nWidth = 0;
|
||||
oLogFontEx.oLogFont.nEscapement = 0;
|
||||
oLogFontEx.oLogFont.nOrientation = 0;
|
||||
oLogFontEx.oLogFont.nWeight = 400;
|
||||
oLogFontEx.oLogFont.uchItalic = 0x00;
|
||||
oLogFontEx.oLogFont.uchUnderline = 0x00;
|
||||
oLogFontEx.oLogFont.uchStrikeOut = 0x00;
|
||||
oLogFontEx.oLogFont.uchCharSet = 0x01;
|
||||
oLogFontEx.oLogFont.uchOutPrecision = 0x00;
|
||||
oLogFontEx.oLogFont.uchClipPrecision = 0x00;
|
||||
oLogFontEx.oLogFont.uchQuality = 0x00;
|
||||
oLogFontEx.oLogFont.uchPitchAndFamily = 0x00;
|
||||
|
||||
memset(oLogFontEx.oLogFont.ushFaceName, 0x00, 32);
|
||||
|
||||
oLogFontEx.oLogFont.ushFaceName[0] = 'A';
|
||||
oLogFontEx.oLogFont.ushFaceName[1] = 'r';
|
||||
oLogFontEx.oLogFont.ushFaceName[2] = 'i';
|
||||
oLogFontEx.oLogFont.ushFaceName[3] = 'a';
|
||||
oLogFontEx.oLogFont.ushFaceName[4] = 'l';
|
||||
}
|
||||
|
||||
CEmfLogFont::~CEmfLogFont()
|
||||
@ -271,6 +299,16 @@ namespace MetaFile
|
||||
unSize = 0;
|
||||
}
|
||||
|
||||
const ILineCap* CEmfLogPen::GetStartLineCap() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const ILineCap* CEmfLogPen::GetEndLineCap() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CEmfLogPalette::CEmfLogPalette() : ushNumberOfEntries(0), pPaletteEntries(NULL)
|
||||
{}
|
||||
|
||||
|
||||
@ -77,6 +77,8 @@ namespace MetaFile
|
||||
void GetBounds(double& left, double& top, double& width, double& height) const override;
|
||||
void GetCenterPoint(double& dX, double& dY) const override;
|
||||
void GetDibPattern(unsigned char** pBuffer, unsigned int &unWidth, unsigned int &unHeight) const override;
|
||||
|
||||
void GetGradientColors(std::vector<long>& arColors, std::vector<double>& arPositions) const override;
|
||||
public:
|
||||
unsigned int unBrushStyle;
|
||||
TRGBA oColor;
|
||||
@ -122,13 +124,15 @@ namespace MetaFile
|
||||
virtual EEmfObjectType GetType() const override;
|
||||
|
||||
// IPen
|
||||
int GetColor() const override;
|
||||
unsigned int GetStyle() const override;
|
||||
double GetWidth() const override;
|
||||
unsigned int GetAlpha() const override;
|
||||
double GetMiterLimit() const override;
|
||||
double GetDashOffset() const override;
|
||||
void GetDashData(double*& arDatas, unsigned int& unSize) const override;
|
||||
int GetColor() const override;
|
||||
unsigned int GetStyle() const override;
|
||||
double GetWidth() const override;
|
||||
unsigned int GetAlpha() const override;
|
||||
double GetMiterLimit() const override;
|
||||
double GetDashOffset() const override;
|
||||
void GetDashData(double*& arDatas, unsigned int& unSize) const override;
|
||||
const ILineCap* GetStartLineCap() const override;
|
||||
const ILineCap* GetEndLineCap() const override;
|
||||
public:
|
||||
unsigned int unPenStyle;
|
||||
unsigned int unWidth;
|
||||
|
||||
@ -593,6 +593,8 @@ namespace MetaFile
|
||||
|
||||
if (!BanEMFProcesses())
|
||||
HANDLE_EMR_CREATEBRUSHINDIRECT(ulBrushIndex, pBrush);
|
||||
else
|
||||
delete pBrush;
|
||||
}
|
||||
|
||||
void CEmfParser::Read_EMR_SETTEXTCOLOR()
|
||||
@ -630,6 +632,8 @@ namespace MetaFile
|
||||
|
||||
if (!BanEMFProcesses())
|
||||
HANDLE_EMR_EXTCREATEFONTINDIRECTW(ulIndex, pFont);
|
||||
else
|
||||
delete pFont;
|
||||
}
|
||||
|
||||
void CEmfParser::Read_EMR_SETTEXTALIGN()
|
||||
@ -722,6 +726,8 @@ namespace MetaFile
|
||||
|
||||
if (!BanEMFProcesses())
|
||||
HANDLE_EMR_EXTCREATEPEN(ulPenIndex, pPen, arUnused);
|
||||
else
|
||||
delete pPen;
|
||||
}
|
||||
|
||||
void CEmfParser::Read_EMR_CREATEPEN()
|
||||
@ -744,6 +750,8 @@ namespace MetaFile
|
||||
|
||||
if (!BanEMFProcesses())
|
||||
HANDLE_EMR_CREATEPEN(ulPenIndex, widthX, pPen);
|
||||
else
|
||||
delete pPen;
|
||||
}
|
||||
|
||||
void CEmfParser::Read_EMR_SETPOLYFILLMODE()
|
||||
@ -1011,6 +1019,8 @@ namespace MetaFile
|
||||
|
||||
if (!BanEMFProcesses())
|
||||
HANDLE_EMR_CREATEPALETTE(ulPaletteIndex, pPalette);
|
||||
else
|
||||
delete pPalette;
|
||||
}
|
||||
|
||||
void CEmfParser::Read_EMR_SELECTPALETTE()
|
||||
@ -1659,13 +1669,15 @@ namespace MetaFile
|
||||
|
||||
RestoreDC(-1);
|
||||
}
|
||||
else if (sType == "GDIC")
|
||||
else if (sType == "GDIC" && NULL != m_pInterpretator)
|
||||
{
|
||||
unsigned int unPublicCommentIdentifier;
|
||||
|
||||
m_oStream >> unPublicCommentIdentifier;
|
||||
|
||||
if (EMR_COMMENT_WINDOWS_METAFILE == unPublicCommentIdentifier)
|
||||
// At the moment, we are disabling support for embedded MWF files (in bug #71100 - The plus-minus symbol is not displayed correctly)
|
||||
// From the tests, it became clear that the embedded WMF files are ignored
|
||||
if (EMR_COMMENT_WINDOWS_METAFILE == unPublicCommentIdentifier && false)
|
||||
{
|
||||
m_oStream.Skip(12); // Version, Reserved, Checksum, Flags
|
||||
|
||||
|
||||
@ -78,8 +78,8 @@ namespace MetaFile
|
||||
unsigned int ulWidth, ulHeight;
|
||||
|
||||
if (ReadImage(oTEmfStretchDIBITS.unOffBmiSrc, oTEmfStretchDIBITS.unCbBmiSrc,
|
||||
oTEmfStretchDIBITS.unOffBitsSrc, oTEmfStretchDIBITS.unCbBitsSrc,
|
||||
sizeof(TEmfStretchDIBITS) + 8, &pBgraBuffer, &ulWidth, &ulHeight))
|
||||
oTEmfStretchDIBITS.unOffBitsSrc, oTEmfStretchDIBITS.unCbBitsSrc,
|
||||
sizeof(TEmfStretchDIBITS) + 8, &pBgraBuffer, &ulWidth, &ulHeight))
|
||||
{
|
||||
if (m_pInterpretator)
|
||||
{
|
||||
@ -761,7 +761,11 @@ namespace MetaFile
|
||||
RELEASEOBJECT(m_pInterpretator);
|
||||
|
||||
if (InterpretatorType::Svg == oInterpretatorType)
|
||||
m_pInterpretator = new CEmfInterpretatorSvg(this, dWidth, dHeight);
|
||||
{
|
||||
CEmfInterpretatorSvg *pEmfInterpretatorSvg = new CEmfInterpretatorSvg(this, dWidth, dHeight);
|
||||
pEmfInterpretatorSvg->SetShapeRendering(EShapeRendering::OptimizeSpeed);
|
||||
m_pInterpretator = pEmfInterpretatorSvg;
|
||||
}
|
||||
}
|
||||
|
||||
CEmfInterpretatorBase* CEmfParserBase::GetInterpretator()
|
||||
@ -1505,11 +1509,19 @@ namespace MetaFile
|
||||
if (NULL != m_pInterpretator && (NULL == m_pPath || Svg != m_pInterpretator->GetType()))
|
||||
m_pInterpretator->HANDLE_EMR_PIE(oBox, oStart, oEnd);
|
||||
|
||||
double dStartAngle = GetEllipseAngle(oBox.Left, oBox.Top, oBox.Right, oBox.Bottom, oStart.X, oStart.Y);
|
||||
double dSweepAngle = GetEllipseAngle(oBox.Left, oBox.Top, oBox.Right, oBox.Bottom, oEnd.X, oEnd.Y) - dStartAngle;
|
||||
const int nCenterX = (oBox.Left + oBox.Right) / 2;
|
||||
const int nCenterY = (oBox.Top + oBox.Bottom) / 2;
|
||||
|
||||
ArcTo(oBox.Left, oBox.Top, oBox.Right, oBox.Bottom, dStartAngle, dSweepAngle);
|
||||
LineTo((oBox.Left + oBox.Right) / 2, (oBox.Top + oBox.Bottom) / 2);
|
||||
double dStartAngle = std::atan2(oStart.Y - nCenterY, oStart.X - nCenterX);
|
||||
double dEndAngle = std::atan2(oEnd.Y - nCenterY, oEnd.X - nCenterX);
|
||||
|
||||
if (dEndAngle > dStartAngle)
|
||||
dEndAngle -= 2 * M_PI;
|
||||
|
||||
MoveTo(nCenterX, nCenterY);
|
||||
LineTo(oStart.X, oStart.Y);
|
||||
ArcTo(oBox.Left, oBox.Top, oBox.Right, oBox.Bottom, dStartAngle * 180. / M_PI, (dEndAngle - dStartAngle) * 180. / M_PI);
|
||||
LineTo(nCenterX, nCenterY);
|
||||
ClosePath();
|
||||
DrawPath(true, true);
|
||||
}
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
#ifndef CEMFPARSERBASE_H
|
||||
#define CEMFPARSERBASE_H
|
||||
|
||||
//#include "../EmfTypes.h"
|
||||
//#include "../EmfObjects.h"
|
||||
//#include "../../Common/MetaFileUtils.h"
|
||||
|
||||
#include "../EmfPlayer.h"
|
||||
|
||||
#include "../../Common/MetaFile.h"
|
||||
@ -25,7 +21,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
|
||||
#define LOG_EMF_RECORDS 0
|
||||
#define LOG_EMF_RECORDS 1
|
||||
|
||||
#ifdef LOG_EMF_RECORDS
|
||||
#if 1 == LOG_EMF_RECORDS
|
||||
|
||||
@ -67,15 +67,11 @@
|
||||
#define EMFPLUS_TRANSLATEWORLDTRANSFORM 0x402D
|
||||
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
#include "CEmfParser.h"
|
||||
#include "../../Wmf/WmfFile.h"
|
||||
#include "../../Wmf/WmfInterpretator/CWmfInterpretatorSvg.h"
|
||||
|
||||
#include "../EmfInterpretator/CEmfInterpretator.h"
|
||||
#include "../EmfInterpretator/CEmfInterpretatorSvg.h"
|
||||
#include "../EmfInterpretator/CEmfInterpretatorArray.h"
|
||||
#include "../EmfInterpretator/CEmfInterpretatorRender.h"
|
||||
|
||||
#ifdef METAFILE_SUPPORT_WMF_EMF_XML
|
||||
@ -655,20 +651,18 @@ namespace MetaFile
|
||||
|
||||
m_oStream >> unPositionCount;
|
||||
|
||||
std::vector<double> arBlendPositions(unPositionCount);
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex)
|
||||
m_oStream >> arBlendPositions[unIndex];
|
||||
|
||||
std::vector<TEmfPlusARGB> arBlendColors(unPositionCount);
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex)
|
||||
m_oStream >> arBlendColors[unIndex];
|
||||
|
||||
if (1 < unPositionCount)
|
||||
if (unPositionCount > 1)
|
||||
{
|
||||
pEmfPlusBrush->oColorBack = arBlendColors[0];
|
||||
pEmfPlusBrush->oColor = arBlendColors.back();
|
||||
pEmfPlusBrush->arGradientColors.resize(unPositionCount);
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex)
|
||||
m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].second;
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex)
|
||||
m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].first;
|
||||
|
||||
pEmfPlusBrush->oColor = pEmfPlusBrush->arGradientColors.back() .first;
|
||||
pEmfPlusBrush->oColorBack = pEmfPlusBrush->arGradientColors.front().first;
|
||||
}
|
||||
}
|
||||
|
||||
@ -679,13 +673,40 @@ namespace MetaFile
|
||||
//TODO: реализовать
|
||||
pEmfPlusBrush->unStyle = BS_LINEARGRADIENT;
|
||||
|
||||
m_oStream.Skip(8); // BrushDataFlags, WrapMode
|
||||
int nBrushDataFlags;
|
||||
m_oStream >> nBrushDataFlags;
|
||||
|
||||
m_oStream.Skip(4); // WrapMode
|
||||
|
||||
// m_oStream >> pEmfPlusBrush->RectF;
|
||||
m_oStream.Skip(16);
|
||||
m_oStream >> pEmfPlusBrush->oColor;
|
||||
m_oStream >> pEmfPlusBrush->oColorBack;
|
||||
|
||||
m_oStream.Skip(8); // Reserved1, Reserved2
|
||||
|
||||
if (BrushDataTransform & nBrushDataFlags)
|
||||
{
|
||||
m_oStream.Skip(24);
|
||||
}
|
||||
|
||||
if (BrushDataPresetColors & nBrushDataFlags)
|
||||
{
|
||||
int nPositionCount;
|
||||
m_oStream >> nPositionCount;
|
||||
|
||||
if (nPositionCount > 1)
|
||||
{
|
||||
pEmfPlusBrush->arGradientColors.resize(nPositionCount);
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < nPositionCount; ++unIndex)
|
||||
m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].second;
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < nPositionCount; ++unIndex)
|
||||
m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].first;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -750,7 +771,7 @@ namespace MetaFile
|
||||
|
||||
switch (nEndCap)
|
||||
{
|
||||
case 0: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_FLAT; break;
|
||||
case 0: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_FLAT; break;
|
||||
case 1: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_SQUARE; break;
|
||||
case 2: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_ROUND; break;
|
||||
}
|
||||
@ -763,7 +784,7 @@ namespace MetaFile
|
||||
|
||||
switch (nJoin)
|
||||
{
|
||||
case 0: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_MITER; break;
|
||||
case 0: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_MITER; break;
|
||||
case 1: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_BEVEL; break;
|
||||
case 2: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_ENDCAP_ROUND; break;
|
||||
}
|
||||
@ -849,7 +870,7 @@ namespace MetaFile
|
||||
m_oStream >> *pLineCapData;
|
||||
|
||||
if (CustomLineCapDataFillPath == pLineCapData->unCustomLineCapDataFlags ||
|
||||
CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags)
|
||||
CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags)
|
||||
{
|
||||
m_oStream.Skip(4); // FillPathLength or LinePathLength
|
||||
pLineCapData->pPath = ReadPath();
|
||||
@ -1321,7 +1342,7 @@ namespace MetaFile
|
||||
if (oImageAttributes.eWrapMode == WrapModeClamp)
|
||||
{
|
||||
if (oRectangle.dX < 0 || oRectangle.dX < 0 ||
|
||||
oRectangle.dX >= oRectangle.dWidth || oRectangle.dY >= oRectangle.dHeight)
|
||||
oRectangle.dX >= oRectangle.dWidth || oRectangle.dY >= oRectangle.dHeight)
|
||||
return oImageAttributes.oClampColor;
|
||||
|
||||
}
|
||||
@ -1519,14 +1540,10 @@ namespace MetaFile
|
||||
case MetafileDataTypeEmf:
|
||||
case MetafileDataTypeEmfPlusOnly:
|
||||
case MetafileDataTypeEmfPlusDual:
|
||||
{
|
||||
return DrawMetafile<CEmfParser>(pBuffer, unSizeBuffer, oSrcRect, arPoints);
|
||||
}
|
||||
case MetafileDataTypeWmf:
|
||||
case MetafileDataTypeWmfPlaceable:
|
||||
{
|
||||
return DrawMetafile<CWmfParser>(pBuffer, unSizeBuffer, oSrcRect, arPoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1639,7 +1656,7 @@ namespace MetaFile
|
||||
BYTE* pNewBuffer = GetClipedImage(pPixels, nWidth, nHeight, oClipRect, nW, nH);
|
||||
|
||||
m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X - m_pDC->GetPixelWidth(), arPoints[2].Y - arPoints[0].Y - m_pDC->GetPixelHeight(),
|
||||
(NULL != pNewBuffer) ? pNewBuffer : pPixels, nW, nH);
|
||||
(NULL != pNewBuffer) ? pNewBuffer : pPixels, nW, nH);
|
||||
|
||||
RELEASEINTERFACE(pGrRenderer);
|
||||
RELEASEARRAYOBJECTS(pNewBuffer);
|
||||
@ -1718,7 +1735,7 @@ namespace MetaFile
|
||||
BYTE* pNewBuffer = GetClipedImage(pBytes, unWidth, unHeight, oClipRect, nW, nH);
|
||||
|
||||
m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X, arPoints[2].Y - arPoints[0].Y,
|
||||
(NULL != pNewBuffer) ? pNewBuffer : pBytes, nW, nH);
|
||||
(NULL != pNewBuffer) ? pNewBuffer : pBytes, nW, nH);
|
||||
|
||||
if (!bExternalBuffer)
|
||||
RELEASEARRAYOBJECTS(pBytes);
|
||||
@ -1781,17 +1798,15 @@ namespace MetaFile
|
||||
m_pDC->SetPen(pPen);
|
||||
|
||||
if (AD_COUNTERCLOCKWISE != m_pDC->GetArcDirection())
|
||||
{
|
||||
dSweepAngle = dSweepAngle - 360;
|
||||
}
|
||||
|
||||
TEmfPlusRectF oConvertedRect = GetConvertedRectangle(oRect);
|
||||
|
||||
MoveTo(oConvertedRect.dX, oConvertedRect.dY);
|
||||
ArcTo(oConvertedRect.dX, oConvertedRect.dY,
|
||||
oConvertedRect.dX + oConvertedRect.dWidth,
|
||||
oConvertedRect.dY + oConvertedRect.dHeight,
|
||||
dStartAngle, dSweepAngle);
|
||||
oConvertedRect.dX + oConvertedRect.dWidth,
|
||||
oConvertedRect.dY + oConvertedRect.dHeight,
|
||||
dStartAngle, dSweepAngle);
|
||||
DrawPath(true, false);
|
||||
|
||||
if (NULL != m_pInterpretator)
|
||||
@ -2266,16 +2281,21 @@ namespace MetaFile
|
||||
if (NULL != pEmfPlusPen->pBrush)
|
||||
m_pDC->SetBrush(pEmfPlusPen->pBrush);
|
||||
|
||||
CPathConverter oPathConverter;
|
||||
CPath oNewPath, oLineCapPath;
|
||||
|
||||
oPathConverter.GetUpdatedPath(oNewPath, oLineCapPath, *pPath, *pEmfPlusPen);
|
||||
|
||||
oNewPath.DrawOn(m_pInterpretator, true, false);
|
||||
oLineCapPath.DrawOn(m_pInterpretator, false, true);
|
||||
|
||||
if (NULL != m_pInterpretator)
|
||||
m_pInterpretator->HANDLE_EMFPLUS_DRAWPATH(shOgjectIndex, unPenId, &oNewPath);
|
||||
{
|
||||
if (InterpretatorType::Render == m_pInterpretator->GetType())
|
||||
{
|
||||
CPathConverter oPathConverter;
|
||||
CPath oNewPath, oLineCapPath;
|
||||
|
||||
oPathConverter.GetUpdatedPath(oNewPath, oLineCapPath, *pPath, *pEmfPlusPen);
|
||||
|
||||
oNewPath.DrawOn(m_pInterpretator, true, false);
|
||||
oLineCapPath.DrawOn(m_pInterpretator, false, true);
|
||||
}
|
||||
else
|
||||
m_pInterpretator->HANDLE_EMFPLUS_DRAWPATH(shOgjectIndex, unPenId, pPath);
|
||||
}
|
||||
|
||||
if (NULL != pEmfPlusPen->pBrush)
|
||||
m_pDC->RemoveBrush(pEmfPlusPen->pBrush);
|
||||
@ -2806,7 +2826,7 @@ namespace MetaFile
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_FILLREGION(unsigned short unShFlags)
|
||||
{
|
||||
short shOgjectIndex = ExpressValue(unShFlags, 0, 7);
|
||||
// short shOgjectIndex = ExpressValue(unShFlags, 0, 7);
|
||||
unsigned int unBrushId;
|
||||
|
||||
m_oStream >> unBrushId;
|
||||
@ -2965,34 +2985,34 @@ namespace MetaFile
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETANTIALIASMODE(unsigned short unShFlags)
|
||||
{
|
||||
short shSmoothingMode = ExpressValue(unShFlags, 1, 7);
|
||||
// short shSmoothingMode = ExpressValue(unShFlags, 1, 7);
|
||||
|
||||
//TODO: реализовать
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETCOMPOSITINGMODE(unsigned short unShFlags)
|
||||
{
|
||||
short shCompositingMode = ExpressValue(unShFlags, 0, 7);
|
||||
// short shCompositingMode = ExpressValue(unShFlags, 0, 7);
|
||||
|
||||
//TODO: реализовать
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETCOMPOSITINGQUALITY(unsigned short unShFlags)
|
||||
{
|
||||
short shCompositingQuality = ExpressValue(unShFlags, 0, 7);
|
||||
// short shCompositingQuality = ExpressValue(unShFlags, 0, 7);
|
||||
|
||||
//TODO: реализовать
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETINTERPOLATIONMODE(unsigned short unShFlags)
|
||||
{
|
||||
short shInterpolationMode = ExpressValue(unShFlags, 0, 7);
|
||||
// short shInterpolationMode = ExpressValue(unShFlags, 0, 7);
|
||||
//TODO: реализовать
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETPIXELOFFSETMODE(unsigned short unShFlags)
|
||||
{
|
||||
short shPixelOffsetMode = ExpressValue(unShFlags, 0, 7);
|
||||
// short shPixelOffsetMode = ExpressValue(unShFlags, 0, 7);
|
||||
|
||||
//TODO: реализовать
|
||||
}
|
||||
@ -3009,20 +3029,20 @@ namespace MetaFile
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETTEXTCONTRAST(unsigned short unShFlags)
|
||||
{
|
||||
short shTextContrast = ExpressValue(unShFlags, 0, 11);
|
||||
// short shTextContrast = ExpressValue(unShFlags, 0, 11);
|
||||
|
||||
//TODO: реализовать
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMRPLUS_SETTEXTRENDERINGHINT(unsigned short unShFlags)
|
||||
{
|
||||
short shTextRenderingHint = ExpressValue(unShFlags, 0, 7);
|
||||
// short shTextRenderingHint = ExpressValue(unShFlags, 0, 7);
|
||||
//TODO: реализовать
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_BEGINCONTAINER(unsigned short unShFlags)
|
||||
{
|
||||
short shPageUnit = ExpressValue(unShFlags, 8, 15);
|
||||
// short shPageUnit = ExpressValue(unShFlags, 8, 15);
|
||||
TEmfPlusRectF oDestRect, oSrcRect;
|
||||
unsigned int unStackIndex;
|
||||
|
||||
@ -3126,7 +3146,6 @@ namespace MetaFile
|
||||
m_oStream >> oMatrix;
|
||||
|
||||
m_pDC->MultiplyTransform(oMatrix, (unShFlags & 0x2000) ? MWT_RIGHTMULTIPLY : MWT_LEFTMULTIPLY);
|
||||
UpdateOutputDC();
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_RESETWORLDTRANSFORM()
|
||||
@ -3134,7 +3153,6 @@ namespace MetaFile
|
||||
m_bBanEmfProcessing = true;
|
||||
|
||||
m_pDC->ResetTransform();
|
||||
UpdateOutputDC();
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_ROTATEWORLDTRANSFORM(unsigned short unShFlags)
|
||||
@ -3153,7 +3171,6 @@ namespace MetaFile
|
||||
TEmfPlusXForm oMatrix(dCosTheta, dSinTheta, -dSinTheta, dCosTheta, 0, 0);
|
||||
|
||||
m_pDC->MultiplyTransform(oMatrix, (unShFlags & 0x2000) ? MWT_RIGHTMULTIPLY : MWT_LEFTMULTIPLY);
|
||||
UpdateOutputDC();
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SCALEWORLDTRANSFORM(unsigned short unShFlags)
|
||||
@ -3168,7 +3185,6 @@ namespace MetaFile
|
||||
TEmfPlusXForm oMatrix(dSx, 0, 0, dSy, 0, 0);
|
||||
|
||||
m_pDC->MultiplyTransform(oMatrix, (unShFlags & 0x2000) ? MWT_RIGHTMULTIPLY : MWT_LEFTMULTIPLY);
|
||||
UpdateOutputDC();
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETPAGETRANSFORM(unsigned short unShFlags)
|
||||
@ -3185,8 +3201,6 @@ namespace MetaFile
|
||||
|
||||
TEmfPlusXForm oUnitKoefMatrix(m_dPageTransformX, 0, 0, m_dPageTransformY, 0, 0);
|
||||
m_pDC->MultiplyTransform(oUnitKoefMatrix, MWT_LEFTMULTIPLY);
|
||||
|
||||
UpdateOutputDC();
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_SETWORLDTRANSFORM()
|
||||
@ -3196,11 +3210,8 @@ namespace MetaFile
|
||||
m_oStream >> oMatrix;
|
||||
|
||||
m_pDC->MultiplyTransform(oMatrix, MWT_SET);
|
||||
|
||||
TEmfPlusXForm oUnitKoefMatrix(m_dPageTransformX, 0, 0, m_dPageTransformY, 0, 0);
|
||||
m_pDC->MultiplyTransform(oUnitKoefMatrix, MWT_LEFTMULTIPLY);
|
||||
|
||||
UpdateOutputDC();
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_TRANSLATEWORLDTRANSFORM(unsigned short unShFlags)
|
||||
@ -3213,7 +3224,6 @@ namespace MetaFile
|
||||
TEmfPlusXForm oMatrix(1, 0, 0, 1, dX, dY);
|
||||
|
||||
m_pDC->MultiplyTransform(oMatrix, (unShFlags & 0x2000) ? MWT_RIGHTMULTIPLY : MWT_LEFTMULTIPLY);
|
||||
UpdateOutputDC();
|
||||
}
|
||||
|
||||
void CEmfPlusParser::Read_EMFPLUS_ENDOFFILE()
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
#ifndef CEMFPLUSPARSER_H
|
||||
#define CEMFPLUSPARSER_H
|
||||
|
||||
//#include "../../Common/MetaFileUtils.h"
|
||||
//#include "../../Common/MetaFile.h"
|
||||
#include "../EmfPlusObjects.h"
|
||||
#include "CEmfParserBase.h"
|
||||
#include "../EmfPlusTypes.h"
|
||||
@ -27,7 +25,6 @@ namespace MetaFile
|
||||
|
||||
void SetStream(BYTE *pBytes, unsigned int unSize);
|
||||
bool GetBanEMFProcesses();
|
||||
|
||||
private:
|
||||
void RegisterObject(CEmfPlusObject* pObject, unsigned int unIndex);
|
||||
|
||||
|
||||
@ -728,7 +728,7 @@ namespace MetaFile
|
||||
m_oFinalTransform.Multiply(oWindowXForm, MWT_RIGHTMULTIPLY);
|
||||
|
||||
m_oFinalTransform2.Init();
|
||||
m_oFinalTransform2.Multiply(m_oTransform, MWT_RIGHTMULTIPLY);
|
||||
// m_oFinalTransform2.Multiply(m_oTransform, MWT_RIGHTMULTIPLY);
|
||||
m_oFinalTransform2.Multiply(oViewportXForm, MWT_RIGHTMULTIPLY);
|
||||
m_oFinalTransform2.Multiply(oWindowXForm, MWT_RIGHTMULTIPLY);
|
||||
}
|
||||
|
||||
@ -79,6 +79,26 @@ namespace MetaFile
|
||||
height = oRectF.dHeight;
|
||||
}
|
||||
|
||||
void CEmfPlusBrush::GetGradientColors(std::vector<long>& arColors, std::vector<double>& arPositions) const
|
||||
{
|
||||
if (arGradientColors.empty())
|
||||
{
|
||||
arColors = {(long)(GetColor() + (GetAlpha() << 24)), (long)(GetColor2() + (GetAlpha2() << 24))};
|
||||
arPositions = {0., 1.};
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
arColors.resize(arGradientColors.size());
|
||||
arPositions.resize(arGradientColors.size());
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < arGradientColors.size(); ++unIndex)
|
||||
{
|
||||
arColors[unIndex] = METAFILE_RGBA(arGradientColors[unIndex].first.chRed, arGradientColors[unIndex].first.chGreen, arGradientColors[unIndex].first.chBlue, arGradientColors[unIndex].first.chAlpha);
|
||||
arPositions[unIndex] = arGradientColors[unIndex].second;
|
||||
}
|
||||
}
|
||||
|
||||
CEmfPlusPen::CEmfPlusPen()
|
||||
: unStyle(PS_SOLID | PS_GEOMETRIC | PS_STARTCAP_FLAT | PS_ENDCAP_FLAT | PS_JOIN_MITER), dWidth(1), oColor(0, 0, 0),
|
||||
pBrush(NULL), dMiterLimit(0), dDashOffset(0),
|
||||
@ -90,7 +110,7 @@ namespace MetaFile
|
||||
RELEASEOBJECT(pBrush)
|
||||
RELEASEARRAYOBJECTS(pDataDash)
|
||||
RELEASEOBJECT(pLineStartCapData)
|
||||
RELEASEOBJECT(pLineEndCapData)
|
||||
RELEASEOBJECT(pLineEndCapData)
|
||||
}
|
||||
|
||||
EEmfObjectType CEmfPlusPen::GetType() const
|
||||
@ -148,6 +168,16 @@ namespace MetaFile
|
||||
unSize = unSizeDash;
|
||||
}
|
||||
|
||||
const ILineCap* CEmfPlusPen::GetStartLineCap() const
|
||||
{
|
||||
return pLineStartCapData;
|
||||
}
|
||||
|
||||
const ILineCap* CEmfPlusPen::GetEndLineCap() const
|
||||
{
|
||||
return pLineEndCapData;
|
||||
}
|
||||
|
||||
CEmfPlusFont::CEmfPlusFont()
|
||||
: m_dEmSize(18), m_unSizeUnit(0), m_bBold(false),
|
||||
m_bItalic(false), m_bUnderline(false), m_bStrikeout(false),
|
||||
|
||||
@ -189,6 +189,7 @@ namespace MetaFile
|
||||
void GetCenterPoint(double& dX, double& dY) const override;
|
||||
void GetBounds(double& left, double& top, double& width, double& height) const override;
|
||||
|
||||
void GetGradientColors(std::vector<long>& arColors, std::vector<double>& arPositions) const override;
|
||||
public:
|
||||
TEmfPlusARGB oColor;
|
||||
TEmfPlusARGB oColorBack;
|
||||
@ -198,6 +199,8 @@ namespace MetaFile
|
||||
TEmfPlusPointF oCenterPoint;
|
||||
unsigned int unAngle;
|
||||
std::wstring wsDibPatternPath;
|
||||
|
||||
std::vector<std::pair<TEmfPlusARGB, double>> arGradientColors;
|
||||
};
|
||||
|
||||
class CEmfPlusPen: public CEmfPlusObject, public IPen
|
||||
@ -209,14 +212,15 @@ namespace MetaFile
|
||||
virtual EEmfPlusObjectType GetObjectType() const override;
|
||||
|
||||
// IPen
|
||||
int GetColor() const override;
|
||||
unsigned int GetStyle() const override;
|
||||
double GetWidth() const override;
|
||||
unsigned int GetAlpha() const override;
|
||||
double GetMiterLimit() const override;
|
||||
double GetDashOffset() const override;
|
||||
void GetDashData(double*& arDatas, unsigned int& unSize) const override;
|
||||
|
||||
int GetColor() const override;
|
||||
unsigned int GetStyle() const override;
|
||||
double GetWidth() const override;
|
||||
unsigned int GetAlpha() const override;
|
||||
double GetMiterLimit() const override;
|
||||
double GetDashOffset() const override;
|
||||
void GetDashData(double*& arDatas, unsigned int& unSize) const override;
|
||||
const ILineCap* GetStartLineCap() const override;
|
||||
const ILineCap* GetEndLineCap() const override;
|
||||
public:
|
||||
unsigned int unStyle;
|
||||
double dWidth;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define EMFPLUSTYPES_H
|
||||
|
||||
#include "EmfTypes.h"
|
||||
#include "../Common/MetaFileObjects.h"
|
||||
|
||||
namespace MetaFile
|
||||
{
|
||||
@ -105,6 +106,16 @@ namespace MetaFile
|
||||
chRed = oARGB.chRed;
|
||||
chAlpha = oARGB.chAlpha;
|
||||
}
|
||||
|
||||
TEmfPlusARGB& operator=(const TEmfPlusARGB& oARGB)
|
||||
{
|
||||
chBlue = oARGB.chBlue;
|
||||
chGreen = oARGB.chGreen;
|
||||
chRed = oARGB.chRed;
|
||||
chAlpha = oARGB.chAlpha;
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct TGUID
|
||||
@ -243,7 +254,7 @@ namespace MetaFile
|
||||
CustomLineCapDataLinePath = 0x00000002
|
||||
} CustomLineCapDataFlags;
|
||||
|
||||
class CLineCapData
|
||||
class CLineCapData : public ILineCap
|
||||
{
|
||||
public:
|
||||
CLineCapData() {};
|
||||
|
||||
@ -448,6 +448,37 @@ namespace MetaFile
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CMetaFile::LoadFromString(const std::wstring& data)
|
||||
{
|
||||
#ifdef METAFILE_SUPPORT_SVG
|
||||
RELEASEINTERFACE(m_pFontManager);
|
||||
|
||||
if (m_pAppFonts)
|
||||
{
|
||||
m_pFontManager = m_pAppFonts->GenerateFontManager();
|
||||
NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create();
|
||||
pMeasurerCache->SetStreams(m_pAppFonts->GetStreams());
|
||||
m_pFontManager->SetOwnerCache(pMeasurerCache);
|
||||
}
|
||||
|
||||
m_oSvgFile.SetFontManager(m_pFontManager);
|
||||
|
||||
if (m_oSvgFile.ReadFromWString(data) == true)
|
||||
{
|
||||
m_lType = c_lMetaSvg;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void CMetaFile::SetTempDirectory(const std::wstring& dir)
|
||||
{
|
||||
#ifdef METAFILE_SUPPORT_SVG
|
||||
m_oSvgFile.SetWorkingDirectory(dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CMetaFile::DrawOnRenderer(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight)
|
||||
{
|
||||
if (NULL == pRenderer)
|
||||
@ -580,6 +611,9 @@ namespace MetaFile
|
||||
|
||||
void CMetaFile::ConvertToRaster(const wchar_t* wsOutFilePath, unsigned int unFileType, int nWidth, int nHeight)
|
||||
{
|
||||
if (nWidth == 0 || nHeight == 0)
|
||||
return;
|
||||
|
||||
NSGraphics::IGraphicsRenderer* pGrRenderer = NSGraphics::Create();
|
||||
|
||||
NSFonts::IFontManager* pFontManager = m_pAppFonts->GenerateFontManager();
|
||||
|
||||
@ -64,6 +64,7 @@ namespace MetaFile
|
||||
|
||||
bool LoadFromFile(const wchar_t* wsFilePath);
|
||||
bool LoadFromBuffer(BYTE* pBuffer, unsigned int unSize);
|
||||
bool LoadFromString(const std::wstring& data);
|
||||
bool DrawOnRenderer(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight);
|
||||
void Close();
|
||||
void GetBounds(double* pdX, double* pdY, double* pdW, double* pdH);
|
||||
@ -75,6 +76,8 @@ namespace MetaFile
|
||||
//конвертация в Svg
|
||||
std::wstring ConvertToSvg(unsigned int unWidth = 0, unsigned int unHeight = 0);
|
||||
|
||||
void SetTempDirectory(const std::wstring& dir);
|
||||
|
||||
//Для тестов
|
||||
#ifdef METAFILE_SUPPORT_WMF_EMF
|
||||
void ConvertToXml(const wchar_t *wsFilePath);
|
||||
|
||||
@ -266,6 +266,7 @@ void CSvmFile::Read_META_LINE()
|
||||
{
|
||||
case LINE_SOLID: last_pen->PenStyle = PS_SOLID ; break;
|
||||
case LINE_DASH: last_pen->PenStyle = PS_DASH ; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -323,6 +324,7 @@ void CSvmFile::Read_META_POLYLINE()
|
||||
{
|
||||
case LINE_SOLID: last_pen->PenStyle = PS_SOLID ; break;
|
||||
case LINE_DASH: last_pen->PenStyle = PS_DASH ; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (last_pen->Width < 1)
|
||||
|
||||
@ -358,6 +358,12 @@ void CSvmBrush::GetBounds(double& left, double& top, double& width, double& heig
|
||||
void CSvmBrush::GetDibPattern(unsigned char **pBuffer, unsigned int &unWidth, unsigned int &unHeight) const
|
||||
{}
|
||||
|
||||
void CSvmBrush::GetGradientColors(std::vector<long>& arColors, std::vector<double>& arPositions) const
|
||||
{
|
||||
arColors = {(long)(GetColor() + (GetAlpha() << 24)), (long)(GetColor2() + (GetAlpha2() << 24))};
|
||||
arPositions = {0., 1.};
|
||||
}
|
||||
|
||||
int CSvmPen::GetColor() const
|
||||
{
|
||||
return METAFILE_RGBA(Color.r, Color.g, Color.b, 0);
|
||||
|
||||
@ -300,6 +300,7 @@ public:
|
||||
void GetBounds(double& left, double& top, double& width, double& height) const override;
|
||||
void GetDibPattern(unsigned char** pBuffer, unsigned int &unWidth, unsigned int &unHeight) const override;
|
||||
|
||||
void GetGradientColors(std::vector<long>& arColors, std::vector<double>& arPositions) const override;
|
||||
public:
|
||||
unsigned short BrushStyleEx; //angle, or ....
|
||||
unsigned short BrushStyle;
|
||||
@ -448,6 +449,14 @@ public:
|
||||
arDatas = NULL;
|
||||
unSize = 0;
|
||||
}
|
||||
const ILineCap* GetStartLineCap() const override
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
const ILineCap* GetEndLineCap() const override
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
public:
|
||||
unsigned short PenStyle;
|
||||
int Width;
|
||||
|
||||
@ -75,7 +75,8 @@ namespace MetaFile
|
||||
};
|
||||
|
||||
CInterpretatorSvgBase::CInterpretatorSvgBase(IMetaFileBase *pParser, double dWidth, double dHeight)
|
||||
: m_oSizeWindow(dWidth, dHeight), m_unNumberDefs(0), m_pParser(pParser), m_pXmlWriter(new XmlUtils::CXmlWriter()), m_bExternXmlWriter(false), m_bUpdatedClip(true)
|
||||
: m_oSizeWindow(dWidth, dHeight), m_unNumberDefs(0), m_pParser(pParser), m_pXmlWriter(new XmlUtils::CXmlWriter()),
|
||||
m_bExternXmlWriter(false), m_bUpdatedClip(true), m_eShapeRendering(EShapeRendering::Auto)
|
||||
{}
|
||||
|
||||
CInterpretatorSvgBase::~CInterpretatorSvgBase()
|
||||
@ -127,6 +128,11 @@ namespace MetaFile
|
||||
return m_pXmlWriter;
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::SetShapeRendering(EShapeRendering eShapeRenderingType)
|
||||
{
|
||||
m_eShapeRendering = eShapeRenderingType;
|
||||
}
|
||||
|
||||
std::wstring CInterpretatorSvgBase::GetFile()
|
||||
{
|
||||
return m_pXmlWriter->GetXmlString();
|
||||
@ -211,16 +217,6 @@ namespace MetaFile
|
||||
m_pXmlWriter->WriteNodeEnd(wsNodeName, false, false);
|
||||
}
|
||||
|
||||
static void EraseWords(std::wstring& wsString, const std::vector<std::wstring>& arWords)
|
||||
{
|
||||
size_t unBegin = 0;
|
||||
for (const std::wstring& wsWord : arWords)
|
||||
{
|
||||
while (std::wstring::npos != (unBegin = wsString.find(wsWord)))
|
||||
wsString.erase(unBegin, wsWord.length());
|
||||
}
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::WriteText(const std::wstring &wsText, const TPointD &oCoord, const TRectL &oBounds, const TPointD &oScale, const std::vector<double>& arDx)
|
||||
{
|
||||
if (NULL == m_pParser || NULL == m_pParser->GetFont())
|
||||
@ -256,30 +252,31 @@ namespace MetaFile
|
||||
WriteNodeBegin(L"g", {});
|
||||
bWriteG = true;
|
||||
|
||||
WriteNode(L"rect", {{L"x", ConvertToWString(oBounds.Left)},
|
||||
{L"y", ConvertToWString(oBounds.Top)},
|
||||
{L"width", ConvertToWString(oBounds.Right - oBounds.Left)},
|
||||
{L"height", ConvertToWString(oBounds.Bottom - oBounds.Top)},
|
||||
{L"fill", wsFillRect},
|
||||
{L"stroke", L"none"}});
|
||||
NodeAttributes arRectAttributes{{L"x", ConvertToWString(oBounds.Left)},
|
||||
{L"y", ConvertToWString(oBounds.Top)},
|
||||
{L"width", ConvertToWString(oBounds.Right - oBounds.Left)},
|
||||
{L"height", ConvertToWString(oBounds.Bottom - oBounds.Top)},
|
||||
{L"fill", wsFillRect},
|
||||
{L"stroke", L"none"}};
|
||||
|
||||
AddShapeRendering(arRectAttributes);
|
||||
|
||||
WriteNode(L"rect", arNodeAttributes);
|
||||
}
|
||||
|
||||
int nColor = m_pParser->GetTextColor();
|
||||
|
||||
if (0 != nColor)
|
||||
arNodeAttributes.push_back({L"fill", CalculateColor(nColor, 255)});
|
||||
arNodeAttributes.Add(L"fill", CalculateColor(nColor, 255));
|
||||
|
||||
const IFont *pFont = m_pParser->GetFont();
|
||||
|
||||
if (NULL == pFont)
|
||||
return;
|
||||
|
||||
double dFontHeight = std::fabs(pFont->GetHeight());
|
||||
|
||||
if (dFontHeight < 0.01)
|
||||
dFontHeight = 18;
|
||||
dFontHeight = DEFAULT_FONT_SIZE;
|
||||
|
||||
arNodeAttributes.push_back({L"font-size", ConvertToWString(dFontHeight)});
|
||||
arNodeAttributes.Add(L"font-size", dFontHeight);
|
||||
|
||||
NSStringUtils::CStringBuilder oFontName;
|
||||
oFontName.WriteEncodeXmlString(pFont->GetFaceName());
|
||||
@ -302,21 +299,21 @@ namespace MetaFile
|
||||
oFontName.WriteEncodeXmlString(L"\'");
|
||||
}
|
||||
#endif
|
||||
arNodeAttributes.push_back({L"font-family", oFontName.GetData()});
|
||||
arNodeAttributes.Add(L"font-family", oFontName.GetData());
|
||||
}
|
||||
|
||||
if (pFont->GetWeight() > 550)
|
||||
arNodeAttributes.push_back({L"font-weight", L"bold"});
|
||||
arNodeAttributes.Add(L"font-weight", L"bold");
|
||||
|
||||
if (pFont->IsItalic())
|
||||
arNodeAttributes.push_back({L"font-style", L"italic"});
|
||||
arNodeAttributes.Add(L"font-style", L"italic");
|
||||
|
||||
if (pFont->IsUnderline() && pFont->IsStrikeOut())
|
||||
arNodeAttributes.push_back({L"text-decoration", L"underline line-through"});
|
||||
arNodeAttributes.Add(L"text-decoration", L"underline line-through");
|
||||
else if (pFont->IsUnderline())
|
||||
arNodeAttributes.push_back({L"text-decoration", L"underline"});
|
||||
arNodeAttributes.Add(L"text-decoration", L"underline");
|
||||
else if (pFont->IsStrikeOut())
|
||||
arNodeAttributes.push_back({L"text-decoration", L"line-through"});
|
||||
arNodeAttributes.Add(L"text-decoration", L"line-through");
|
||||
|
||||
//TODO:: разобраться для корректной работы
|
||||
// double dFontCharSpace = pFont->GetCharSet();
|
||||
@ -338,14 +335,14 @@ namespace MetaFile
|
||||
}
|
||||
else if (ulTextAlign & TA_BOTTOM || ulVTextAlign == VTA_BOTTOM)
|
||||
{
|
||||
arNodeAttributes.push_back({L"dominant-baseline", L"auto"});
|
||||
arNodeAttributes.Add(L"dominant-baseline", L"auto");
|
||||
|
||||
if (ulVTextAlign != VTA_BOTTOM)
|
||||
ulTextAlign -= TA_BOTTOM;
|
||||
}
|
||||
else if (ulVTextAlign == VTA_CENTER)
|
||||
{
|
||||
arNodeAttributes.push_back({L"dominant-baseline", L"middle"});
|
||||
arNodeAttributes.Add(L"dominant-baseline", L"middle");
|
||||
}
|
||||
else // if (ulTextAlign & TA_TOP)
|
||||
{
|
||||
@ -355,14 +352,14 @@ namespace MetaFile
|
||||
if (ulTextAlign == TA_RIGHT)
|
||||
{
|
||||
if (arDx.empty())
|
||||
arNodeAttributes.push_back({L"text-anchor", L"end"});
|
||||
arNodeAttributes.Add(L"text-anchor", L"end");
|
||||
else
|
||||
dXCoord -= std::accumulate(arDx.begin(), arDx.end(), 0.0);
|
||||
}
|
||||
else if (ulTextAlign == TA_CENTER)
|
||||
{
|
||||
if (arDx.empty())
|
||||
arNodeAttributes.push_back({L"text-anchor", L"middle"});
|
||||
arNodeAttributes.Add(L"text-anchor", L"middle");
|
||||
else
|
||||
dXCoord -= std::accumulate(arDx.begin(), arDx.end(), 0.0) / 2;
|
||||
}
|
||||
@ -394,7 +391,7 @@ namespace MetaFile
|
||||
if (oScale.Y < -0.00001)
|
||||
dXCoord -= dFontHeight * dSin;
|
||||
|
||||
arNodeAttributes.push_back({L"transform", L"rotate(" + ConvertToWString(dEscapement) + L' ' + ConvertToWString(dXCoord) + L' ' + ConvertToWString(dYCoord) + L')'});
|
||||
arNodeAttributes.Add(L"transform", L"rotate(" + ConvertToWString(dEscapement) + L' ' + ConvertToWString(dXCoord) + L' ' + ConvertToWString(dYCoord) + L')');
|
||||
|
||||
if (oScale.Y > 0.00001)
|
||||
dXCoord -= dFontHeight * dSin;
|
||||
@ -402,7 +399,7 @@ namespace MetaFile
|
||||
|
||||
AddTransform(arNodeAttributes, &oTransform);
|
||||
|
||||
arNodeAttributes.push_back({L"xml:space", L"preserve"});
|
||||
arNodeAttributes.Add(L"xml:space", L"preserve");
|
||||
|
||||
size_t unPosLineBreak = wsNormalizedText.find(L"\n");
|
||||
|
||||
@ -424,8 +421,8 @@ namespace MetaFile
|
||||
|
||||
if (std::wstring::npos == unPosLineBreak)
|
||||
{
|
||||
arNodeAttributes.push_back({L"x", wsXCoord});
|
||||
arNodeAttributes.push_back({L"y", ConvertToWString(dYCoord)});
|
||||
arNodeAttributes.Add(L"x", wsXCoord);
|
||||
arNodeAttributes.Add(L"y", dYCoord);
|
||||
|
||||
WriteNode(L"text", arNodeAttributes, wsNormalizedText);
|
||||
}
|
||||
@ -439,7 +436,7 @@ namespace MetaFile
|
||||
do
|
||||
{
|
||||
WriteNode(L"tspan", {{L"x", wsXCoord},
|
||||
{L"y", ConvertToWString(dYNewCoord)}}, wsNormalizedText.substr(unStart, unPosLineBreak - unStart));
|
||||
{L"y", ConvertToWString(dYNewCoord)}}, wsNormalizedText.substr(unStart, unPosLineBreak - unStart));
|
||||
|
||||
dYNewCoord += dFontHeight * 1.6;
|
||||
unStart = wsNormalizedText.find_first_not_of(L"\n", unPosLineBreak);
|
||||
@ -499,6 +496,7 @@ namespace MetaFile
|
||||
{L"height", ConvertToWString(dH)},
|
||||
{L"fill", CalculateColor(pBuffer[2], pBuffer[1], pBuffer[0], 255)}};
|
||||
|
||||
AddShapeRendering(arAttributes);
|
||||
AddTransform(arAttributes, &oTransform);
|
||||
AddClip();
|
||||
|
||||
@ -562,16 +560,18 @@ namespace MetaFile
|
||||
|
||||
void CInterpretatorSvgBase::IntersectClip(const TRectD &oClip)
|
||||
{
|
||||
double dLeft = oClip.Left;
|
||||
double dTop = oClip.Top;
|
||||
double dRight = oClip.Right;
|
||||
double dBottom = oClip.Bottom;
|
||||
TRectD oUpdatedClip{oClip};
|
||||
|
||||
m_pParser->GetTransform().Apply(dLeft, dTop);
|
||||
m_pParser->GetTransform().Apply(dRight, dBottom);
|
||||
NormalizeRect(oUpdatedClip);
|
||||
|
||||
m_pParser->GetTransform().Apply(oUpdatedClip.Left, oUpdatedClip.Top);
|
||||
m_pParser->GetTransform().Apply(oUpdatedClip.Right, oUpdatedClip.Bottom);
|
||||
|
||||
const std::wstring wsId = L"INTERSECTCLIP_" + ConvertToWString(++m_unNumberDefs, 0);
|
||||
const std::wstring wsValue = L"<rect x=\"" + ConvertToWString(dLeft, 0) + L"\" y=\"" + ConvertToWString(dTop, 0) + L"\" width=\"" + ConvertToWString(dRight - dLeft, 0) + L"\" height=\"" + ConvertToWString(dBottom - dTop, 0) + L"\"/>";
|
||||
const std::wstring wsValue = L"<rect x=\"" + ConvertToWString(oUpdatedClip.Left, 0) +
|
||||
L"\" y=\"" + ConvertToWString(oUpdatedClip.Top, 0) +
|
||||
L"\" width=\"" + ConvertToWString(oUpdatedClip.Right - oUpdatedClip.Left, 0) +
|
||||
L"\" height=\"" + ConvertToWString(oUpdatedClip.Bottom - oUpdatedClip.Top, 0) + L"\"/>";
|
||||
|
||||
m_oClip.AddClipValue(wsId, wsValue);
|
||||
}
|
||||
@ -579,28 +579,24 @@ namespace MetaFile
|
||||
void CInterpretatorSvgBase::ExcludeClip(const TRectD &oClip, const TRectD &oBB)
|
||||
{
|
||||
const TXForm &oTransform{m_pParser->GetTransform()};
|
||||
|
||||
double dClipLeft = oClip.Left;
|
||||
double dClipTop = oClip.Top;
|
||||
double dClipRight = oClip.Right;
|
||||
double dClipBottom = oClip.Bottom;
|
||||
|
||||
oTransform.Apply(dClipLeft, dClipTop);
|
||||
oTransform.Apply(dClipRight, dClipBottom);
|
||||
TRectD oUpdatedClip{oClip};
|
||||
NormalizeRect(oUpdatedClip);
|
||||
|
||||
double dBBLeft = oBB.Left;
|
||||
double dBBTop = oBB.Top;
|
||||
double dBBRight = oBB.Right;
|
||||
double dBBBottom = oBB.Bottom;
|
||||
oTransform.Apply(oUpdatedClip.Left, oUpdatedClip.Top);
|
||||
oTransform.Apply(oUpdatedClip.Right, oUpdatedClip.Bottom);
|
||||
|
||||
oTransform.Apply(dBBLeft, dBBTop);
|
||||
oTransform.Apply(dBBRight, dBBBottom);
|
||||
TRectD oBBRect{oBB};
|
||||
NormalizeRect(oBBRect);
|
||||
|
||||
oTransform.Apply(oBBRect.Left, oBBRect.Top);
|
||||
oTransform.Apply(oBBRect.Right, oBBRect.Bottom);
|
||||
|
||||
const std::wstring wsId = L"EXCLUDECLIP_" + ConvertToWString(++m_unNumberDefs, 0);
|
||||
const std::wstring wsValue = L"<path d=\"M" + ConvertToWString(dBBLeft) + L' ' + ConvertToWString(dBBTop) + L", L" + ConvertToWString(dBBRight) + L' ' + ConvertToWString(dBBTop) + L", " +
|
||||
ConvertToWString(dBBRight) + L' ' + ConvertToWString(dBBBottom) + L", " + ConvertToWString(dBBLeft ) + L' ' + ConvertToWString(dBBBottom) + L", M" +
|
||||
ConvertToWString(dClipLeft) + L' ' + ConvertToWString(dClipTop) + L", L" + ConvertToWString(dClipRight) + L' ' + ConvertToWString(dClipTop) + L", " +
|
||||
ConvertToWString(dClipRight) + L' ' + ConvertToWString(dClipBottom) + L", " + ConvertToWString(dClipLeft) + L' ' + ConvertToWString(dClipLeft ) + L"\" clip-rule=\"evenodd\"/>";
|
||||
const std::wstring wsValue = L"<path d=\"M" + ConvertToWString(oBBRect.Left) + L' ' + ConvertToWString(oBBRect.Top) + L", L" + ConvertToWString(oBBRect.Right) + L' ' + ConvertToWString(oBBRect.Top) + L", " +
|
||||
ConvertToWString(oBBRect.Right) + L' ' + ConvertToWString(oBBRect.Bottom) + L", " + ConvertToWString(oBBRect.Left) + L' ' + ConvertToWString(oBBRect.Bottom) + L", Z M" +
|
||||
ConvertToWString(oUpdatedClip.Left) + L' ' + ConvertToWString(oUpdatedClip.Top) + L", L" + ConvertToWString(oUpdatedClip.Right) + L' ' + ConvertToWString(oUpdatedClip.Top) + L", " +
|
||||
ConvertToWString(oUpdatedClip.Right) + L' ' + ConvertToWString(oUpdatedClip.Bottom) + L", " + ConvertToWString(oUpdatedClip.Left) + L' ' + ConvertToWString(oUpdatedClip.Bottom) + L" Z\" clip-rule=\"evenodd\"/>";
|
||||
|
||||
m_oClip.AddClipValue(wsId, wsValue);
|
||||
}
|
||||
@ -630,10 +626,10 @@ namespace MetaFile
|
||||
|
||||
switch (m_pParser->GetRop2Mode())
|
||||
{
|
||||
case R2_BLACK: arAttributes.push_back({L"stroke", L"rgb(0, 0, 0)"}); break;
|
||||
case R2_BLACK: arAttributes.Add(L"stroke", L"rgb(0, 0, 0)"); break;
|
||||
case R2_NOP: return;
|
||||
case R2_WHITE: arAttributes.push_back({L"stroke", L"rgb(255, 255, 255)"}); break;
|
||||
default: arAttributes.push_back({L"stroke", CalculateColor(pPen->GetColor(), pPen->GetAlpha())}); break;
|
||||
case R2_WHITE: arAttributes.Add(L"stroke", L"rgb(255, 255, 255)"); break;
|
||||
default: arAttributes.Add(L"stroke", CalculateColor(pPen->GetColor(), pPen->GetAlpha())); break;
|
||||
}
|
||||
|
||||
unsigned int unMetaPenStyle = pPen->GetStyle();
|
||||
@ -668,19 +664,16 @@ namespace MetaFile
|
||||
|
||||
double dStrokeWidth = std::fabs(m_pParser->GetPen()->GetWidth());
|
||||
|
||||
if (Equals(0, dStrokeWidth) || (Equals(1, dStrokeWidth) && PS_COSMETIC == (m_pParser->GetPen()->GetStyle() & PS_TYPE_MASK)))
|
||||
if (Equals(0., dStrokeWidth))
|
||||
{
|
||||
dStrokeWidth = 1;
|
||||
arAttributes.push_back({L"vector-effect", L"non-scaling-stroke"});
|
||||
|
||||
wsLineCap = L"butt";
|
||||
wsLineJoin = L"miter";
|
||||
dStrokeWidth = 1.;
|
||||
arAttributes.Add(L"vector-effect", L"non-scaling-stroke");
|
||||
}
|
||||
|
||||
arAttributes.push_back({L"stroke-width", ConvertToWString(dStrokeWidth)});
|
||||
arAttributes.push_back({L"stroke-miterlimit", ConvertToWString(pPen->GetMiterLimit())});
|
||||
arAttributes.push_back({L"stroke-linecap", wsLineCap});
|
||||
arAttributes.push_back({L"stroke-linejoin", wsLineJoin});
|
||||
arAttributes.Add(L"stroke-width", dStrokeWidth);
|
||||
arAttributes.Add(L"stroke-miterlimit", pPen->GetMiterLimit());
|
||||
arAttributes.Add(L"stroke-linecap", wsLineCap);
|
||||
arAttributes.Add(L"stroke-linejoin", wsLineJoin);
|
||||
|
||||
double* arDatas = NULL;
|
||||
unsigned int unDataSize = 0;
|
||||
@ -700,23 +693,23 @@ namespace MetaFile
|
||||
}
|
||||
wsDashArray.pop_back();
|
||||
|
||||
arAttributes.push_back({L"stroke-dasharray", wsDashArray});
|
||||
arAttributes.Add(L"stroke-dasharray", wsDashArray);
|
||||
}
|
||||
else if (PS_DASH == ulPenStyle)
|
||||
arAttributes.push_back({L"stroke-dasharray", ConvertToWString(dStrokeWidth * 4) + L' ' + ConvertToWString(dStrokeWidth * 2)});
|
||||
arAttributes.Add(L"stroke-dasharray", ConvertToWString(dStrokeWidth * 4) + L' ' + ConvertToWString(dStrokeWidth * 2));
|
||||
else if (PS_DOT == ulPenStyle)
|
||||
arAttributes.push_back({L"stroke-dasharray", ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth)});
|
||||
arAttributes.Add(L"stroke-dasharray", ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth));
|
||||
else if (PS_DASHDOT == ulPenStyle)
|
||||
arAttributes.push_back({L"stroke-dasharray", ConvertToWString(dStrokeWidth * 4) + L' ' + ConvertToWString(dStrokeWidth * 2) + L' ' + ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth * 2)});
|
||||
arAttributes.Add(L"stroke-dasharray", ConvertToWString(dStrokeWidth * 4) + L' ' + ConvertToWString(dStrokeWidth * 2) + L' ' + ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth * 2));
|
||||
else if (PS_DASHDOTDOT == ulPenStyle)
|
||||
arAttributes.push_back({L"stroke-dasharray", ConvertToWString(dStrokeWidth * 4) + L' ' + ConvertToWString(dStrokeWidth * 2) + L' ' + ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth * 2) + L' ' + ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth * 2)});
|
||||
arAttributes.Add(L"stroke-dasharray", ConvertToWString(dStrokeWidth * 4) + L' ' + ConvertToWString(dStrokeWidth * 2) + L' ' + ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth * 2) + L' ' + ConvertToWString(dStrokeWidth) + L' ' + ConvertToWString(dStrokeWidth * 2));
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::AddFill(NodeAttributes &arAttributes, double dWidth, double dHeight)
|
||||
{
|
||||
if (NULL == m_pParser)
|
||||
{
|
||||
arAttributes.push_back({L"fill", L"none"});
|
||||
arAttributes.Add(L"fill", L"none");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -735,7 +728,7 @@ namespace MetaFile
|
||||
|
||||
if (NULL == pBrush || BS_NULL == pBrush->GetStyle())
|
||||
{
|
||||
arAttributes.push_back({L"fill", L"none"});
|
||||
arAttributes.Add(L"fill", L"none");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -743,7 +736,7 @@ namespace MetaFile
|
||||
{
|
||||
case BS_SOLID:
|
||||
{
|
||||
arAttributes.push_back({L"fill", CalculateColor(pBrush->GetColor(), pBrush->GetAlpha())});
|
||||
arAttributes.Add(L"fill", CalculateColor(pBrush->GetColor(), pBrush->GetAlpha()));
|
||||
return;
|
||||
}
|
||||
case BS_HATCHED:
|
||||
@ -752,7 +745,7 @@ namespace MetaFile
|
||||
|
||||
if (!wsStyleId.empty())
|
||||
{
|
||||
arAttributes.push_back({L"fill", L"url(#" + wsStyleId + L")"});
|
||||
arAttributes.Add(L"fill", L"url(#" + wsStyleId + L")");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -764,7 +757,7 @@ namespace MetaFile
|
||||
|
||||
if (!wsStyleId.empty())
|
||||
{
|
||||
arAttributes.push_back({L"fill", L"url(#" + wsStyleId + L")"});
|
||||
arAttributes.Add(L"fill", L"url(#" + wsStyleId + L")");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -774,7 +767,7 @@ namespace MetaFile
|
||||
|
||||
if (!wsStyleId.empty())
|
||||
{
|
||||
arAttributes.push_back({L"fill", L"url(#" + wsStyleId + L")"});
|
||||
arAttributes.Add(L"fill", L"url(#" + wsStyleId + L")");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -788,12 +781,12 @@ namespace MetaFile
|
||||
|
||||
if (!wsStyleId.empty())
|
||||
{
|
||||
arAttributes.push_back({L"fill", L"url(#" + wsStyleId + L")"});
|
||||
arAttributes.Add(L"fill", L"url(#" + wsStyleId + L")");
|
||||
return;
|
||||
}
|
||||
}
|
||||
default:
|
||||
arAttributes.push_back({L"fill", L"none"});
|
||||
arAttributes.Add(L"fill", L"none");
|
||||
}
|
||||
}
|
||||
|
||||
@ -832,7 +825,7 @@ namespace MetaFile
|
||||
|
||||
if (bScale && !bTranslate)
|
||||
{
|
||||
wsValue = L"scale(" + ConvertToWString(oOldTransform.M11) + L',' + ConvertToWString(oOldTransform.M22) + L')';
|
||||
wsValue = L"scale(" + ConvertToWString(oOldTransform.M11) + L',' + ConvertToWString(oOldTransform.M22) + L')';
|
||||
}
|
||||
else if (bTranslate && !bScale)
|
||||
{
|
||||
@ -840,18 +833,18 @@ namespace MetaFile
|
||||
}
|
||||
else if (bScale && bTranslate)
|
||||
{
|
||||
wsValue = L"matrix(" + ConvertToWString(oOldTransform.M11) + L',' +
|
||||
ConvertToWString(oOldTransform.M12) + L',' +
|
||||
ConvertToWString(oOldTransform.M21) + L',' +
|
||||
ConvertToWString(oOldTransform.M22) + L',' +
|
||||
ConvertToWString(oOldTransform.Dx) + L',' + ConvertToWString(oOldTransform.Dy) + L')';
|
||||
wsValue = L"matrix(" + ConvertToWString(oOldTransform.M11) + L',' +
|
||||
ConvertToWString(oOldTransform.M12) + L',' +
|
||||
ConvertToWString(oOldTransform.M21) + L',' +
|
||||
ConvertToWString(oOldTransform.M22) + L',' +
|
||||
ConvertToWString(oOldTransform.Dx) + L',' + ConvertToWString(oOldTransform.Dy) + L')';
|
||||
}
|
||||
else return;
|
||||
|
||||
if (NULL != pFoundTransform)
|
||||
pFoundTransform->second.insert(0, wsValue + L' ');
|
||||
else
|
||||
arAttributes.push_back({L"transform", wsValue});
|
||||
arAttributes.Add(L"transform", wsValue);
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::AddClip()
|
||||
@ -891,7 +884,101 @@ namespace MetaFile
|
||||
|
||||
void CInterpretatorSvgBase::AddNoneFill(NodeAttributes &arAttributes) const
|
||||
{
|
||||
arAttributes.push_back({L"fill", L"none"});
|
||||
arAttributes.Add(L"fill", L"none");
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::AddShapeRendering(NodeAttributes& arAttributes) const
|
||||
{
|
||||
switch (m_eShapeRendering)
|
||||
{
|
||||
case EShapeRendering::OptimizeSpeed:
|
||||
{
|
||||
arAttributes.Add(L"shape-rendering", L"optimizeSpeed");
|
||||
break;
|
||||
}
|
||||
case EShapeRendering::CrispEdges:
|
||||
{
|
||||
arAttributes.Add(L"shape-rendering", L"crispEdges");
|
||||
break;
|
||||
}
|
||||
case EShapeRendering::GeometricPrecision:
|
||||
{
|
||||
arAttributes.Add(L"shape-rendering", L"geometricPrecision");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TPointD GetFirstPoint(const CPathCommandBase* pPathCommand)
|
||||
{
|
||||
if (NULL == pPathCommand)
|
||||
return {0., 0.};
|
||||
|
||||
switch (pPathCommand->GetType())
|
||||
{
|
||||
case EPathCommandType::PATH_COMMAND_MOVETO:
|
||||
{
|
||||
CPathCommandMoveTo* pMoveTo{(CPathCommandMoveTo*)pPathCommand};
|
||||
return {pMoveTo->GetX(), pMoveTo->GetY()};
|
||||
}
|
||||
case EPathCommandType::PATH_COMMAND_LINETO:
|
||||
{
|
||||
CPathCommandLineTo* pLineTo{(CPathCommandLineTo*)pPathCommand};
|
||||
return {pLineTo->GetX(), pLineTo->GetY()};
|
||||
}
|
||||
default:
|
||||
return {0., 0.};
|
||||
}
|
||||
}
|
||||
|
||||
void CInterpretatorSvgBase::AddLineCaps(NodeAttributes& arAttributes, const CPath* pMainPath)
|
||||
{
|
||||
if (NULL == m_pParser || NULL == m_pParser->GetPen() || NULL == pMainPath)
|
||||
return;
|
||||
|
||||
const IPen *pPen = m_pParser->GetPen();
|
||||
const std::vector<CPathCommandBase *> arCommands{pMainPath->GetCommands()};
|
||||
const CLineCapData* pStartLineCap = dynamic_cast<const CLineCapData*>(pPen->GetStartLineCap());
|
||||
|
||||
if (NULL != pStartLineCap)
|
||||
{
|
||||
double dAngle = 0.;
|
||||
|
||||
if (arCommands.size() > 1)
|
||||
{
|
||||
const TPointD oFirstPoint {GetFirstPoint(arCommands[0])};
|
||||
const TPointD oSecondPoint{GetFirstPoint(arCommands[1])};
|
||||
|
||||
dAngle = (atan2((oSecondPoint.Y - oFirstPoint.Y), (oSecondPoint.X - oFirstPoint.X))) / M_PI * 180. + 90.;
|
||||
}
|
||||
|
||||
const std::wstring wsStartLineCapId{CreateLineCap(pStartLineCap, dAngle)};
|
||||
|
||||
if (!wsStartLineCapId.empty())
|
||||
arAttributes.Add(L"marker-start", L"url(#" + wsStartLineCapId + L')');
|
||||
}
|
||||
|
||||
const CLineCapData* pEndLineCap = dynamic_cast<const CLineCapData*>(pPen->GetEndLineCap());
|
||||
|
||||
if (NULL != pEndLineCap)
|
||||
{
|
||||
double dAngle = 0.;
|
||||
|
||||
if (arCommands.size() > 1)
|
||||
{
|
||||
const TPointD oFirstPoint {GetFirstPoint(arCommands[arCommands.size() - 1])};
|
||||
const TPointD oSecondPoint{GetFirstPoint(arCommands[arCommands.size() - 2])};
|
||||
|
||||
dAngle = (atan2((oSecondPoint.Y - oFirstPoint.Y), (oSecondPoint.X - oFirstPoint.X))) / M_PI * 180. + 90.;
|
||||
}
|
||||
|
||||
const std::wstring wsEndLineCapId{CreateLineCap(pEndLineCap, dAngle)};
|
||||
|
||||
if (!wsEndLineCapId.empty())
|
||||
arAttributes.Add(L"marker-end", L"url(#" + wsEndLineCapId + L')');
|
||||
}
|
||||
}
|
||||
|
||||
TPointD CInterpretatorSvgBase::GetCutPos() const
|
||||
@ -902,7 +989,7 @@ namespace MetaFile
|
||||
return TPointD(m_oViewport.dLeft, m_oViewport.dRight);
|
||||
}
|
||||
|
||||
std::wstring CInterpretatorSvgBase::CreatePath(const CPath& oPath, const TXForm *pTransform)
|
||||
std::wstring CInterpretatorSvgBase::CreatePath(const CPath& oPath, const TXForm *pTransform) const
|
||||
{
|
||||
if (NULL == m_pParser || oPath.Empty())
|
||||
return std::wstring();
|
||||
@ -969,9 +1056,9 @@ namespace MetaFile
|
||||
oTransform.Apply(oPoint2.X, oPoint2.Y);
|
||||
oTransform.Apply(oPointE.X, oPointE.Y);
|
||||
|
||||
wsValue += ConvertToWString(oPoint1.X) + L',' + ConvertToWString(oPoint1.Y) + L' ' +
|
||||
ConvertToWString(oPoint2.X) + L',' + ConvertToWString(oPoint2.Y) + L' ' +
|
||||
ConvertToWString(oPointE.X) + L',' + ConvertToWString(oPointE.Y) + L' ';
|
||||
wsValue += ConvertToWString(oPoint1.X) + L',' + ConvertToWString(oPoint1.Y) + L' ' +
|
||||
ConvertToWString(oPoint2.X) + L',' + ConvertToWString(oPoint2.Y) + L' ' +
|
||||
ConvertToWString(oPointE.X) + L',' + ConvertToWString(oPointE.Y) + L' ';
|
||||
|
||||
break;
|
||||
}
|
||||
@ -1187,16 +1274,23 @@ namespace MetaFile
|
||||
|
||||
std::wstring wsStyleId;
|
||||
|
||||
if (BS_LINEARGRADIENT == pBrush->GetStyle() ||
|
||||
BS_RECTGRADIENT == pBrush->GetStyle() ||
|
||||
BS_PATHGRADIENT == pBrush->GetStyle())
|
||||
if (BS_LINEARGRADIENT == pBrush->GetStyle() ||
|
||||
BS_RECTGRADIENT == pBrush->GetStyle() ||
|
||||
BS_PATHGRADIENT == pBrush->GetStyle())
|
||||
{
|
||||
wsStyleId = L"LINEARGRADIENT_" + ConvertToWString(++m_unNumberDefs, 0);
|
||||
|
||||
m_wsDefs += L"<linearGradient id=\"" + wsStyleId + L"\">" +
|
||||
L"<stop offset=\"0%\" stop-color=\"" + CalculateColor(pBrush->GetColor(), pBrush->GetAlpha()) + L"\"/>" +
|
||||
L"<stop offset=\"100%\" stop-color=\"" + CalculateColor(pBrush->GetColor2(), pBrush->GetAlpha2()) + L"\"/>" +
|
||||
L"</linearGradient>";
|
||||
m_wsDefs += L"<linearGradient id=\"" + wsStyleId + L"\">";
|
||||
|
||||
std::vector<long> arColors;
|
||||
std::vector<double> arPositions;
|
||||
pBrush->GetGradientColors(arColors, arPositions);
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < arColors.size(); ++unIndex)
|
||||
m_wsDefs += L"<stop offset=\"" + ConvertToWString(arPositions[unIndex], 2) +
|
||||
L"\" stop-color=\"" + CalculateColor(arColors[unIndex]) + L"\"/>";
|
||||
|
||||
m_wsDefs += L"</linearGradient>";
|
||||
|
||||
return wsStyleId;
|
||||
}
|
||||
@ -1237,6 +1331,46 @@ namespace MetaFile
|
||||
return std::wstring();
|
||||
}
|
||||
|
||||
std::wstring CInterpretatorSvgBase::CreateLineCap(const CLineCapData* pLineCap, const double& dAngle)
|
||||
{
|
||||
if (NULL == pLineCap)
|
||||
return std::wstring();
|
||||
|
||||
CustomLineCapDataType enLineCapDataType = pLineCap->GetType();
|
||||
|
||||
if (CustomLineCapDataType::CustomLineCapDataTypeDefault == enLineCapDataType)
|
||||
{
|
||||
const TEmfPlusCustomLineCapData* pCustomLineCap = dynamic_cast<const TEmfPlusCustomLineCapData*>(pLineCap);
|
||||
|
||||
if (NULL == pCustomLineCap)
|
||||
return std::wstring();
|
||||
|
||||
const std::wstring wsPath = CreatePath(*pCustomLineCap->pPath);
|
||||
|
||||
if (wsPath.empty())
|
||||
return std::wstring();
|
||||
|
||||
const std::wstring wsMarkerId {L"CUSTOM_MARKER_" + std::to_wstring(++m_unNumberDefs)};
|
||||
const TRectD oPathBounds{pCustomLineCap->pPath->GetBounds()};
|
||||
const double dWidth {std::abs(oPathBounds.Right - oPathBounds.Left)};
|
||||
const double dHeight {std::abs(oPathBounds.Bottom - oPathBounds.Top)};
|
||||
const std::wstring wsWidth {ConvertToWString(dWidth)};
|
||||
const std::wstring wsHeight {ConvertToWString(dHeight)};
|
||||
const std::wstring wsViewBox {L"viewBox=\"" + ConvertToWString(oPathBounds.Left) + L' ' + ConvertToWString(oPathBounds.Top) +
|
||||
L' ' + wsWidth + L' ' + wsHeight + L'\"'};
|
||||
|
||||
const double dRefY = -dHeight * (std::min)(3. / dWidth, 3. / dHeight);
|
||||
|
||||
m_wsDefs += L"<marker id=\"" + wsMarkerId + L"\" " + wsViewBox + L" markerWidth=\"" +
|
||||
wsWidth + L"\" markerHeight=\"" + wsHeight + L"\" refY=\"" + ConvertToWString(dRefY) +
|
||||
L"\" orient=\"" + std::to_wstring(dAngle) + L"\"><path d=\"" + wsPath + L"\"/></marker>";
|
||||
|
||||
return wsMarkerId;
|
||||
}
|
||||
|
||||
return std::wstring();
|
||||
}
|
||||
|
||||
CHatchGenerator::CHatchGenerator()
|
||||
: m_nHatchStyle(-1), m_unNumber(0), m_chStrokeAlpha(255), m_nBackgroundColor(-1), m_chBackgroundAlpha(255)
|
||||
{}
|
||||
@ -1936,4 +2070,29 @@ namespace MetaFile
|
||||
|
||||
return L"rgba(" + std::to_wstring(uchRed) + L", " + std::to_wstring(uchGreen) + L", " + std::to_wstring(uchBlue) + L", " + ConvertToWString((double)uchAlpha / 255., 3) + L')';
|
||||
}
|
||||
|
||||
std::wstring CalculateColor(unsigned int unColor)
|
||||
{
|
||||
BYTE chAlpha = unColor >> 24;
|
||||
|
||||
return CalculateColor(unColor, chAlpha);
|
||||
}
|
||||
|
||||
void NormalizeRect(TRectD& oRect)
|
||||
{
|
||||
if (oRect.Right < oRect.Left)
|
||||
std::swap(oRect.Right, oRect.Left);
|
||||
|
||||
if (oRect.Bottom < oRect.Top)
|
||||
std::swap(oRect.Bottom, oRect.Top);
|
||||
}
|
||||
|
||||
TRectD TranslateRect(const TRectL& oRect)
|
||||
{
|
||||
TRectD oNewRect(oRect.Left, oRect.Top, oRect.Right, oRect.Bottom);
|
||||
|
||||
NormalizeRect(oNewRect);
|
||||
|
||||
return oNewRect;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,8 +62,8 @@ namespace MetaFile
|
||||
|
||||
void AddClipValue(const std::wstring& wsId, const std::wstring& wsValue, int nClipMode = RGN_AND);
|
||||
|
||||
inline std::wstring GetClip() const;
|
||||
inline std::wstring GetClipId() const;
|
||||
std::wstring GetClip() const;
|
||||
std::wstring GetClipId() const;
|
||||
private:
|
||||
struct TClipValue
|
||||
{
|
||||
@ -77,6 +77,14 @@ namespace MetaFile
|
||||
bool m_bStartClip;
|
||||
};
|
||||
|
||||
enum class EShapeRendering
|
||||
{
|
||||
Auto,
|
||||
OptimizeSpeed,
|
||||
CrispEdges,
|
||||
GeometricPrecision
|
||||
};
|
||||
|
||||
class CInterpretatorSvgBase : public IOutputDevice
|
||||
{
|
||||
public:
|
||||
@ -90,6 +98,8 @@ namespace MetaFile
|
||||
void SetXmlWriter(XmlUtils::CXmlWriter* pXmlWriter);
|
||||
XmlUtils::CXmlWriter* GetXmlWriter();
|
||||
|
||||
void SetShapeRendering(EShapeRendering eShapeRenderingType);
|
||||
|
||||
std::wstring GetFile();
|
||||
void IncludeSvg(const std::wstring& wsSvg, const TRectD& oRect, const TRectD& oClipRect, TXForm *pTransform);
|
||||
private:
|
||||
@ -115,14 +125,18 @@ namespace MetaFile
|
||||
void CloseClip();
|
||||
|
||||
void AddNoneFill(NodeAttributes &arAttributes) const;
|
||||
void AddShapeRendering(NodeAttributes &arAttributes) const;
|
||||
|
||||
void AddLineCaps(NodeAttributes &arAttributes, const CPath* pMainPath);
|
||||
|
||||
TPointD GetCutPos() const;
|
||||
|
||||
std::wstring CreatePath(const CPath& oPath, const TXForm* pTransform = NULL);
|
||||
std::wstring CreatePath(const CPath& oPath, const TXForm* pTransform = NULL) const;
|
||||
std::wstring CreateHatchStyle(unsigned int unHatchStyle, double dWidth, double dHeight);
|
||||
std::wstring CreateDibPatternStyle(const IBrush* pBrush);
|
||||
std::wstring CreatePatternStyle(const IBrush* pBrush);
|
||||
std::wstring CreateGradient(const IBrush *pBrush);
|
||||
std::wstring CreateLineCap(const CLineCapData* pLineCap, const double& dAngle);
|
||||
private:
|
||||
TSvgViewport m_oViewport;
|
||||
TPointD m_oSizeWindow;
|
||||
@ -138,12 +152,17 @@ namespace MetaFile
|
||||
bool m_bUpdatedClip;
|
||||
CSvgClip m_oClip;
|
||||
|
||||
EShapeRendering m_eShapeRendering;
|
||||
|
||||
friend class CEmfInterpretatorSvg;
|
||||
friend class CWmfInterpretatorSvg;
|
||||
};
|
||||
|
||||
std::wstring CalculateColor(unsigned int unColor);
|
||||
std::wstring CalculateColor(unsigned int unColor, BYTE uchAlpha);
|
||||
std::wstring CalculateColor(BYTE uchRed, BYTE uchGreen, BYTE uchBlue, BYTE uchAlpha);
|
||||
void NormalizeRect(TRectD& oRect);
|
||||
TRectD TranslateRect(const TRectL &oRect);
|
||||
}
|
||||
|
||||
#endif // CINTERPRETATORSVGBASE_H
|
||||
|
||||
@ -29,7 +29,7 @@ namespace MetaFile
|
||||
}
|
||||
|
||||
void CWmfInterpretatorRender::DrawString(std::wstring &wsText, unsigned int unCharsCount, double dX, double dY, double *pDx,
|
||||
int iGraphicsMode, double dXScale, double dYScale)
|
||||
int iGraphicsMode, double dXScale, double dYScale)
|
||||
{
|
||||
if (NULL != m_pMetaFileRenderer)
|
||||
m_pMetaFileRenderer->DrawString(wsText, unCharsCount, dX, dY, pDx, iGraphicsMode, dXScale, dYScale);
|
||||
|
||||
@ -19,7 +19,7 @@ namespace MetaFile
|
||||
void DrawBitmap(double dX, double dY, double dW, double dH, BYTE* pBuffer, unsigned int unWidth, unsigned int unHeight) override;
|
||||
|
||||
void DrawString(std::wstring& wsText, unsigned int unCharsCount, double dX, double dY, double* pDx,
|
||||
int iGraphicsMode = 1, double dXScale = 1, double dYScale = 1) override;
|
||||
int iGraphicsMode = 1, double dXScale = 1, double dYScale = 1) override;
|
||||
|
||||
void DrawDriverString(const std::wstring& wsString, const std::vector<TPointD>& arPoints) override;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user