汉字和英文的识别及左右括号的处理

int x = rectDraw.left;
  int y = rectDraw.top;
  //计算字符串的逻辑坐标的长度
  int m_lenofherz = strText.GetLength() * tm.tmAveCharWidth;
  int m_lenofvert = 0;//m_lenofherz:为字符横向显示字符时,字符的总宽度  m_lenofvert:为字符竖直显示时,字符的竖直高度
  //计算字符串逻辑坐标的高度
  for(int i=0;i<strText.GetLength();)
  {
   //if (strText & 0x80)   //字符集为Unicode时,汉字和英文字符都占一个字节
   //{//是汉字时,一次取两个字节
   // strTemp = strText.GetAt(i++);
   // strTemp += strText.GetAt(i++);  
   // m_lenofvert += tm.tmHeight;
   //}
   //else
   {//英文时,一次取一个字节
    strTemp += strText.GetAt(i++);  
    m_lenofvert += tm.tmHeight;
   }
  }
  if(m_lenofherz < abs(rectDraw.Width()))
  {
   pDC->SetTextAlign(TA_CENTER);
   pDC->TextOut(rectDraw.CenterPoint().x,rectDraw.CenterPoint().y,m_trackname); //             //道的名称
  }
  else
  {
   if(m_lenofvert<=abs(rectDraw.Height()))
   {
    y -= (abs(rectDraw.Height()) - m_lenofvert)/2;
   }
   strTemp = _T("");
   for(int i=0;i<strText.GetLength();)
   {
    //if (strText & 0x80) //字符集为Unicode时,汉字和英文字符都占一个字节
    //{//汉字
    // strTemp = strText.GetAt(i++);
    // strTemp += strText.GetAt(i++);
    // x = rectDraw.CenterPoint().x ;
    // pDC->TextOut(x, y, strTemp);
    // y -= tm.tmHeight;
    // CString m_s;
    // m_s.Format(_T("y %d/n,rectDraw.Height() %d/n,rectDraw.top %d/n,rectDraw.bottom %d/n,m_lenofvert %d/n"),y,rectDraw.Height(),rectDraw.top,rectDraw.bottom,m_lenofvert);
    // m_s +=strTemp;
    // AfxMessageBox(m_s);
    //}
    //else
    {
     strTemp+= strText.GetAt(i++);
     if (strTemp==_T("(")||strTemp==_T("("))
     {
      strTemp = _T("(");
      continue;
     }
     CString m_s = _T("");
     if((i)<=(strText.GetLength()-1))
     {
      m_s = strText.GetAt(i);
      if (m_s==_T(")")||m_s==_T(")"))
      {
       strTemp += _T(")");
       i++;
      }
      
     }
     x = rectDraw.CenterPoint().x ;
     pDC->TextOut(x, y, strTemp);
     y -= tm.tmHeight;
     strTemp = _T("");
    }
    
   }  
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值