Use character count api of mf
authorSoonmin Jung <sm0415.jung@samsung.com>
Mon, 10 Dec 2012 06:15:09 +0000 (15:15 +0900)
committerSoonmin Jung <sm0415.jung@samsung.com>
Mon, 10 Dec 2012 06:17:28 +0000 (15:17 +0900)
Change-Id: I7d407d2fa513440de412025b73732e6a9aec0040

composer/include/msg-ui-composer-body-page.h
composer/include/msg-ui-composer-common.h
composer/src/ui-composer/msg-ui-composer-body-callback.c
composer/src/ui-composer/msg-ui-composer-body-page.c
composer/src/ui-composer/msg-ui-composer-body.c
composer/src/ui-composer/msg-ui-composer-common.c

index ce76132..26f6d54 100755 (executable)
@@ -46,7 +46,8 @@ void msg_ui_composer_mms_body_clear(MSG_COMPOSER_VIEW_DATA_S *cd);
 COMPOSER_RETURN_TYPE_E msg_ui_composer_mms_body_remove_page(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Object *remove_page);
 
 void msg_ui_composer_body_info_area_update(MSG_COMPOSER_VIEW_DATA_S *cd);
-int msg_ui_composer_body_entry_char_count(void *data, const unsigned  char *body_ucs2_text, int ucs2_len, int *char_count);
+int msg_ui_composer_body_entry_char_count(void *data, const char *text, int *char_count, int *page_size);
+
 void msg_ui_composer_body_apply_font_size(MSG_COMPOSER_VIEW_DATA_S *cd, const char *font_sytle);
 
 #endif                         /* __MSG_UI_COMPOSER_BODY_PAGE_H_ */
index 24d4b19..c6dfaa9 100755 (executable)
@@ -69,7 +69,6 @@ COMPOSER_RETURN_TYPE_E msg_composer_common_get_image_in_video(const char *video_
 COMPOSER_RETURN_TYPE_E msg_ui_composer_common_get_file(MSG_COMPOSER_VIEW_DATA_S *cd, const char *src_file_path, char *dst_file_path, int size_dst_file_path);
 
 void msg_composer_entry_filter_remove_markup(void *data, Evas_Object *entry, char **text);
-int msg_ui_composer_convert_UTF8ToUCS2(unsigned char *pDestText, int maxLength, const char *pSrcText, int srcTextLen);
 void msg_ui_composer_common_tickernoti(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_TICKERNOTI_TYPE_E tickertype);
 void msg_composer_entry_filter_addimage(void *data, Evas_Object *entry, char **text);
 void msg_ui_composer_entry_imf_state_cb(void * data, Ecore_IMF_Context *ctx, int value);
index 9036538..9226297 100755 (executable)
@@ -669,9 +669,7 @@ void msg_ui_composer_body_entry_changed_cb(void *data, Evas_Object *obj, void *e
                page_data->text_info.encode = COMPOSER_CHAR_ENCODE_UNICODE;
                page_data->text_info.char_count = 0;
        } else {
-               unsigned char ucs2_text[COMPOSER_MMS_TEXT_MAX_CHAR*2] = {0,};
-               int ucs2_len = msg_ui_composer_convert_UTF8ToUCS2(ucs2_text, sizeof(ucs2_text), body_text, text_len);
-               page_data->text_info.encode = msg_ui_composer_body_entry_char_count(cd, ucs2_text, ucs2_len, &page_data->text_info.char_count);
+               page_data->text_info.encode = msg_ui_composer_body_entry_char_count(cd, (const char *)body_text, &page_data->text_info.char_count, &page_data->text_info.page_size);
        }
        g_free(body_text);
 
index f961e6d..339c33e 100755 (executable)
@@ -235,86 +235,65 @@ static int __msg_ui_composer_body_verify_region_order(MSG_COMPOSER_VIEW_DATA_S *
        return region_order;
 }
 
-int msg_ui_composer_body_entry_char_count(void *data, const unsigned char *body_ucs2_text, int ucs2_len, int *char_count)
+int msg_ui_composer_body_entry_char_count(void *data, const char *text, int *char_count, int *page_size)
 {
        D_ENTER;
+       D_MSG_RETVM_IF(data == NULL, -1, "param is NULL");
+       D_MSG_RETVM_IF(text == NULL, -1, "param is NULL");
+       D_MSG_RETVM_IF(char_count == NULL, -1, "param is NULL");
+       D_MSG_RETVM_IF(page_size == NULL, -1, "param is NULL");
+
+       MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
+       unsigned int text_size = 0;
+       unsigned int segment_size = 0;
+       int encoded_mode = 0;
+       int ret = MSG_SUCCESS;
+       COMPOSER_CHAR_ENCODE_E encode = COMPOSER_CHAR_ENCODE_MAX;
+
+       ret = msg_util_calculate_text_length(text, cd->encode_mode, &text_size, &segment_size, (msg_encode_type_t *)&encoded_mode);
+       D_MSG("encode_mode = %d, text_size = %d, segment_size = %d encoded_mode = %d", cd->encode_mode, text_size, segment_size, encoded_mode);
+
+       if (ret != MSG_SUCCESS) {
+               D_EMSG("msg_calculate_text_length is failed ret = %d", ret);
+       } else {
+               switch (cd->encode_mode) {
+               case MSG_ENCODE_GSM7BIT:
+                       *char_count = (int)text_size;
+                       *page_size = (int)segment_size;
 
-       if (!data || !body_ucs2_text) {
-               MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT, "[ASSERT] parameter is NULL POINTER !!!!");
-               return -1;
-       }
-
-       int src_len = ucs2_len;
-       int count = 0;
-       int dst_char_encode = COMPOSER_CHAR_ENCODE_MAX;
-       int i = 0;
-
-       unsigned char upperByte, lowerByte;
-       unsigned short eachChar;
-
-       for(i=0; i<src_len; i++) {
-
-               bool is_def_table = false;
-               bool is_ext_table = false;
-
-               upperByte = body_ucs2_text[i++];
-               lowerByte = body_ucs2_text[i];
+                       if (encoded_mode == MSG_ENCODE_GSM7BIT_ABNORMAL)
+                               encode = COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL;
+                       else
+                               encode = COMPOSER_CHAR_ENCODE_GSM7;
 
-               eachChar = (upperByte << 8) & 0xFF00;
-               eachChar = eachChar | lowerByte;
+                       break;
 
-               /* in the UTF8, "Enter (Line Feed)" expressed as a "PS"
-                but in the UNICODE_GSM7 pair table, "Enter" expressed as a "LF (0x0a)"
-                so we need to change PS (0x2029_UNICODE) to LF (0x000A_GSM7)
-               */
-               if (eachChar == 0x2029) {/*PS*/
-                       eachChar = 0x000A; /* change LF*/
-               }
+               case MSG_ENCODE_UCS2:
+                       *char_count = (int)text_size;
+                       *page_size = (int)segment_size;
+                       encode = COMPOSER_CHAR_ENCODE_UNICODE;
 
-               int j=0;
+                       break;
 
-               /* found char on default table*/
-               for(j=0; j<(sizeof(g_GSM7BitToUCS2)/sizeof(short)); j++) {
-                       if (eachChar == g_GSM7BitToUCS2[j]) {
-                               count++;
-                               is_def_table = true;
-                               break;
-                       }
-               }
+               case MSG_ENCODE_AUTO:
+                       *char_count = (int)text_size;
+                       *page_size = (int)segment_size;
 
-               /* found char on default ext table*/
-               if (is_def_table == false) {
-                       for(j=0; j<(sizeof(g_GSM7BitExtToUCS2)/sizeof(short)); j++) {
-                               if (eachChar == g_GSM7BitExtToUCS2[j] && eachChar != 0x0020) {
-                                       count += 2;
-                                       is_ext_table = true;
-                                       break;
-                               }
-                       }
-               }
+                       if (encoded_mode == MSG_ENCODE_GSM7BIT)
+                               encode = COMPOSER_CHAR_ENCODE_GSM7;
+                       else
+                               encode = COMPOSER_CHAR_ENCODE_UNICODE;
 
-               if (is_def_table || is_ext_table) {
-                       dst_char_encode = COMPOSER_CHAR_ENCODE_GSM7;
-                       continue;
-               } else {
-                       dst_char_encode = COMPOSER_CHAR_ENCODE_UNICODE;
                        break;
+
+               default:
+                       D_EMSG("unsupported encode mode %d", cd->encode_mode);
                }
-       }
 
-       if (dst_char_encode == COMPOSER_CHAR_ENCODE_GSM7 || dst_char_encode == COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL) {
-               MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "[DEBUG] dst_char_encode is COMPOSER_CHAR_ENCODE_GSM7");
-               // gsm7 char set
-               *char_count = count;
-       } else {
-               // unicode char set
-               MSG_UI_DEBUG(MSG_UI_LEVEL_DEBUG, "[DEBUG] dst_char_encode = COMPOSER_CHAR_ENCODE_UNICODE");
-               *char_count = ucs2_len / 2;
        }
 
-
        D_LEAVE;
-       return dst_char_encode;
+       return encode;
 }
 
 void msg_ui_composer_body_info_area_update(MSG_COMPOSER_VIEW_DATA_S *cd)
@@ -329,6 +308,7 @@ void msg_ui_composer_body_info_area_update(MSG_COMPOSER_VIEW_DATA_S *cd)
 
                int char_encode = page_data->text_info.encode;
                int char_count = page_data->text_info.char_count;
+               int page_size = page_data->text_info.page_size;
                int cms_page = 0;
                int cms_max_count = 0;
                int max_count = 0;
@@ -339,37 +319,24 @@ void msg_ui_composer_body_info_area_update(MSG_COMPOSER_VIEW_DATA_S *cd)
                        return;
                }
 
-               if (char_encode == COMPOSER_CHAR_ENCODE_UNICODE) {
-                       if (char_count > COMPOSER_SMS_UNICODE_MAX_LEN) {
-                               cms_page = char_count / COMPOSER_CMS_UNICODE_MAX_LEN;
+               if (char_encode == COMPOSER_CHAR_ENCODE_UNICODE ||
+                       char_encode == COMPOSER_CHAR_ENCODE_GSM7 ||
+                       char_encode == COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL) {
+                       if (char_count > page_size) {
+                               cms_page = char_count / page_size;
 
-                               if (!(char_count % COMPOSER_CMS_UNICODE_MAX_LEN))
+                               if (!(char_count % page_size))
                                        --cms_page;
 
                                if ((cms_page+1) >= cd->cms_max_page)
-                                       max_count = COMPOSER_CMS_UNICODE_MAX_LEN * cd->cms_max_page;
+                                       max_count = page_size * cd->cms_max_page;
                                else
-                                       max_count = COMPOSER_CMS_UNICODE_MAX_LEN * (cms_page+1);
+                                       max_count = page_size * (cms_page+1);
 
                        } else {
-                               max_count = COMPOSER_SMS_UNICODE_MAX_LEN;
+                               max_count = page_size;
                        }
-                       cms_max_count = COMPOSER_CMS_UNICODE_MAX_LEN * cd->cms_max_page;
-               } else if (char_encode == COMPOSER_CHAR_ENCODE_GSM7 || char_encode == COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL) {
-                       if (char_count > COMPOSER_SMS_GSM7_MAX_LEN) {
-                               cms_page = char_count / COMPOSER_CMS_GSM7_MAX_LEN;
-
-                               if (!(char_count % COMPOSER_CMS_GSM7_MAX_LEN))
-                                       --cms_page;
-
-                               if ((cms_page+1) >= cd->cms_max_page)
-                                       max_count = COMPOSER_CMS_GSM7_MAX_LEN * cd->cms_max_page;
-                               else
-                                       max_count = COMPOSER_CMS_GSM7_MAX_LEN * (cms_page+1);
-                       } else {
-                               max_count = COMPOSER_SMS_GSM7_MAX_LEN;
-                       }
-                       cms_max_count = COMPOSER_CMS_GSM7_MAX_LEN * cd->cms_max_page;
+                       cms_max_count = page_size * cd->cms_max_page;
                } else {
                        D_EMSG("Unknown character encode");
                        return;
@@ -377,6 +344,9 @@ void msg_ui_composer_body_info_area_update(MSG_COMPOSER_VIEW_DATA_S *cd)
 
                remaining_count = max_count - char_count;
 
+               if (char_encode == COMPOSER_CHAR_ENCODE_UNICODE)
+                       remaining_count /= 2;
+
                snprintf(count_str, sizeof(count_str), "%d/%d", remaining_count, cms_page+1);
 
                if (cd->ly_body_h >= COMPOSER_ENOUGH_TEXT_RENDERING_BODY_HEIGHT)
index cd20681..949f428 100755 (executable)
@@ -1232,24 +1232,24 @@ static bool __msg_ui_composer_is_mms_text(MSG_COMPOSER_VIEW_DATA_S *cd, Evas_Obj
                return false;
        }
 
-       int ucs2_len = 0;
        int char_count = 0;
        int cms_page = 0;
        int cms_max_count = 0;
        int char_encode = COMPOSER_CHAR_ENCODE_MAX;
+       int page_size = 0;
+
        char *body_text = elm_entry_markup_to_utf8(elm_entry_entry_get(entry));
-       unsigned char ucs2_text[COMPOSER_MMS_TEXT_MAX_CHAR * 2] = {0,};
 
        if (body_text == NULL){
                D_EMSG("no text on there")
                return false;
        }
 
-       ucs2_len = msg_ui_composer_convert_UTF8ToUCS2(ucs2_text, sizeof(ucs2_text), body_text, strlen(body_text));
+       char_encode = msg_ui_composer_body_entry_char_count(cd, (const char *)body_text, &char_count, &page_size);
+       D_MSG("cd->encode_mode = %d", cd->encode_mode);
+       D_MSG("encode = %d, text_size = %d, page_size = %d", char_encode, char_count, page_size);
        free(body_text);
 
-       char_encode = msg_ui_composer_body_entry_char_count(cd, ucs2_text, ucs2_len, &char_count);
-
        if (char_encode == COMPOSER_CHAR_ENCODE_UNICODE) {
                cms_max_count = COMPOSER_CMS_UNICODE_MAX_LEN * cd->cms_max_page;
        } else if (char_encode == COMPOSER_CHAR_ENCODE_GSM7 || char_encode == COMPOSER_CHAR_ENCODE_GSM7_ABNORMAL) {
index 7621822..f8535b1 100755 (executable)
@@ -1153,47 +1153,6 @@ msg_composer_entry_filter_remove_markup(void *data, Evas_Object *entry, char **t
        D_LEAVE;
 }
 
-int msg_ui_composer_convert_UTF8ToUCS2(unsigned char *pDestText, int maxLength, const char *pSrcText, int srcTextLen)
-{
-       D_ENTER;
-       int textLen = 0;
-       unsigned char *unicodeTemp = (unsigned char*)pDestText;
-
-       int ucs2Length = 0;
-       int remainedBuffer = maxLength;
-
-       if(maxLength == 0 || pSrcText == NULL || pDestText ==  NULL)
-       {
-               MSG_UI_DEBUG(MSG_UI_LEVEL_ASSERT,"[ASSERT]UTF8 to UCS2 Failed as text length is NULL \n");
-               return -1;
-       }
-
-       // null terminated string
-       if (srcTextLen == -1) {
-               textLen = strlen((char*)pSrcText);
-               srcTextLen = textLen;
-       } else {
-               textLen = srcTextLen;
-       }
-
-       GIConv cd;
-       int err=0;
-
-       cd = g_iconv_open("UCS-2BE", "UTF8");
-
-       if (cd > 0)
-       {
-               err = g_iconv(cd, (char**)&pSrcText, (gsize*)&textLen, (char**)&unicodeTemp, (gsize*)&remainedBuffer);
-       }
-
-       ucs2Length = maxLength - remainedBuffer;
-
-       g_iconv_close(cd);
-
-       D_LEAVE;
-       return ucs2Length;
-}
-
 void msg_ui_composer_common_tickernoti(MSG_COMPOSER_VIEW_DATA_S *cd, COMPOSER_TICKERNOTI_TYPE_E tickertype)
 {
        char popup_msg[DEF_BUF_LEN_L] = {0,};