mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-08 19:44:45 +08:00
suggest words works
This commit is contained in:
parent
dd8d81d09c
commit
aa5174c13e
@ -29,9 +29,19 @@
|
||||
|
||||
static ret_t candidates_on_button_click(void* ctx, event_t* e) {
|
||||
char str[32];
|
||||
const char* p = utf8_from_utf16(WIDGET(ctx)->text.str, str, sizeof(str) - 1);
|
||||
input_method_t* im = input_method();
|
||||
wstr_t* text = &(WIDGET(ctx)->text);
|
||||
wchar_t c = text->str[text->size - 1];
|
||||
return_value_if_fail(im != NULL && text->size > 0, RET_FAIL);
|
||||
|
||||
utf8_from_utf16(text->str, str, sizeof(str) - 1);
|
||||
if (input_method_commit_text(im, str) == RET_OK) {
|
||||
suggest_words_t* suggest_words = im->suggest_words;
|
||||
if (suggest_words && suggest_words_find(suggest_words, c) == RET_OK) {
|
||||
input_method_dispatch_candidates(im, suggest_words->words, suggest_words->words_nr);
|
||||
}
|
||||
}
|
||||
|
||||
input_method_commit_text(input_method(), p);
|
||||
(void)e;
|
||||
|
||||
return RET_OK;
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "base/widget.h"
|
||||
#include "base/input_engine.h"
|
||||
#include "base/suggest_words.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
@ -149,6 +150,7 @@ typedef struct _input_method_t {
|
||||
input_type_t input_type;
|
||||
|
||||
input_engine_t* engine;
|
||||
suggest_words_t* suggest_words;
|
||||
/**
|
||||
* 子类需要实现的函数。
|
||||
*/
|
||||
|
145
src/base/suggest_words.c
Normal file
145
src/base/suggest_words.c
Normal file
@ -0,0 +1,145 @@
|
||||
/**
|
||||
* File: suggest_words.h
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: suggest_words
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* License file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* History:
|
||||
* ================================================================
|
||||
* 2018-06-27 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base/mem.h"
|
||||
#include "base/utf8.h"
|
||||
#include "base/buffer.h"
|
||||
#include "base/suggest_words.h"
|
||||
|
||||
/*ref:tools/word_gen/gen.js*/
|
||||
|
||||
typedef struct _suggest_words_index_t {
|
||||
uint32_t code;
|
||||
uint32_t offset;
|
||||
} suggest_words_index_t;
|
||||
|
||||
typedef struct _suggest_words_header_t {
|
||||
uint32_t version;
|
||||
uint32_t nr;
|
||||
} suggest_words_header_t;
|
||||
|
||||
static const uint8_t* suggest_words_find_data(const resource_info_t* res, wchar_t c) {
|
||||
int low = 0;
|
||||
int mid = 0;
|
||||
int high = 0;
|
||||
int result = 0;
|
||||
const suggest_words_header_t* header = (suggest_words_header_t*)(res->data);
|
||||
const suggest_words_index_t* index =
|
||||
(suggest_words_index_t*)(res->data + sizeof(suggest_words_header_t));
|
||||
uint32_t data_offset =
|
||||
sizeof(suggest_words_header_t) + header->nr * sizeof(suggest_words_index_t);
|
||||
|
||||
high = header->nr - 1;
|
||||
while (low <= high) {
|
||||
mid = low + ((high - low) >> 1);
|
||||
result = index[mid].code - c;
|
||||
|
||||
if (result == 0) {
|
||||
return res->data + data_offset + index[mid].offset;
|
||||
} else if (result < 0) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const uint16_t* get_str(const uint16_t* p16, wchar_t* str, uint32_t max_chars) {
|
||||
uint32_t i = 0;
|
||||
wchar_t* pc = str;
|
||||
|
||||
while (*p16) {
|
||||
if (i < max_chars) {
|
||||
*pc++ = *p16++;
|
||||
} else {
|
||||
p16++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return p16 + 1;
|
||||
}
|
||||
|
||||
static ret_t suggest_words_update(suggest_words_t* suggest_words, const uint8_t* data) {
|
||||
wbuffer_t wb;
|
||||
uint32_t i = 0;
|
||||
uint32_t nr = 0;
|
||||
char sword[64];
|
||||
wchar_t word[16];
|
||||
const uint8_t* p = data;
|
||||
const uint16_t* p16 = (const uint16_t*)(data + 4);
|
||||
|
||||
wbuffer_init(&wb, (uint8_t*)(suggest_words->words), sizeof(suggest_words->words));
|
||||
|
||||
load_uint32(p, nr);
|
||||
suggest_words->words_nr = 0;
|
||||
|
||||
for (i = 0; i < nr; i++) {
|
||||
memset(word, 0x00, sizeof(word));
|
||||
p16 = get_str(p16, word, ARRAY_SIZE(word) - 1);
|
||||
|
||||
utf8_from_utf16(word, sword, sizeof(sword));
|
||||
if (wbuffer_write_string(&wb, sword) != RET_OK) {
|
||||
break;
|
||||
}
|
||||
suggest_words->words_nr++;
|
||||
}
|
||||
|
||||
if(suggest_words->words_nr < 5) {
|
||||
if (wbuffer_write_string(&wb, "的") == RET_OK) {
|
||||
suggest_words->words_nr++;
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t suggest_words_find(suggest_words_t* suggest_words, wchar_t c) {
|
||||
const uint8_t* data = NULL;
|
||||
return_value_if_fail(suggest_words != NULL && c != 0, RET_BAD_PARAMS);
|
||||
|
||||
data = suggest_words_find_data(suggest_words->res, c);
|
||||
return_value_if_fail(data != NULL, RET_FAIL);
|
||||
|
||||
return suggest_words_update(suggest_words, data);
|
||||
}
|
||||
|
||||
suggest_words_t* suggest_words_create(const resource_info_t* res) {
|
||||
suggest_words_t* suggest_words = NULL;
|
||||
return_value_if_fail(res != NULL && res->data != NULL, NULL);
|
||||
|
||||
suggest_words = TKMEM_ZALLOC(suggest_words_t);
|
||||
return_value_if_fail(suggest_words != NULL, NULL);
|
||||
|
||||
suggest_words->res = res;
|
||||
|
||||
return suggest_words;
|
||||
}
|
||||
|
||||
ret_t suggest_words_destroy(suggest_words_t* suggest_words) {
|
||||
return_value_if_fail(suggest_words != NULL, RET_BAD_PARAMS);
|
||||
|
||||
TKMEM_FREE(suggest_words);
|
||||
|
||||
return RET_OK;
|
||||
}
|
87
src/base/suggest_words.h
Normal file
87
src/base/suggest_words.h
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* File: suggest_words.h
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: suggest_words
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* License file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* History:
|
||||
* ================================================================
|
||||
* 2018-06-27 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TK_SUGGEST_WORDS_H
|
||||
#define TK_SUGGEST_WORDS_H
|
||||
|
||||
#include "base/resource_manager.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
#define TK_IM_MAX_SUGGEST_CHARS 127
|
||||
|
||||
struct _suggest_words_t;
|
||||
typedef struct _suggest_words_t suggest_words_t;
|
||||
|
||||
/**
|
||||
* @class suggest_words_t
|
||||
* @scriptable no
|
||||
* 输入法联想字词。
|
||||
*/
|
||||
struct _suggest_words_t {
|
||||
/**
|
||||
* @property {char*} words
|
||||
* @private
|
||||
* 联想字列表。find函数执行成功后会更新。
|
||||
*/
|
||||
char words[TK_IM_MAX_SUGGEST_CHARS + 1];
|
||||
/**
|
||||
* @property {uint32_t} words_nr
|
||||
* @private
|
||||
* 联想字/词个数。find函数执行成功后会更新。
|
||||
*/
|
||||
uint32_t words_nr;
|
||||
|
||||
const resource_info_t* res;
|
||||
};
|
||||
|
||||
/**
|
||||
* @method suggest_words_create
|
||||
* @constructor
|
||||
* 创建联想字对象。
|
||||
*
|
||||
* @return {suggest_words_t*} 返回联想字对象。
|
||||
*/
|
||||
suggest_words_t* suggest_words_create(const resource_info_t* res);
|
||||
|
||||
/**
|
||||
* @method suggest_words_find
|
||||
* 查找prefix对应的联想字列表,成功后会更新words/words_nr。
|
||||
* @param {suggest_words_t*} suggest_words 联想字对象。
|
||||
* @param {wchar_t} c 字符。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t suggest_words_find(suggest_words_t* suggest_words, wchar_t c);
|
||||
|
||||
/**
|
||||
* @method suggest_words_destroy
|
||||
* @deconstructor
|
||||
* 销毁联想字对象。
|
||||
* @param {suggest_words_t*} suggest_words 联想字对象。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t suggest_words_destroy(suggest_words_t* suggest_words);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_SUGGEST_WORDS_H*/
|
@ -232,6 +232,7 @@ typedef ret_t (*tk_destroy_t)(void* data);
|
||||
typedef ret_t (*tk_on_done_t)(void* data);
|
||||
typedef bool_t (*tk_is_valid_t)(void* data);
|
||||
|
||||
/*NAME_LEN+1 must aligned to 4*/
|
||||
enum { NAME_LEN = 15 };
|
||||
|
||||
typedef float float_t;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "base/idle.h"
|
||||
#include "base/window.h"
|
||||
#include "base/keyboard.h"
|
||||
#include "suggest_words.inc"
|
||||
#include "base/input_method.h"
|
||||
#include "ui_loader/ui_builder_default.h"
|
||||
|
||||
@ -201,6 +202,7 @@ input_method_t* input_method_create(void) {
|
||||
im->request = input_method_default_request;
|
||||
emitter_init(&(im->emitter));
|
||||
im->engine = input_engine_create();
|
||||
im->suggest_words = suggest_words_create((const resource_info_t*)(data_suggest_words));
|
||||
|
||||
return im;
|
||||
}
|
||||
@ -210,6 +212,8 @@ ret_t input_method_destroy(input_method_t* im) {
|
||||
|
||||
emitter_deinit(&(im->emitter));
|
||||
input_engine_destroy(im->engine);
|
||||
suggest_words_destroy(im->suggest_words);
|
||||
|
||||
TKMEM_FREE(im);
|
||||
|
||||
return RET_OK;
|
||||
|
1501
src/input_methods/suggest_words.inc
Normal file
1501
src/input_methods/suggest_words.inc
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include "base/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/button.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include "base/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/progress_bar.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include "base/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/progress_bar.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include "base/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/progress_bar.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include "base/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/progress_bar.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/array.h"
|
||||
#include "base/array.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <math.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/buffer.h"
|
||||
#include "base/buffer.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/button.h"
|
||||
#include "base/button.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/array.h"
|
||||
#include "base/array.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/font_manager.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/check_button.h"
|
||||
|
||||
static ret_t on_changed(void* ctx, event_t* e) {
|
||||
|
@ -1 +1 @@
|
||||
#include "base/main_loop.h"
|
||||
#include "base/main_loop.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/dialog.h"
|
||||
#include "base/dialog.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/edit.h"
|
||||
#include "base/edit.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/emitter.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/enums.h"
|
||||
#include "base/enums.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/resource_manager.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/event_queue.h"
|
||||
|
||||
#define NR 10
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/mem.h"
|
||||
#include "base/mem.h"
|
||||
#include "base/events.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "font_dummy.h"
|
||||
#include "font_dummy.h"
|
||||
|
||||
static glyph_t s_glyph_0;
|
||||
static glyph_t s_glyph_1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef TK_FONT_DUMMY_H
|
||||
#ifndef TK_FONT_DUMMY_H
|
||||
#define TK_FONT_DUMMY_H
|
||||
|
||||
#include "base/font.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/font.h"
|
||||
#include "base/mem.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/font_manager.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/fs.h"
|
||||
#include "base/fs.h"
|
||||
#include "base/mem.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
static uint32_t s_now = 0;
|
||||
static uint32_t s_now = 0;
|
||||
static uint32_t timer_get_time() {
|
||||
return s_now;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/glyph_cache.h"
|
||||
#include "base/glyph_cache.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(GlyphCache, basic) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/idle.h"
|
||||
#include "base/idle.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/mem.h"
|
||||
#include "base/mem.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "tools/common/utils.h"
|
||||
#include "base/image_manager.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/image_manager.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/image.h"
|
||||
#include "base/image.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/font_manager.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/keyboard.h"
|
||||
#include "base/keyboard.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(KeyBoard, basic) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/canvas.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/label.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/layout.h"
|
||||
#include "base/layout.h"
|
||||
#include "base/group_box.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
292
tests/lcd_log.cc
292
tests/lcd_log.cc
@ -1,146 +1,146 @@
|
||||
/**
|
||||
* File: lcd_log.cc
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: log lcd commands
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* this program is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. see the
|
||||
* license file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* history:
|
||||
* ================================================================
|
||||
* 2018-01-13 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lcd_log.h"
|
||||
|
||||
typedef struct _lcd_log_t {
|
||||
lcd_t base;
|
||||
string str;
|
||||
} lcd_log_t;
|
||||
|
||||
static string itos(int v) {
|
||||
char str[32];
|
||||
snprintf(str, sizeof(str), "%d", v);
|
||||
|
||||
return string(str);
|
||||
}
|
||||
|
||||
static ret_t lcd_log_begin_frame(lcd_t* lcd, rect_t* dirty_rect) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "bf();";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "dhl(" + (itos(x)) + string(",") + (itos(y)) + string(",") + (itos(w)) + string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "dvl(" + (itos(x)) + string(",") + (itos(y)) + string(",") + (itos(h)) + string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) {
|
||||
uint32_t i = 0;
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
log->str += "dps(";
|
||||
for (i = 0; i < nr; i++) {
|
||||
point_t* p = points + i;
|
||||
log->str += string("(") + (itos(p->x)) + string(",") + (itos(p->y)) + string(")");
|
||||
}
|
||||
log->str += ");";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_fill_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "fr(" + (itos(x)) + string(",") + (itos(y)) + string(",") + (itos(w)) + string(",") +
|
||||
(itos(h)) + string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
log->str += "dg(" + (itos(src->x)) + string(",") + (itos(src->y)) + string(",") + (itos(src->w)) +
|
||||
string(",") + (itos(src->h)) + string(",") + (itos(x)) + string(",") + (itos(y)) +
|
||||
string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
log->str += "dg(" + (itos(src->x)) + string(",") + (itos(src->y)) + string(",") + (itos(src->w)) +
|
||||
string(",") + (itos(src->h)) + string(",") + (itos(dst->x)) + string(",") +
|
||||
(itos(dst->y)) + string(",") + (itos(dst->w)) + string(",") + (itos(dst->h)) +
|
||||
string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_end_frame(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "ef();";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_destroy(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
delete log;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
lcd_t* lcd_log_init(wh_t w, wh_t h) {
|
||||
lcd_log_t* lcd = new lcd_log_t();
|
||||
lcd_t* base = &(lcd->base);
|
||||
|
||||
memset(lcd, 0x00, sizeof(lcd_log_t));
|
||||
|
||||
base->begin_frame = lcd_log_begin_frame;
|
||||
base->draw_vline = lcd_log_draw_vline;
|
||||
base->draw_hline = lcd_log_draw_hline;
|
||||
base->fill_rect = lcd_log_fill_rect;
|
||||
base->draw_image = lcd_log_draw_image;
|
||||
base->draw_glyph = lcd_log_draw_glyph;
|
||||
base->draw_points = lcd_log_draw_points;
|
||||
base->end_frame = lcd_log_end_frame;
|
||||
base->destroy = lcd_log_destroy;
|
||||
|
||||
base->w = w;
|
||||
base->h = h;
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
ret_t lcd_log_reset(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str = "";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
const string& lcd_log_get_commands(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
return log->str;
|
||||
}
|
||||
/**
|
||||
* File: lcd_log.cc
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: log lcd commands
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* this program is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. see the
|
||||
* license file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* history:
|
||||
* ================================================================
|
||||
* 2018-01-13 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lcd_log.h"
|
||||
|
||||
typedef struct _lcd_log_t {
|
||||
lcd_t base;
|
||||
string str;
|
||||
} lcd_log_t;
|
||||
|
||||
static string itos(int v) {
|
||||
char str[32];
|
||||
snprintf(str, sizeof(str), "%d", v);
|
||||
|
||||
return string(str);
|
||||
}
|
||||
|
||||
static ret_t lcd_log_begin_frame(lcd_t* lcd, rect_t* dirty_rect) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "bf();";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "dhl(" + (itos(x)) + string(",") + (itos(y)) + string(",") + (itos(w)) + string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "dvl(" + (itos(x)) + string(",") + (itos(y)) + string(",") + (itos(h)) + string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) {
|
||||
uint32_t i = 0;
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
log->str += "dps(";
|
||||
for (i = 0; i < nr; i++) {
|
||||
point_t* p = points + i;
|
||||
log->str += string("(") + (itos(p->x)) + string(",") + (itos(p->y)) + string(")");
|
||||
}
|
||||
log->str += ");";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_fill_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "fr(" + (itos(x)) + string(",") + (itos(y)) + string(",") + (itos(w)) + string(",") +
|
||||
(itos(h)) + string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
log->str += "dg(" + (itos(src->x)) + string(",") + (itos(src->y)) + string(",") + (itos(src->w)) +
|
||||
string(",") + (itos(src->h)) + string(",") + (itos(x)) + string(",") + (itos(y)) +
|
||||
string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
log->str += "dg(" + (itos(src->x)) + string(",") + (itos(src->y)) + string(",") + (itos(src->w)) +
|
||||
string(",") + (itos(src->h)) + string(",") + (itos(dst->x)) + string(",") +
|
||||
(itos(dst->y)) + string(",") + (itos(dst->w)) + string(",") + (itos(dst->h)) +
|
||||
string(");");
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_end_frame(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str += "ef();";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_log_destroy(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
delete log;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
lcd_t* lcd_log_init(wh_t w, wh_t h) {
|
||||
lcd_log_t* lcd = new lcd_log_t();
|
||||
lcd_t* base = &(lcd->base);
|
||||
|
||||
memset(lcd, 0x00, sizeof(lcd_log_t));
|
||||
|
||||
base->begin_frame = lcd_log_begin_frame;
|
||||
base->draw_vline = lcd_log_draw_vline;
|
||||
base->draw_hline = lcd_log_draw_hline;
|
||||
base->fill_rect = lcd_log_fill_rect;
|
||||
base->draw_image = lcd_log_draw_image;
|
||||
base->draw_glyph = lcd_log_draw_glyph;
|
||||
base->draw_points = lcd_log_draw_points;
|
||||
base->end_frame = lcd_log_end_frame;
|
||||
base->destroy = lcd_log_destroy;
|
||||
|
||||
base->w = w;
|
||||
base->h = h;
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
ret_t lcd_log_reset(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
log->str = "";
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
const string& lcd_log_get_commands(lcd_t* lcd) {
|
||||
lcd_log_t* log = (lcd_log_t*)lcd;
|
||||
|
||||
return log->str;
|
||||
}
|
||||
|
@ -1,39 +1,39 @@
|
||||
/**
|
||||
* File: lcd_log.h
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: log lcd commands.
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* this program is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. see the
|
||||
* license file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* history:
|
||||
* ================================================================
|
||||
* 2018-01-13 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LCD_LOG_H
|
||||
#define LCD_LOG_H
|
||||
|
||||
#include <string>
|
||||
#include "base/lcd.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
lcd_t* lcd_log_init(wh_t w, wh_t h);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
ret_t lcd_log_reset(lcd_t* lcd);
|
||||
const string& lcd_log_get_commands(lcd_t* lcd);
|
||||
|
||||
#endif /*LCD_LOG_H*/
|
||||
/**
|
||||
* File: lcd_log.h
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: log lcd commands.
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* this program is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. see the
|
||||
* license file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* history:
|
||||
* ================================================================
|
||||
* 2018-01-13 li xianjing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LCD_LOG_H
|
||||
#define LCD_LOG_H
|
||||
|
||||
#include <string>
|
||||
#include "base/lcd.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
lcd_t* lcd_log_init(wh_t w, wh_t h);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
ret_t lcd_log_reset(lcd_t* lcd);
|
||||
const string& lcd_log_get_commands(lcd_t* lcd);
|
||||
|
||||
#endif /*LCD_LOG_H*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/canvas.h"
|
||||
#include "base/canvas.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "lcd/lcd_mem_rgba8888.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/locale.h"
|
||||
#include "base/locale.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2006, Google Inc.
|
||||
// Copyright 2006, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/matrix.h"
|
||||
#include "base/matrix.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(Matrix, basic) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/pages.h"
|
||||
#include "base/pages.h"
|
||||
#include "base/view.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/progress_bar.h"
|
||||
#include "base/progress_bar.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/rect.h"
|
||||
#include "base/rect.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(Rect, merge) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/resource_manager.h"
|
||||
#include "base/resource_manager.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(ResourceManager, basic) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/rom_fs.h"
|
||||
#include "base/rom_fs.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(ROMFS, basic) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/button.h"
|
||||
#include "base/slide_view.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/slider.h"
|
||||
#include "base/slider.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "blend/soft_g2d.h"
|
||||
#include "blend/soft_g2d.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define FB_W 8
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/locale.h"
|
||||
#include "tools/str_gen/str_gen.h"
|
||||
#include "tools/str_gen/xml_str_gen.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/str.h"
|
||||
#include "base/str.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(Str, basic) {
|
||||
|
21
tests/suggest_test.cc
Normal file
21
tests/suggest_test.cc
Normal file
@ -0,0 +1,21 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/suggest_words.h"
|
||||
#include "tests/suggest_test.inc"
|
||||
|
||||
TEST(SuggestWords, basic) {
|
||||
suggest_words_t* sw = suggest_words_create((const resource_info_t*)data_suggest_test);
|
||||
|
||||
ASSERT_EQ(suggest_words_find(sw, L"故"[0]), RET_OK);
|
||||
ASSERT_EQ(sw->words_nr, 2);
|
||||
ASSERT_EQ(strcmp(sw->words, "事"), 0);
|
||||
|
||||
ASSERT_EQ(suggest_words_find(sw, L"飞"[0]), RET_OK);
|
||||
ASSERT_EQ(sw->words_nr, 2);
|
||||
ASSERT_EQ(strcmp(sw->words, "刀"), 0);
|
||||
|
||||
ASSERT_EQ(suggest_words_find(sw, L"几"[0]), RET_OK);
|
||||
ASSERT_EQ(sw->words_nr, 6);
|
||||
ASSERT_EQ(strcmp(sw->words, "个"), 0);
|
||||
|
||||
suggest_words_destroy(sw);
|
||||
}
|
1501
tests/suggest_test.inc
Normal file
1501
tests/suggest_test.inc
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/theme.h"
|
||||
#include "base/widget.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/enums.h"
|
||||
#include "base/theme.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include "base/timer.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/tokenizer.h"
|
||||
#include "base/tokenizer.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/dialog.h"
|
||||
#include "base/dialog.h"
|
||||
#include "ui_loader/ui_builder_default.h"
|
||||
#include "ui_loader/ui_builder_writer.h"
|
||||
#include "ui_loader/ui_loader_default.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/dialog.h"
|
||||
#include "base/dialog.h"
|
||||
#include "ui_loader/ui_builder_default.h"
|
||||
#include "ui_loader/ui_builder_writer.h"
|
||||
#include "ui_loader/ui_loader_xml.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include "base/utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/value.h"
|
||||
#include "base/value.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(value, i8) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/velocity.h"
|
||||
#include "base/velocity.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <math.h>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "base/mem.h"
|
||||
#include "base/button.h"
|
||||
#include "base/widget_factory.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "base/button.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "base/window.h"
|
||||
#include "base/window.h"
|
||||
#include "base/canvas.h"
|
||||
#include "base/widget.h"
|
||||
#include "font_dummy.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "xml/xml_parser.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -9,10 +9,10 @@ segment.useDefault();
|
||||
|
||||
let allWords = {};
|
||||
let doneURLS = {};
|
||||
let maxURLS = 10;
|
||||
let maxURLS = 40;
|
||||
let maxPages = maxURLS;
|
||||
const maxWordsPerChar = 10;
|
||||
let rootURL = ['https://blog.csdn.net/'];
|
||||
let rootURL = ['http://www.sina.com.cn/', 'https://blog.csdn.net/'];
|
||||
|
||||
function bufferWriteWord(buff, word, start) {
|
||||
let offset = start;
|
||||
@ -90,10 +90,10 @@ function tidyResult() {
|
||||
}
|
||||
|
||||
arr.sort((a, b) => {
|
||||
return a.c - b.c;
|
||||
return a.c.charCodeAt(0) - b.c.charCodeAt(0);
|
||||
})
|
||||
|
||||
console.log(JSON.stringify(arr, null, '\t'));
|
||||
console.log(JSON.stringify(arr, null, ' '));
|
||||
|
||||
return arr;
|
||||
}
|
||||
@ -144,7 +144,11 @@ function addUrls(requestUrl, urls, c) {
|
||||
const href = iter.attribs.href;
|
||||
const url = URL.resolve(requestUrl, href);
|
||||
|
||||
if (doneURLS[url] || url.indexOf('#') >= 0 || url.indexOf('css') >= 0 || url.indexOf('ico') >= 0) {
|
||||
if (url.indexOf('javascript:') >= 0 || url.indexOf('css') >= 0 || url.indexOf(':') > 8) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (doneURLS[url] || url.indexOf('#') >= 0 || url.indexOf('ico') >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -194,4 +198,4 @@ var c = new Crawler({
|
||||
}
|
||||
});
|
||||
|
||||
c.queue(rootURL);
|
||||
c.queue(rootURL);
|
||||
|
BIN
tools/word_gen/words.bin
Normal file
BIN
tools/word_gen/words.bin
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user