增加字符替换方法 1023/1 1023/head
authorhcj <1224667075@qq.com>
Thu, 26 Sep 2024 12:22:15 +0000 (20:22 +0800)
committerhcj <1224667075@qq.com>
Thu, 26 Sep 2024 12:22:15 +0000 (20:22 +0800)
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