android - 在 C++ 中为 Android 应用程序编码 ASCII
问题描述
我有一些在我的 android 应用程序中使用的 C++ 代码。它接受一个字符串并将每个字符转换为这个ascii 表中的一个 int 。然后我基于此渲染正确的字形。它适用于我测试了一些不同的谷歌像素和三星手机的大多数设备,但是当我在 api 24 - 30 上的 3.3" WQVGA 模拟器中测试时,它无法正常工作。
我想我在这一切都错了。有没有更好的方法来做到这一点?我的代码有修复吗?
谢谢你的时间。
void text::drawtexthorizontal( double x, double y, int textheight, string textin)
{
int n = textin.length();
// declaring character array
char char_array[n + 1];
// copying the contents of the string to char array
strcpy(char_array, textin.c_str());
for (int i = 0; i < n; i++){
//get ascii or "extended" ascii index and store it in symbol
int symbol;
if( (char_array[i] & ( 1 << 7 )) >> 7 == 1){
if( (char_array[i] & ( 1 << 6 )) >> 6 == 1){
//comb takes 2 byte representation and returns an int between 128 and 255 corresponding to extended ascii
symbol = comb(int(char_array[i]),int(char_array[i+1]));
i++;
}
else{
symbol = comb(int(char_array[i+1]),int(char_array[i]));
i++;
}
}
else symbol = int(char_array[i]);
//render chars[symbol]
}
}
int text::comb( int n, int m){
/*https://naveenr.net/unicode-character-set-and-utf-8-utf-16-utf-32-encoding/ for 2 byte encoding*/
int a[8] = { 0 },b[8] = { 0 };;
int i,k=0;
for (i = 0; n > 0; i++) {
a[i] = n % 2;
n /= 2;
}
for (i = 0; m > 0; i++){
b[i] = m % 2;
m /= 2;
}
for (i = 4; i >=0 ; i--){
k = 10 * k + a[i];
}
for (i = 5; i >=0 ; i--){
k = 10 * k + b[i];
}
int dec_value = 0;
// Initializing base value to 1, i.e 2^0
int base = 1;
int temp = k;
while (temp) {
int last_digit = temp % 10;
temp = temp / 10;
dec_value += last_digit * base;
base = base * 2;
}
if(dec_value > 255) dec_value = 32;
return dec_value;
}
解决方案
推荐阅读
- magento2 - Magento 2 安装后不加载 css 或 js:升级
- asp.net - 带有身份的网络表单,需要迭代用户的角色
- reactjs - 如何使用 React.js 在 React.createElement() 中传递回调函数
- amazon-s3 - 如何配置 mlflow 跟踪服务的工件存储以使用 minio STS 生成的 acces_key、secret_key 和 session_token 连接到 minio S3
- php - 如何保存和更新可重复自定义字段的复选框
- r - R Shiny navbarPage中的静态图像(png)
- kubernetes - Prometheus /etc/config/prometheus.yml:Kubernetes 没有这样的文件或目录
- linq - 为什么 EF Core DbSet LINQ 找不到存在的值?
- xamarin.forms - Xamarin 表单:在外部应用程序中打开 PDF 文件
- vue.js - Vuejs 和 axios 的数组问题