mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
text viewer: can select the indent spaces when the line mode is reflow.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26763 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1b613f583d
commit
a784938b78
6 changed files with 34 additions and 18 deletions
|
@ -28,7 +28,7 @@ Difference between viewer.rock
|
||||||
- If the next line is a blank line or spaces only line, this line breaks.
|
- If the next line is a blank line or spaces only line, this line breaks.
|
||||||
|
|
||||||
[reflow]
|
[reflow]
|
||||||
- indent changes two spaces.
|
- indent changes is two spaces (changable in the settings).
|
||||||
- supports the player which does not define HAVE_LCD_BITMAP.
|
- supports the player which does not define HAVE_LCD_BITMAP.
|
||||||
|
|
||||||
[alignment]
|
[alignment]
|
||||||
|
@ -44,8 +44,6 @@ TODO list
|
||||||
|
|
||||||
- add History feature.
|
- add History feature.
|
||||||
|
|
||||||
- when the line_mode is reflow, allow to specify indent spaces.
|
|
||||||
|
|
||||||
- draw images that are linked to the text. (<img src="...">)
|
- draw images that are linked to the text. (<img src="...">)
|
||||||
|
|
||||||
- play audios that are linked to the text. (<audio src="...">)
|
- play audios that are linked to the text. (<audio src="...">)
|
||||||
|
|
|
@ -315,6 +315,12 @@ static bool tv_font_setting(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool tv_indent_spaces_setting(void)
|
||||||
|
{
|
||||||
|
return rb->set_int("Indent Spaces", "", UNIT_INT,
|
||||||
|
&new_prefs.indent_spaces, NULL, 1, 0, 5, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
MENUITEM_FUNCTION(encoding_item, 0, "Encoding", tv_encoding_setting,
|
MENUITEM_FUNCTION(encoding_item, 0, "Encoding", tv_encoding_setting,
|
||||||
NULL, NULL, Icon_NOICON);
|
NULL, NULL, Icon_NOICON);
|
||||||
MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", tv_word_wrap_setting,
|
MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", tv_word_wrap_setting,
|
||||||
|
@ -333,6 +339,8 @@ MENUITEM_FUNCTION(footer_item, 0, "Show Footer", tv_footer_setting,
|
||||||
MENUITEM_FUNCTION(font_item, 0, "Font", tv_font_setting,
|
MENUITEM_FUNCTION(font_item, 0, "Font", tv_font_setting,
|
||||||
NULL, NULL, Icon_NOICON);
|
NULL, NULL, Icon_NOICON);
|
||||||
#endif
|
#endif
|
||||||
|
MENUITEM_FUNCTION(indent_spaces_item, 0, "Indent Spaces", tv_indent_spaces_setting,
|
||||||
|
NULL, NULL, Icon_NOICON);
|
||||||
|
|
||||||
MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
|
MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
|
||||||
&encoding_item, &word_wrap_item, &line_mode_item, &windows_item,
|
&encoding_item, &word_wrap_item, &line_mode_item, &windows_item,
|
||||||
|
@ -340,7 +348,7 @@ MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
&header_item, &footer_item, &font_item,
|
&header_item, &footer_item, &font_item,
|
||||||
#endif
|
#endif
|
||||||
&scroll_menu);
|
&scroll_menu, &indent_spaces_item);
|
||||||
|
|
||||||
static enum tv_menu_result tv_options_menu(void)
|
static enum tv_menu_result tv_options_menu(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp,
|
||||||
(oldp->horizontal_scrollbar != newp->horizontal_scrollbar) ||
|
(oldp->horizontal_scrollbar != newp->horizontal_scrollbar) ||
|
||||||
(oldp->vertical_scrollbar != newp->vertical_scrollbar) ||
|
(oldp->vertical_scrollbar != newp->vertical_scrollbar) ||
|
||||||
(oldp->encoding != newp->encoding) ||
|
(oldp->encoding != newp->encoding) ||
|
||||||
|
(oldp->indent_spaces != newp->indent_spaces) ||
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
(oldp->header_mode != newp->header_mode) ||
|
(oldp->header_mode != newp->header_mode) ||
|
||||||
(oldp->footer_mode != newp->footer_mode) ||
|
(oldp->footer_mode != newp->footer_mode) ||
|
||||||
|
@ -113,6 +114,7 @@ void tv_set_default_preferences(struct tv_preferences *p)
|
||||||
#endif
|
#endif
|
||||||
p->autoscroll_speed = 1;
|
p->autoscroll_speed = 1;
|
||||||
p->narrow_mode = NM_PAGE;
|
p->narrow_mode = NM_PAGE;
|
||||||
|
p->indent_spaces = 2;
|
||||||
/* Set codepage to system default */
|
/* Set codepage to system default */
|
||||||
p->encoding = rb->global_settings->default_codepage;
|
p->encoding = rb->global_settings->default_codepage;
|
||||||
p->file_name[0] = '\0';
|
p->file_name[0] = '\0';
|
||||||
|
|
|
@ -89,6 +89,8 @@ struct tv_preferences {
|
||||||
NM_TOP_BOTTOM,
|
NM_TOP_BOTTOM,
|
||||||
} narrow_mode;
|
} narrow_mode;
|
||||||
|
|
||||||
|
int indent_spaces;
|
||||||
|
|
||||||
unsigned char font_name[MAX_PATH];
|
unsigned char font_name[MAX_PATH];
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
struct font *font;
|
struct font *font;
|
||||||
|
|
|
@ -49,7 +49,8 @@
|
||||||
* horizontal_scrollbar 1
|
* horizontal_scrollbar 1
|
||||||
* horizontal_scroll_mode 1
|
* horizontal_scroll_mode 1
|
||||||
* narrow_mode 1
|
* narrow_mode 1
|
||||||
* (reserved) 13
|
* indent_spaces 1
|
||||||
|
* (reserved) 12
|
||||||
* font name MAX_PATH
|
* font name MAX_PATH
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@
|
||||||
#define TV_GLOBAL_SETTINGS_FILE VIEWERS_DIR "/tv_global.dat"
|
#define TV_GLOBAL_SETTINGS_FILE VIEWERS_DIR "/tv_global.dat"
|
||||||
|
|
||||||
#define TV_GLOBAL_SETTINGS_HEADER "\x54\x56\x47\x53" /* "TVGS" */
|
#define TV_GLOBAL_SETTINGS_HEADER "\x54\x56\x47\x53" /* "TVGS" */
|
||||||
#define TV_GLOBAL_SETTINGS_VERSION 0x36
|
#define TV_GLOBAL_SETTINGS_VERSION 0x37
|
||||||
#define TV_GLOBAL_SETTINGS_HEADER_SIZE 5
|
#define TV_GLOBAL_SETTINGS_HEADER_SIZE 5
|
||||||
#define TV_GLOBAL_SETTINGS_FIRST_VERSION 0x31
|
#define TV_GLOBAL_SETTINGS_FIRST_VERSION 0x31
|
||||||
|
|
||||||
|
@ -90,7 +91,8 @@
|
||||||
* horizontal_scrollbar 1
|
* horizontal_scrollbar 1
|
||||||
* horizontal_scroll_mode 1
|
* horizontal_scroll_mode 1
|
||||||
* narrow_mode 1
|
* narrow_mode 1
|
||||||
* (reserved) 13
|
* indent_spaces 1
|
||||||
|
* (reserved) 12
|
||||||
* font name MAX_PATH
|
* font name MAX_PATH
|
||||||
* bookmark count 1
|
* bookmark count 1
|
||||||
* [1st bookmark]
|
* [1st bookmark]
|
||||||
|
@ -112,7 +114,7 @@
|
||||||
#define TV_SETTINGS_TMP_FILE VIEWERS_DIR "/tv_file.tmp"
|
#define TV_SETTINGS_TMP_FILE VIEWERS_DIR "/tv_file.tmp"
|
||||||
|
|
||||||
#define TV_SETTINGS_HEADER "\x54\x56\x53" /* "TVS" */
|
#define TV_SETTINGS_HEADER "\x54\x56\x53" /* "TVS" */
|
||||||
#define TV_SETTINGS_VERSION 0x37
|
#define TV_SETTINGS_VERSION 0x38
|
||||||
#define TV_SETTINGS_HEADER_SIZE 4
|
#define TV_SETTINGS_HEADER_SIZE 4
|
||||||
#define TV_SETTINGS_FIRST_VERSION 0x32
|
#define TV_SETTINGS_FIRST_VERSION 0x32
|
||||||
|
|
||||||
|
@ -174,6 +176,11 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre
|
||||||
else
|
else
|
||||||
prefs->narrow_mode = NM_PAGE;
|
prefs->narrow_mode = NM_PAGE;
|
||||||
|
|
||||||
|
if (version > 5)
|
||||||
|
prefs->indent_spaces = *p++;
|
||||||
|
else
|
||||||
|
prefs->indent_spaces = 2;
|
||||||
|
|
||||||
rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH);
|
rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH);
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
@ -204,6 +211,7 @@ static bool tv_write_preferences(int pfd, const struct tv_preferences *prefs)
|
||||||
*p++ = prefs->horizontal_scrollbar;
|
*p++ = prefs->horizontal_scrollbar;
|
||||||
*p++ = prefs->horizontal_scroll_mode;
|
*p++ = prefs->horizontal_scroll_mode;
|
||||||
*p++ = prefs->narrow_mode;
|
*p++ = prefs->narrow_mode;
|
||||||
|
*p++ = prefs->indent_spaces;
|
||||||
|
|
||||||
rb->memcpy(buf + 28, prefs->font_name, MAX_PATH);
|
rb->memcpy(buf + 28, prefs->font_name, MAX_PATH);
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,6 @@ enum tv_text_type {
|
||||||
|
|
||||||
#define TV_MAX_BLOCKS 5
|
#define TV_MAX_BLOCKS 5
|
||||||
|
|
||||||
/*
|
|
||||||
* number of spaces to indent first paragraph
|
|
||||||
* (this value uses the line mode is REFLOW only)
|
|
||||||
*/
|
|
||||||
#define TV_INDENT_SPACES 2
|
|
||||||
|
|
||||||
static const struct tv_preferences *prefs;
|
static const struct tv_preferences *prefs;
|
||||||
static enum tv_text_type text_type = TV_TEXT_UNKNOWN;
|
static enum tv_text_type text_type = TV_TEXT_UNKNOWN;
|
||||||
|
|
||||||
|
@ -434,7 +428,7 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
|
||||||
is_indent = false;
|
is_indent = false;
|
||||||
|
|
||||||
if (prefs->line_mode == REFLOW && is_indent)
|
if (prefs->line_mode == REFLOW && is_indent)
|
||||||
gw = tv_glyph_width(ch) * TV_INDENT_SPACES;
|
gw = tv_glyph_width(ch) * prefs->indent_spaces;
|
||||||
else
|
else
|
||||||
gw = tv_glyph_width(ch);
|
gw = tv_glyph_width(ch);
|
||||||
|
|
||||||
|
@ -451,12 +445,13 @@ static int tv_parse_text(const unsigned char *src, unsigned short *ucs,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefs->line_mode == REFLOW && is_indent)
|
if (prefs->line_mode != REFLOW || !is_indent)
|
||||||
|
ucs[chars++] = ch;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
for (i = 1; i < TV_INDENT_SPACES; i++)
|
for (i = 0; i < prefs->indent_spaces; i++)
|
||||||
ucs[chars++] = ch;
|
ucs[chars++] = ch;
|
||||||
}
|
}
|
||||||
ucs[chars++] = ch;
|
|
||||||
|
|
||||||
if (tv_is_line_break_char(ch))
|
if (tv_is_line_break_char(ch))
|
||||||
{
|
{
|
||||||
|
@ -518,6 +513,9 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
|
||||||
tv_get_ucs(src, &ch);
|
tv_get_ucs(src, &ch);
|
||||||
is_indent = (tv_isspace(ch) && !is_break_line);
|
is_indent = (tv_isspace(ch) && !is_break_line);
|
||||||
|
|
||||||
|
if (is_indent && prefs->indent_spaces == 0 && (expand_extra_line = !expand_extra_line) == true)
|
||||||
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < block_count; i++)
|
for (i = 0; i < block_count; i++)
|
||||||
{
|
{
|
||||||
size += tv_parse_text(src + size, ucsbuf[i], &chars[i], is_indent);
|
size += tv_parse_text(src + size, ucsbuf[i], &chars[i], is_indent);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue