Ticket #4885: osd_rtl.patch
File osd_rtl.patch, 11.9 KB (added by , 15 years ago) |
---|
-
mythtv/libs/libmythtv/osdlistbtntype.cpp
65 65 m_hmult = (hmult == 0.0f) ? 1.0f : hmult; 66 66 m_unbiasedarea = unbias(area, wmult, hmult); 67 67 m_unbiasedsize = unbias(levelsize, wmult, hmult); 68 if (gContext->GetLanguage()=="he") 69 m_isRtl = true; 70 else 71 m_isRtl = false; 68 72 } 69 73 70 74 OSDListTreeType::~OSDListTreeType() … … 74 78 delete *it; 75 79 } 76 80 81 void OSDListTreeType::SetRtl (bool isRtl) 82 { 83 /*** 84 m_isRtl = isRtl; 85 if (gContext->GetLanguage()=="he") 86 m_isRtl = true; 87 else 88 m_isRtl = false; 89 ***/ 90 } 91 77 92 void OSDListTreeType::Reinit(float wmult, float hmult) 78 93 { 79 94 m_wmult = (wmult == 0.0f) ? 1.0f : wmult; … … 140 155 { 141 156 QString levelname = QString("level%1").arg(i + 1); 142 157 QRect curlevelarea = m_levelsize; 143 curlevelarea.moveBy(m_totalarea.x(), m_totalarea.y()); 144 curlevelarea.moveBy((m_levelsize.width() + m_levelspacing) * i, 0); 145 158 159 // if we are left to right 160 if (false == m_isRtl) 161 { 162 curlevelarea.moveBy(m_totalarea.x(), m_totalarea.y()); 163 curlevelarea.moveBy((m_levelsize.width() + m_levelspacing) * i, 0); 164 } 165 166 // if we are right to left 167 else 168 { 169 curlevelarea.moveBy(m_totalarea.width(), m_totalarea.y()); 170 curlevelarea.moveBy( ((-1 - i) * m_levelsize.width()) - m_levelspacing,0); 171 } 146 172 OSDListBtnType *newlevel = new OSDListBtnType( 147 173 levelname, curlevelarea, m_wmult, m_hmult, true); 148 174 … … 214 240 GetLevel(m_levelnum)->MovePageDown(); 215 241 EnterItem(); 216 242 } 217 else if ( has_action("LEFT", actions) && (m_levelnum > 0))243 else if (!m_isRtl && has_action("LEFT", actions) && (m_levelnum > 0)) 218 244 { 245 219 246 GetLevel(m_levelnum)->Reset(); 220 247 GetLevel(m_levelnum)->SetVisible(false); 221 248 222 249 m_levelnum--; 223 250 EnterItem(); 224 251 } 225 else if ((has_action("LEFT", actions) && m_arrowAccel) || 252 253 else if (m_isRtl && has_action("LEFT",actions)) 254 { 255 // Right to left - left acts as select / advance one stage 256 if ((m_levelnum + 1 < m_depth) && 257 (currentpos->childCount() > 0)) 258 { 259 GetLevel(m_levelnum)->SetActive(false); 260 m_levelnum++; 261 262 FillLevelFromTree(currentpos, m_levelnum); 263 GetLevel(m_levelnum)->SetVisible(true); 264 EnterItem(); 265 } 266 else 267 { 268 SelectItem(); 269 } 270 } 271 else if ((!m_isRtl && has_action("LEFT", actions) && m_arrowAccel) || 226 272 has_action("ESCAPE", actions) || 227 273 has_action("CLEAROSD", actions) || 228 274 has_action("MENU", actions)) 229 275 { 230 276 m_visible = false; 231 277 } 232 else if ( has_action("RIGHT", actions) &&278 else if (!m_isRtl && has_action("RIGHT", actions) && 233 279 (m_levelnum + 1 < m_depth) && 234 280 (currentpos->childCount() > 0)) 235 281 { … … 240 286 GetLevel(m_levelnum)->SetVisible(true); 241 287 EnterItem(); 242 288 } 243 else if (( has_action("RIGHT", actions) && m_arrowAccel) ||289 else if ((!m_isRtl && has_action("RIGHT", actions) && m_arrowAccel) || 244 290 has_action("SELECT", actions)) 245 291 { 246 292 SelectItem(); 247 293 } 294 else if ((true ==m_isRtl) && has_action("RIGHT",actions) && (m_levelnum > 0)) 295 { 296 GetLevel(m_levelnum)->Reset(); 297 GetLevel(m_levelnum)->SetVisible(false); 298 299 m_levelnum--; 300 EnterItem(); 301 } 302 248 303 else 249 304 { 250 305 return false; … … 662 717 LoadPixmap(m_checkNonePix, "check-empty"); 663 718 LoadPixmap(m_checkHalfPix, "check-half"); 664 719 LoadPixmap(m_checkFullPix, "check-full"); 665 LoadPixmap(m_arrowPix, "arrow"); 720 if (gContext->GetLanguage()=="he") 721 LoadPixmap(m_arrowPix, "ltarrow"); 722 else 723 LoadPixmap(m_arrowPix, "arrow"); 666 724 667 725 uint itemWidth = (m_rect.width() + 1) & (~1); 668 726 … … 751 809 if (m_checkable) 752 810 m_checkRect = QRect(margin, (height - ch)/2, cw, ch); 753 811 754 if (m_showArrow) 755 m_arrowRect = QRect(width - aw - margin, (height - ah)/2, aw, ah); 812 if (m_showArrow) 813 if (gContext->GetLanguage() == "he") 814 m_arrowRect = QRect(m_parent->m_contentsRect.x() + margin, (height - ah)/2, aw, ah); 815 else 816 m_arrowRect = QRect(width - aw - margin, (height - ah)/2, aw, ah); 817 756 818 757 819 if (m_pixmap) 758 820 { … … 764 826 tx += (m_checkable) ? m_checkRect.width() + margin : 0; 765 827 tx += (m_pixmap) ? m_pixmapRect.width() + margin : 0; 766 828 tw -= (m_checkable) ? m_checkRect.width() + margin : 0; 829 767 830 tw -= (m_showArrow) ? m_arrowRect.width() + margin : 0; 831 832 if (gContext->GetLanguage()=="he") 833 tx += (m_showArrow) ? m_arrowRect.width() + margin : 0; 834 768 835 tw -= (m_pixmap) ? m_pixmapRect.width() + margin : 0; 769 836 m_textRect = QRect(tx, 0, tw, height); 770 837 -
mythtv/libs/libmythtv/ttfont.h
8 8 #include <qstring.h> 9 9 #include <qmap.h> 10 10 #include <qcolor.h> 11 11 #include <qmutex.h> 12 12 #include "config.h" 13 13 14 14 #ifdef HAVE_STDINT_H … … 67 67 int offset_y, int xstart, int ystart, int width, 68 68 int height, int alphamod, kTTF_Color k = kTTF_Normal); 69 69 bool cache_glyph(unsigned short c); 70 70 71 QString ConvertFromRtoL(const QString &text) const; 72 73 static QString BasicConvertFromRtoL(const QString &text); 74 75 76 71 77 bool valid; 72 78 FT_Library library; 73 79 FT_Face face; … … 104 110 int loadedfontsize; 105 111 float m_wscale; 106 112 float m_hmult; 113 114 mutable QMutex fribidi_lock; 115 mutable QTextCodec *codeci; 107 116 }; 108 117 109 118 #endif -
mythtv/libs/libmythtv/osdlistbtntype.h
108 108 bool HandleKeypress(QKeyEvent *e); 109 109 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff); 110 110 111 void SetRtl (bool isRtl); 112 111 113 signals: 112 114 void itemSelected(OSDListTreeType *parent, OSDGenericTree *item); 113 115 void itemEntered(OSDListTreeType *parent, OSDGenericTree *item); … … 151 153 int m_levelnum; 152 154 bool m_visible; 153 155 bool m_arrowAccel; 156 bool m_isRtl; 154 157 }; 155 158 156 159 class OSDListBtnType : public OSDType -
mythtv/libs/libmythtv/ttfont.cpp
21 21 22 22 #include <iostream> 23 23 24 #ifdef USING_FRIBIDI 25 #include "fribidi/fribidi.h" 26 #include <qtextcodec.h> 27 #endif // USING_FRIBIDI 28 24 29 using namespace std; 25 30 26 31 #include <cstdio> … … 30 35 31 36 #include "osdtypes.h" 32 37 #include "osdsurface.h" 38 #include "mythcontext.h" 33 39 34 40 static int have_library = 0; 35 41 static FT_Library the_library; … … 430 436 surface->pow_lut); 431 437 } 432 438 439 QString TTFFont::BasicConvertFromRtoL(const QString &text) 440 { 441 QStringList rtl_string_composer; 442 bool handle_rtl = false; 443 QChar prev_char; 444 445 // Handling Right-to-Left languages. 446 // Left-to-Right languages are not affected. 447 448 // first,we need to ignore all the spaces in the end of the string 449 int lastCharIdx = (int)text.length() - 1; 450 while (text[lastCharIdx].isSpace()) 451 lastCharIdx--; 452 for (int i = lastCharIdx; i >= 0; i--) 453 { 454 QChar::Direction text_dir = text[i].direction(); 455 if (text_dir != QChar::DirR && 456 text_dir != QChar::DirRLE && 457 text_dir != QChar::DirRLO) 458 { 459 if (handle_rtl || rtl_string_composer.empty()) 460 rtl_string_composer.append(QString()); 461 462 if (text[i].isSpace() && !prev_char.isNull() 463 && prev_char.isDigit() && handle_rtl) 464 rtl_string_composer.back().append(text[i]); 465 else 466 rtl_string_composer.back().prepend(text[i]); 467 468 prev_char = text[i]; 469 470 handle_rtl = false; 471 } 472 else 473 { 474 if (!handle_rtl) 475 { 476 rtl_string_composer.append(QString()); 477 handle_rtl = true; 478 prev_char = QChar(); 479 } 480 rtl_string_composer.back().append(text[i]); 481 } 482 } 483 484 QString output = rtl_string_composer.join(""); 485 486 // return QDeepCopy<QString>(output); 487 return output; 488 } 489 490 QString TTFFont::ConvertFromRtoL(const QString &text) const 491 { 492 QString output = BasicConvertFromRtoL(text); 493 // cout<< output; 494 #ifdef USING_FRIBIDI 495 cout<<"fribidi"; 496 QMutexLocker locker(&fribidi_lock); 497 if (!codeci) 498 codeci = QTextCodec::codecForName("utf8"); 499 500 if (!codeci) 501 return output; 502 503 QCString temp = codeci->fromUnicode(text); 504 505 FriBidiCharType base; 506 size_t len; 507 508 bool fribidi_flip_commas = true; 509 base = (fribidi_flip_commas) ? FRIBIDI_TYPE_ON : FRIBIDI_TYPE_L; 510 511 const char *ip = temp; 512 FriBidiChar logical[strlen(ip) + 1], visual[strlen(ip) + 1]; 513 514 int char_set_num = fribidi_parse_charset("UTF-8"); 515 516 len = fribidi_charset_to_unicode( 517 (FriBidiCharSet) char_set_num, (char *)ip, strlen(ip), logical); 518 519 bool log2vis = fribidi_log2vis( 520 logical, len, &base, visual, NULL, NULL, NULL); // output 521 522 if (log2vis) 523 len = fribidi_remove_bidi_marks(visual, len, NULL, NULL, NULL); 524 525 output = ""; 526 for (size_t i = 1; i < len ; i++) 527 output += QChar(visual[i]); 528 529 530 #endif // USING_FRIBIDI 531 532 return output; 533 } 534 535 433 536 void TTFFont::DrawString(OSDSurface *surface, int x, int y, 434 537 const QString &text, int maxx, int maxy, 435 538 int alphamod, bool double_size) … … 452 555 } 453 556 rmap = create_font_raster(w, h); 454 557 455 render_text(rmap, rtmp, text, &inx, &iny, double_size);558 render_text(rmap, rtmp, ConvertFromRtoL(text), &inx, &iny, double_size); 456 559 457 560 is_pixmap = 1; 458 561 … … 496 599 return; 497 600 } 498 601 602 if (gContext->GetLanguage()=="he") 603 { 604 x = maxx - width; 605 } 606 499 607 if (m_shadowxoff != 0 || m_shadowyoff != 0) 500 608 { 501 609 merge_text(surface, rmap, clipx, clipy, x + m_shadowxoff, 502 610 y + m_shadowyoff, width, height, alphamod, kTTF_Shadow); 503 611 } 504 612 613 614 505 615 if (m_outline) 506 616 { 507 617 merge_text(surface, rmap, clipx, clipy, x - 1, y - 1, width, height, … … 514 624 alphamod, kTTF_Outline); 515 625 } 516 626 627 517 628 merge_text(surface, rmap, clipx, clipy, x, y, width, height, alphamod); 518 629 519 630 destroy_font_raster(rmap); -
mythtv/libs/libmythtv/osd.cpp
1298 1298 uint grSelectedAlpha(255); 1299 1299 int spacing = 2; 1300 1300 int margin = 3; 1301 bool isRtl = false; 1301 1302 1302 1303 QString name = element.attribute("name", ""); 1303 1304 if (name.isNull() || name.isEmpty()) … … 1312 1313 QDomElement info = child.toElement(); 1313 1314 if (!info.isNull()) 1314 1315 { 1315 if (info.tagName() == "area") 1316 if (info.tagName() == "RTL") 1317 { 1318 if (getFirstText(info) == "yes") 1319 { 1320 isRtl = true; 1321 } 1322 else if (getFirstText(info) == "no") 1323 { 1324 isRtl = false; 1325 } 1326 } 1327 else if (info.tagName() == "area") 1316 1328 { 1317 1329 area = parseRect(getFirstText(info)); 1318 1330 normalizeRect(area); … … 1428 1440 lb->SetSpacing(spacing); 1429 1441 lb->SetMargin(margin); 1430 1442 1443 lb->SetRtl(isRtl); 1444 1431 1445 container->AddType(lb); 1432 1446 } 1433 1447