Merge #1023 into sdk602patch0626 from refs/changes/1023/head 1024/target/1
author胡传军 <1224667075@qq.com>
Thu, 26 Sep 2024 12:26:33 +0000 (12:26 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Thu, 26 Sep 2024 12:26:33 +0000 (12:26 +0000)
增加字符替换方法

* refs/changes/1023/head: (1 commits squashed)

  - 增加字符替换方法

Signed-off-by: aliyun8003852482 <1224667075@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1023
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h

index 5334328..5c5d51d 100644 (file)
@@ -1,5 +1,11 @@
 #include "uicomponents/UIComponents.h"
 #include <vector>
+#include  <string.h>
+#include <string>
+#include <iostream>
+#include "common/text.h"
+#include "common/typed_text.h"
+#include "font/ui_font.h"
 
 namespace OHOS
 {
@@ -843,4 +849,46 @@ namespace OHOS
         }
         return imageArray;
     }
+
+    void updata_char(char *str_,char *str,uint32_t max_len)
+    {
+        strcpy_s(str_,max_len,str);
+        uint32_t j = 0;
+        uint32_t letter = 0;
+        if (str == nullptr) {
+            return ;
+        }
+        while (str[j] != '\0') 
+        {
+            int i=j;
+            letter = TypedText::GetUTF8Next(str, j, j);
+            int len=j-i;
+            UIFont* fontEngine= UIFont::GetInstance();
+            GlyphPathData path;
+            if(!fontEngine->GetGlyphPathData(letter, 0, path))
+            {
+                printf("********************* letter%d %d %d not exist\r\n",i,j,letter);
+                char *buf= "□";
+                uint16_t buf_len=strlen(buf);
+                uint16_t offset =0;
+                int num=len/buf_len;
+                int mod_num=len%buf_len;
+                for(int x=0;x<num;x++)
+                {
+                    memcpy_s(&str_[i+offset],buf_len,buf,buf_len);
+                    offset+=buf_len;
+                }
+                if(mod_num!=0)
+                {
+                    for(int x=0;x<num;x++)
+                    {
+                        str_[i+offset]=' ';
+                        offset+=1;
+                    }
+                }
+            }
+        }
+        printf("%s\r\n",str_);
+    }
+   
 }
index 352021e..ca024b0 100644 (file)
@@ -301,6 +301,9 @@ namespace OHOS
      * @param id         资源文本 ID。
      */
     void SetLabelId(UILabel *&label, UIResourceTextId id);
+
+    void updata_char(char *str_,char *str,uint32_t max_len);
+
 #endif
 
 } // namespace OHOS