diff options
author | lexborisov <lex.borisov@gmail.com> | 2016-09-09 15:14:09 +0300 |
---|---|---|
committer | lexborisov <lex.borisov@gmail.com> | 2016-09-09 15:14:09 +0300 |
commit | 40cf5dc93739e29856c890906f64a397bcb95392 (patch) | |
tree | a9d96525b56c8ff868be5203f3af34825160c9d5 /source/myhtml | |
parent | 3a6dbfba0fa8a5623c0ef7b8d1598fb4eaa06dd9 (diff) |
Redesigned MyFONT; Added new example for get glyph metrics.
Diffstat (limited to 'source/myhtml')
-rw-r--r-- | source/myhtml/encoding.c | 35 | ||||
-rw-r--r-- | source/myhtml/encoding.h | 1 | ||||
-rw-r--r-- | source/myhtml/myhtml.c | 4 | ||||
-rw-r--r-- | source/myhtml/parser.c | 16 | ||||
-rw-r--r-- | source/myhtml/tokenizer.c | 32 |
5 files changed, 70 insertions, 18 deletions
diff --git a/source/myhtml/encoding.c b/source/myhtml/encoding.c index 737f2fa..1c7560a 100644 --- a/source/myhtml/encoding.c +++ b/source/myhtml/encoding.c @@ -1098,6 +1098,41 @@ size_t myhtml_encoding_codepoint_to_lowercase_ascii_utf_8(size_t codepoint, char return 0; } +size_t myhtml_encoding_ascii_utf_8_to_codepoint(const unsigned char* data, size_t* codepoint) +{ + if (*data < 0x80){ + /* 0xxxxxxx */ + *codepoint = (size_t)*data; + return 1; + } + else if ((*data & 0xe0) == 0xc0) { + /* 110xxxxx 10xxxxxx */ + *codepoint = (data[0] ^ (0xC0 & data[0])) << 6; + *codepoint |= (data[1] ^ (0x80 & data[1])); + + return 2; + } + else if ((*data & 0xf0) == 0xe0) { + /* 1110xxxx 10xxxxxx 10xxxxxx */ + *codepoint = (data[0] ^ (0xE0 & data[0])) << 12; + *codepoint |= (data[1] ^ (0x80 & data[1])) << 6; + *codepoint |= (data[2] ^ (0x80 & data[2])); + + return 3; + } + else if ((*data & 0xf8) == 0xf0) { + /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + *codepoint = (data[0] ^ (0xF0 & data[0])) << 18; + *codepoint |= (data[1] ^ (0x80 & data[1])) << 12; + *codepoint |= (data[2] ^ (0x80 & data[2])) << 6; + *codepoint |= (data[3] ^ (0x80 & data[3])); + + return 4; + } + + return 0; +} + size_t myhtml_encoding_codepoint_to_ascii_utf_16(size_t codepoint, char *data) { if((codepoint >> 16)) { diff --git a/source/myhtml/encoding.h b/source/myhtml/encoding.h index f376aae..8c7b679 100644 --- a/source/myhtml/encoding.h +++ b/source/myhtml/encoding.h @@ -127,6 +127,7 @@ enum myhtml_encoding_status myhtml_encoding_decode_x_user_defined(unsigned const size_t myhtml_encoding_codepoint_to_ascii_utf_8(size_t codepoint, char *data); size_t myhtml_encoding_codepoint_to_lowercase_ascii_utf_8(size_t codepoint, char *data); size_t myhtml_encoding_codepoint_to_ascii_utf_16(size_t codepoint, char *data); +size_t myhtml_encoding_ascii_utf_8_to_codepoint(const unsigned char* data, size_t* codepoint); void myhtml_encoding_result_clean(myhtml_encoding_result_t *res); diff --git a/source/myhtml/myhtml.c b/source/myhtml/myhtml.c index 387d8f4..d64b18b 100644 --- a/source/myhtml/myhtml.c +++ b/source/myhtml/myhtml.c @@ -1403,7 +1403,7 @@ void myhtml_queue_add(myhtml_tree_t *tree, size_t begin, myhtml_token_node_t* to if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) { myhtml_parser_worker(0, qnode); - while(myhtml_rules_tree_dispatcher(tree, token)){}; + myhtml_parser_stream(0, qnode); tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread, tree->queue, 4, NULL); } @@ -1414,7 +1414,7 @@ void myhtml_queue_add(myhtml_tree_t *tree, size_t begin, myhtml_token_node_t* to #else myhtml_parser_worker(0, qnode); - while(myhtml_rules_tree_dispatcher(tree, token)){}; + myhtml_parser_stream(0, qnode); tree->current_qnode = mythread_queue_node_malloc_limit(tree->myhtml->thread, tree->queue, 4, NULL); diff --git a/source/myhtml/parser.c b/source/myhtml/parser.c index 82b87f5..bc77b9f 100644 --- a/source/myhtml/parser.c +++ b/source/myhtml/parser.c @@ -185,7 +185,21 @@ void myhtml_parser_worker(mythread_id_t thread_id, mythread_queue_node_t *qnode) myhtml_tree_t* tree = qnode->tree; myhtml_token_node_t* token = qnode->token; - if(qnode->tree->parse_flags & MyHTML_TREE_PARSE_FLAGS_WITHOUT_PROCESS_TOKEN) { + /* + * Tree can not be built without tokens + * + * MyHTML_TREE_PARSE_FLAGS_WITHOUT_PROCESS_TOKEN == 3 + * MyHTML_TREE_PARSE_FLAGS_WITHOUT_BUILD_TREE == 1 + * + * MyHTML_TREE_PARSE_FLAGS_WITHOUT_PROCESS_TOKEN include MyHTML_TREE_PARSE_FLAGS_WITHOUT_BUILD_TREE + * + * if set only MyHTML_TREE_PARSE_FLAGS_WITHOUT_BUILD_TREE and check only for MyHTML_TREE_PARSE_FLAGS_WITHOUT_PROCESS_TOKEN + * return true + * we need check both, 1 and 2 + */ + if((qnode->tree->parse_flags & MyHTML_TREE_PARSE_FLAGS_WITHOUT_PROCESS_TOKEN) && + (qnode->tree->parse_flags & 2)) + { if(tree->callback_before_token) tree->callback_before_token_ctx = tree->callback_before_token(tree, token, tree->callback_before_token_ctx); diff --git a/source/myhtml/tokenizer.c b/source/myhtml/tokenizer.c index 605a9a3..7c8f777 100644 --- a/source/myhtml/tokenizer.c +++ b/source/myhtml/tokenizer.c @@ -257,24 +257,26 @@ void myhtml_tokenizer_pause(myhtml_tree_t* tree) void myhtml_tokenizer_calc_current_namespace(myhtml_tree_t* tree, myhtml_token_node_t* token_node) { - if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) - { - myhtml_tokenizer_state_set(tree) = tree->state_of_builder; - } - else { - if(token_node->tag_id == MyHTML_TAG_MATH || - token_node->tag_id == MyHTML_TAG_SVG || - token_node->tag_id == MyHTML_TAG_FRAMESET) + if((tree->parse_flags & MyHTML_TREE_PARSE_FLAGS_WITHOUT_BUILD_TREE) == 0) { + if(tree->flags & MyHTML_TREE_FLAGS_SINGLE_MODE) { - tree->token_namespace = token_node; + myhtml_tokenizer_state_set(tree) = tree->state_of_builder; } - else if(tree->token_namespace && (token_node->type & MyHTML_TOKEN_TYPE_CLOSE) == 0) { - const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(tree->tags, token_node->tag_id); - - if(tag_ctx->data_parser != MyHTML_TOKENIZER_STATE_DATA) + else { + if(token_node->tag_id == MyHTML_TAG_MATH || + token_node->tag_id == MyHTML_TAG_SVG || + token_node->tag_id == MyHTML_TAG_FRAMESET) { - myhtml_tree_wait_for_last_done_token(tree, token_node); - myhtml_tokenizer_state_set(tree) = tree->state_of_builder; + tree->token_namespace = token_node; + } + else if(tree->token_namespace && (token_node->type & MyHTML_TOKEN_TYPE_CLOSE) == 0) { + const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(tree->tags, token_node->tag_id); + + if(tag_ctx->data_parser != MyHTML_TOKENIZER_STATE_DATA) + { + myhtml_tree_wait_for_last_done_token(tree, token_node); + myhtml_tokenizer_state_set(tree) = tree->state_of_builder; + } } } } |