From: Good Guy Date: Tue, 9 May 2017 19:42:12 +0000 (-0600) Subject: textbox positions array deleted, 3K bytes + stats for titler X-Git-Url: http://git.cinelerra-gg.org/git/?a=commitdiff_plain;h=4c1a91d9f9373e564ecbeb8f568e4a3e7fe48e64;p=goodguy%2Fhistory.git textbox positions array deleted, 3K bytes + stats for titler --- diff --git a/cinelerra-5.1/guicast/bctextbox.C b/cinelerra-5.1/guicast/bctextbox.C index 6916f2e1..a6611352 100644 --- a/cinelerra-5.1/guicast/bctextbox.C +++ b/cinelerra-5.1/guicast/bctextbox.C @@ -133,7 +133,6 @@ BC_TextBox::~BC_TextBox() delete suggestions_popup; suggestions->remove_all_objects(); delete suggestions; - delete [] positions; delete [] wtext; if( size > 0 ) delete [] text; @@ -171,8 +170,6 @@ int BC_TextBox::reset_parameters(int rows, int has_border, int font, int size) wtext = 0; wsize = 0; wlen = 0; - positions = 0; - plen = 0; keypress_draw = 1; last_keypress = 0; separators = 0; @@ -226,12 +223,6 @@ int BC_TextBox::wtext_update() wchar_t *ntext = new wchar_t[nsize+1]; memcpy(ntext, wtext, wsize*sizeof(wtext[0])); delete [] wtext; wtext = ntext; wsize = nsize; - int *npositions = new int[nsize+1]; - if( plen > 0 ) - memcpy(npositions, positions, (plen+1)*sizeof(positions[0])); - else - npositions[0] = 0; - delete [] positions; positions = npositions; plen = nsize; } wlen = BC_Resources::encode(src_enc, dst_enc, text, strlen(text), (char*)wtext, wsize*sizeof(wchar_t)) / sizeof(wchar_t); @@ -406,7 +397,6 @@ void BC_TextBox::set_suggestions(ArrayList *suggestions, int column) if( col < 0 ) col = 0; char *cur = current_suggestion + col; tstrcat(cur); - draw(0); // update positions highlight_letter2 = wtext_update(); //printf("BC_TextBox::set_suggestions %d %d\n", __LINE__, suggestion_column); @@ -687,13 +677,13 @@ void BC_TextBox::draw(int flush) set_color(color); if(highlight_letter1 >= row_begin && highlight_letter1 <= row_end) - highlight_x1 = positions[highlight_letter1]; + highlight_x1 = get_x_position(highlight_letter1, row_begin); else highlight_x1 = 0; if(highlight_letter2 > row_begin && highlight_letter2 <= row_end) - highlight_x2 = positions[highlight_letter2]; + highlight_x2 = get_x_position(highlight_letter2, row_begin); else highlight_x2 = get_w(); @@ -705,17 +695,14 @@ void BC_TextBox::draw(int flush) int len = row_end - row_begin; if( len > 0 ) { set_color(enabled ? resources->text_default : DMGREY); - draw_wtext(text_x, k + text_ascent, wtext_row, len, - 0, &positions[wtext_row - wtext]); + draw_wtext(text_x, k + text_ascent, wtext_row, len, 0); } - else - positions[wtext_row - wtext] = 0; // Get ibeam location if(ibeam_letter >= row_begin && ibeam_letter <= row_end) { need_ibeam = 0; ibeam_y = k - text_y; - ibeam_x = positions[ibeam_letter]; + ibeam_x = get_x_position(ibeam_letter, row_begin); } } } @@ -1767,6 +1754,11 @@ void BC_TextBox::do_separators(int ibeam_left) } } +int BC_TextBox::get_x_position(int i, int start) +{ + return get_text_width(font, &wtext[start], i - start); +} + void BC_TextBox::get_ibeam_position(int &x, int &y) { int i, row_begin, row_end; @@ -1779,7 +1771,7 @@ void BC_TextBox::get_ibeam_position(int &x, int &y) row_end = i; if( ibeam_letter >= row_begin && ibeam_letter <= row_end ) { - x = get_text_width(font, &wtext[row_begin], ibeam_letter - row_begin); + x = get_x_position(ibeam_letter, row_begin); //printf("BC_TextBox::get_ibeam_position %d %d %d %d %d\n", ibeam_letter, row_begin, row_end, x, y); return; } diff --git a/cinelerra-5.1/guicast/bctextbox.h b/cinelerra-5.1/guicast/bctextbox.h index a46661cd..a798e780 100644 --- a/cinelerra-5.1/guicast/bctextbox.h +++ b/cinelerra-5.1/guicast/bctextbox.h @@ -158,6 +158,7 @@ private: // ibeam_left causes the ibeam to move left. int is_separator(const char *txt, int i); void do_separators(int ibeam_left); + int get_x_position(int i, int start=0); void get_ibeam_position(int &x, int &y); void find_ibeam(int dispatch_event); void select_word(int &letter1, int &letter2, int ibeam_letter); @@ -192,7 +193,7 @@ private: int high_color, back_color; int background_color; int size, tsize, dirty; - int wlen, wsize, *positions, plen; + int wlen, wsize; char temp_string[KEYPRESSLEN]; int is_utf8; int active; diff --git a/cinelerra-5.1/guicast/bcwindowbase.h b/cinelerra-5.1/guicast/bcwindowbase.h index d06f062d..0bcad162 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.h +++ b/cinelerra-5.1/guicast/bcwindowbase.h @@ -397,8 +397,7 @@ public: BC_Pixmap *pixmap = 0, int is_utf8 = 0); void draw_xft_text(int x, int y, const wchar_t *text, int length, BC_Pixmap *pixmap); - void draw_wtext(int x, int y, const wchar_t *text, int length = -1, - BC_Pixmap *pixmap = 0, int *charpos = 0); + void draw_wtext(int x, int y, const wchar_t *text, int length = -1, BC_Pixmap *pixmap = 0); // truncate the text to a ... version that fits in the width, using the current_font void truncate_text(char *result, const char *text, int w); void draw_center_text(int x, int y, const char *text, int length = -1); @@ -573,7 +572,6 @@ private: int64_t get_color_bgr24(int color); XFontStruct* get_font_struct(int font); XftFont* get_xft_struct(int font); - int wcharpos(const wchar_t *text, XftFont *font, int length, int *charpos); Cursor get_cursor_struct(int cursor); XFontSet get_fontset(int font); XFontSet get_curr_fontset(void); diff --git a/cinelerra-5.1/guicast/bcwindowdraw.C b/cinelerra-5.1/guicast/bcwindowdraw.C index 52b7f837..61865c50 100644 --- a/cinelerra-5.1/guicast/bcwindowdraw.C +++ b/cinelerra-5.1/guicast/bcwindowdraw.C @@ -246,37 +246,6 @@ void BC_WindowBase::draw_xft_text(int x, int y, } } -int BC_WindowBase::wcharpos(const wchar_t *text, XftFont *font, int length, - int *charpos) -{ - XGlyphInfo extents; - - if(charpos) - { - int bpos = charpos[-1]; - - for(int i = 0; i < length; i++) - { - XftTextExtents32(top_level->display, - font, - (const FcChar32*)text, - i + 1, - &extents); - charpos[i] = extents.xOff + bpos; - } - return charpos[length - 1] - bpos; - } - else - { - XftTextExtents32(top_level->display, - font, - (const FcChar32*)text, - length, - &extents); - return extents.xOff; - } -} - void BC_WindowBase::xft_draw_string(XftColor *xft_color, XftFont *xft_font, int x, int y, const FcChar32 *fc, int len, BC_Pixmap *pixmap) { @@ -312,7 +281,7 @@ void BC_WindowBase::xft_draw_string(XftColor *xft_color, XftFont *xft_font, } void BC_WindowBase::draw_wtext(int x, int y, - const wchar_t *text, int length, BC_Pixmap *pixmap, int *charpos) + const wchar_t *text, int length, BC_Pixmap *pixmap) { if( !get_resources()->use_xft ) { if( !get_font_struct(current_font) ) return; @@ -329,15 +298,13 @@ void BC_WindowBase::draw_wtext(int x, int y, XRenderColor color; XftColor xft_color; const wchar_t *up, *ubp; - int l, *cp; + int l; FcPattern *newpat; XftFont *curfont, *nextfont, *altfont, *basefont; if(length < 0) length = wcslen(text); - if(charpos) - charpos[0] = 0; if(!length) return; @@ -359,7 +326,6 @@ void BC_WindowBase::draw_wtext(int x, int y, curfont = nextfont = basefont; altfont = 0; - cp = 0; ubp = text; for(up = text; up < &text[length]; up++) @@ -397,10 +363,11 @@ void BC_WindowBase::draw_wtext(int x, int y, xft_draw_string(&xft_color, curfont, x, y, (const FcChar32*)ubp, l, pixmap); - if(charpos) - cp = &charpos[ubp - text + 1]; + XGlyphInfo extents; + XftTextExtents32(top_level->display, curfont, + (const FcChar32*)ubp, l, &extents); + x += extents.xOff; - x += wcharpos(ubp, curfont, l, cp); ubp = up; curfont = nextfont; } @@ -410,8 +377,6 @@ void BC_WindowBase::draw_wtext(int x, int y, { xft_draw_string(&xft_color, curfont, x, y, (const FcChar32*)ubp, up - ubp, pixmap); - if(charpos) - wcharpos(ubp, curfont, up - ubp, &charpos[ubp - text + 1]); } if(altfont) diff --git a/cinelerra-5.1/plugins/titler/titler.C b/cinelerra-5.1/plugins/titler/titler.C index aa4619fb..67f88a96 100644 --- a/cinelerra-5.1/plugins/titler/titler.C +++ b/cinelerra-5.1/plugins/titler/titler.C @@ -2604,11 +2604,19 @@ void TitleMain::save_data(KeyFrame *keyframe) output.tag.set_property("LOOP_PLAYBACK", config.loop_playback); output.append_tag(); output.append_newline(); - char text[BCTEXTLEN]; + char text[2*sizeof(config.wtext)]; int text_len = BC_Resources::encode( BC_Resources::wide_encoding, DEFAULT_ENCODING, (char*)config.wtext, config.wlen*sizeof(wchar_t), text, sizeof(text)); + int len = output.length(), avail = MESSAGESIZE-16 - len; + if( text_len >= avail ) { // back off last utf8 char + text_len = avail; + while( text_len > 0 && (text[text_len-1] & 0xc0) == 0x80 ) + text[--text_len] = 0; + if( text_len > 0 ) + text[--text_len] = 0; + } output.append_text(text, text_len); output.tag.set_title("/TITLE"); output.append_tag(); diff --git a/cinelerra-5.1/plugins/titler/titler.h b/cinelerra-5.1/plugins/titler/titler.h index eff6db54..bca00765 100644 --- a/cinelerra-5.1/plugins/titler/titler.h +++ b/cinelerra-5.1/plugins/titler/titler.h @@ -156,7 +156,7 @@ public: double fade_in, fade_out; float pixels_per_second; // Speed of motion // Text to display - wchar_t wtext[BCTEXTLEN]; + wchar_t wtext[3*BCTEXTLEN]; int wlen; // Position in frame relative to top left float title_x, title_y; diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.C b/cinelerra-5.1/plugins/titler/titlerwindow.C index 66fb01db..d4414060 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.C +++ b/cinelerra-5.1/plugins/titler/titlerwindow.C @@ -101,6 +101,8 @@ TitleWindow::TitleWindow(TitleMain *client) fade_out = 0; text_title = 0; text = 0; + text_chars = 0; + text_bfrsz = 0; justify_title = 0; left = 0; center = 0; right = 0; top = 0; mid = 0; bottom = 0; @@ -383,6 +385,12 @@ void TitleWindow::create_objects() x = 10; add_tool(text_title = new BC_Title(x, y, _("Text:"))); + x += text_title->get_w() + 20; + int wid = BC_Title::calculate_w(this,"0")*10; + add_tool(text_chars = new TitleTextChars(x,y,wid)); + x += text_chars->get_w() + 20; + add_tool(text_bfrsz = new TitleTextBfrSz(x,y,wid)); + y += text_title->get_h() + margin; x = margin; text = new TitleText(client, this, x, y, get_w()-margin - x, get_h() - y - 10); @@ -670,6 +678,14 @@ void TitleWindow::update_justification() bottom->update(client->config.vjustification == JUSTIFY_BOTTOM); } +void TitleWindow::update_stats() +{ + text_chars->update(client->config.wlen); + int len = MESSAGESIZE-16 - strlen(text->get_text()); + if( len < 0 ) len = 0; + text_bfrsz->update(len); +} + void TitleWindow::update() { title_x->update((int64_t)client->config.title_x); @@ -707,6 +723,7 @@ void TitleWindow::update() } } update_justification(); + update_stats(); update_color(); } @@ -1051,9 +1068,37 @@ int TitleText::handle_event() wcsncpy(client->config.wtext, get_wtext(), len); client->config.wtext[len-1] = 0; client->config.wlen = wcslen(client->config.wtext); + window->update_stats(); client->send_configure_change(); return 1; } +TitleTextChars::TitleTextChars(int x, int y, int w) + : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w) +{ +} +TitleTextChars::~TitleTextChars() +{ +} +int TitleTextChars::update(int n) +{ + char text[BCSTRLEN]; + sprintf(text, _("chars: %d "),n); + return BC_Title::update(text, 0); +} + +TitleTextBfrSz::TitleTextBfrSz(int x, int y, int w) + : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w) +{ +} +TitleTextBfrSz::~TitleTextBfrSz() +{ +} +int TitleTextBfrSz::update(int n) +{ + char text[BCSTRLEN]; + sprintf(text, _("bfrsz: %d "),n); + return BC_Title::update(text, 0); +} TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y) diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.h b/cinelerra-5.1/plugins/titler/titlerwindow.h index 1088aa81..1f968301 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.h +++ b/cinelerra-5.1/plugins/titler/titlerwindow.h @@ -52,6 +52,8 @@ class TitleLinePitch; class TitleFade; class TitleFont; class TitleText; +class TitleTextChars; +class TitleTextBfrSz; class TitleX; class TitleY; class TitleW; @@ -89,6 +91,7 @@ public: int grab_event(XEvent *event); void update_color(); void update_justification(); + void update_stats(); void update(); void previous_font(); void next_font(); @@ -150,6 +153,8 @@ public: TitleFade *fade_out; BC_Title *text_title; TitleText *text; + TitleTextChars *text_chars; + TitleTextBfrSz *text_bfrsz; BC_Title *justify_title; TitleLeft *left; TitleCenter *center; @@ -351,6 +356,21 @@ public: TitleMain *client; TitleWindow *window; }; +class TitleTextChars : public BC_Title +{ +public: + int update(int n); + TitleTextChars(int x, int y, int w); + ~TitleTextChars(); +}; +class TitleTextBfrSz : public BC_Title +{ +public: + int update(int n); + TitleTextBfrSz(int x, int y, int w); + ~TitleTextBfrSz(); +}; + class TitleX : public BC_TumbleTextBox { public: