Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Text Layout with Qt
Search
Jiang Jiang
December 12, 2011
Technology
180
2
Share
Text Layout with Qt
A talk presented in Chinese about the text layout support in Qt framework.
Jiang Jiang
December 12, 2011
More Decks by Jiang Jiang
See All by Jiang Jiang
Vertical Text Layout For Qt
jjgod
1
1.1k
Other Decks in Technology
See All in Technology
ServiceによるKubernetes通信制御ーClusterIPを例に
miku01
1
150
20260428_Product Management Summit_Loglass_JoeHirose
loglassjoe
4
7.3k
サンプリングは「作る」のか「使う」のか? 分散トレースのコストと運用を両立する実践的戦略 / Why you need the tail sampling and why you don't want it
ymotongpoo
3
120
Fabric MCPの紹介と使い分け
ryomaru0825
1
150
もっとコンテンツをよく構造化して理解したいので、LLM 時代こそ Taxonomy の設計品質に目を向けたい〜!
morinota
0
200
Percolatorを廃止し、マルチ検索サービスへ刷新した話 / Search Engineering Tech Talk 2026 Spring
visional_engineering_and_design
0
330
ハーネスエンジニアリング入門
hatyibei
0
110
クラウドネイティブ DB はいかにして制約を 克服したか? 〜進化歴史から紐解く、スケーラブルアーキテクチャ設計指針〜
hacomono
PRO
3
280
The 7 pitfalls of AI
ufried
0
200
20260428_Product Management Summit_tadokoroyoshiro
tadokoro_yoshiro
15
18k
Oracle Cloud Infrastructure presents managed, serverless MCP Servers for Oracle AI Database
thatjeffsmith
0
110
Vision Banana: Image Generators are Generalist Vision Learners
kzykmyzw
0
310
Featured
See All Featured
The Invisible Side of Design
smashingmag
302
52k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
The SEO Collaboration Effect
kristinabergwall1
1
440
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
380
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
200
Docker and Python
trallard
47
3.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Paper Plane
katiecoart
PRO
1
49k
WCS-LA-2024
lcolladotor
0
570
Optimizing for Happiness
mojombo
378
71k
Transcript
5FYU3FOEFSJOHXJUI2U 2U֥໓Чᛴಙඌ ࡾࡿ KJBOHKJBOH!OPLJBDPN
ܱႿ Ֆᇏ॓ჽ࠹ෘ෮иြၛުđᄝ/PLJB ύථ֥2Uྙቆ۽ቔਔ၂୍϶Ġ ༟ߋ࣮۲ᇕ໓Чᛴಙඌđູ2U षؿؓႋۿିĠ ಣιႪ֥ሳุބஆϱĠι॓ߘཬ ඪaҕაषჷཛଢb • •
•
ݺ2U
ᄸહႨ2UϜᛴಙ֞ଞഈĤ
QLabel QLabel
QTextEdit/QLineEdit QTextEdit/QLineEdit
2.-5FYU&MFNFOU
TextEdit/TextInput
)5.-JO28FC7JFX
QPainter::drawText QPainter::drawText
ߎႵ۷ਲࠃི֥ۚٚمગĤ
߶ਔࢳ֞હĤ Ֆ໓Чࢳ༅֞ཁൕཞ֥ಆݖӱ 2U૫෮Ⴕཁൕ໓Ч֥ٚمđૌ֥Ⴊׄ ಌׄđൡႨٓຶ 2Uᄝ۲۱༯൞ᄸဢൌགྷؓႋۿି֥ • • •
E4BDA0E5A5BD5174 E4BDA0E5A5BD5174
E4BDA0 E5A5BD 51 74 E4BDA0 E5A5BD 51 74
65' U+4F60 U+597D U+0051 U+0074 U+4F60 U+597D U+0051 U+0074
ݺ2U 6 ' 6 % 6 6
QString::fromUtf8(" QString::fromUtf8("Qt") Qt")
ఃщĤ QTextCodec *codec = QTextCodec::codecForName("GB18030-0"); QString str = codec->toUnicode("...");
ଽ҆ൌགྷཬᆩ് 24USJOHଽ҆Ⴈ65'-&Ќթሳژ Աđؓႋ2$IBS֥ਙđૄ۱2$IBS൞ ၂۱65'-&սׄ ᄝ6OJDPEF#.1ၛຓ֥ նਈܞࠡᇏ֥ ݱሳ Ⴈਆ۱৵࿃֥2$IBSіൕ ބ8JOEPXT.BD049֩ӈ༢֥ჰ
ള"1*၂ᇁđॖၛᆰࢤሇߐ • • •
໓Чᛴಙ֥ݖӱ ሳژіղ ሳุྐ༏ ሳุ ሳྙა໊ ᇂྐ༏ ஆϱႄౣ ሳุࢳ༅ ሳุ९
ܻᅅ߄
ሳุ
Arial Times Verdana Nokia Pure Text
Nokia Sans
ሳุ९
ሳุ९֥թԥ໊ᇂ 4ZTUFN-JCSBSZ'POUT -JCSBSZ'POUT _-JCSBSZ'POUT $=8JOEPXT='POUT VTSTIBSFGPOUT _GPOUT
ೂޅ๙ݖӱ٠໙ሳุ९Ĥ
ჰള֥ሳุܵ &OVN'POU'BNJMJFT %8SJUF'POU$PMMFDUJPO "QQMF5ZQF4FSWJDFT $5'POU$PMMFDUJPO.BOBHFS GPOUDPOGJH
ॴሳุܵ 2'POU 2'POU%BUBCBTF
࿊ᄴ၂۱ሳุ QFont f("Helvetica"); f.setWeight(QFont::Bold); f.setStyle(QFont::StyleOblique); Helvetica Bold Oblique
ਙԛॖ࿊ሳุ QFontDatabase db; QStringList families = db.families(); for (int
i; i < families.size(); i++) qDebug() << families[i] << db.styles(families[i]); Arial (Bold, Regular, Oblique, Bold Oblique) Heiti SC (Light, Medium) ...
໓Чᛴಙ֥ݖӱ ሳژіղ ሳุྐ༏ ሳุ ሳྙა໊ ᇂྐ༏ ஆϱႄౣ ሳุࢳ༅ ሳุ९
ܻᅅ߄
ሳุ֥ࢳ༅
$."1
$."1 ሳژ DIBSBDUFS ሳྙ෬ႄ HMZQI 6 ' 6
% 6 6
ሳྙক
ଽ҆ൌགྷཬᆩ് .BD 9 8JOEPXT ሳุ९ "54 $PSF5FYU GPOUDPOGJH
(%* %JSFDU8SJUF ሳุᄛೆ $PSF5FYU 'SFF5ZQF
໊ᇂ࠹ෘ
ሳए GPOUNFUSJDT
HMZQINFUSJDT QFontMetrics:: boundingRect(ch)
2'POU.FUSJDT QFont f("STHeiti"); QFontMetrics m(f); QString str = QString::fromUtf8("Qt");
m.boundingRect(str); m.height(); m.ascent(); m.descent(); ... ၂ࠆ౼ ሳएྐ༏ ֥ٚൔ
ݺ2U֥एྐ༏ ሳژ ሳྙ෬ႄ BEWBODF QY ჰ໊ׄᇂ ࡌഡ ູఏׄ
ݺ 2 U
໓Чᛴಙ֥ݖӱ ሳژіղ ሳุྐ༏ ሳุ ሳྙა໊ ᇂྐ༏ ஆϱႄౣ ሳุࢳ༅ ሳุ९
ܻᅅ߄
҃अ࠹ෘߎླေॉ੮
ࡗएטᆜ LFSOJOH ৵ሳ MJHBUVSF ูߐሳྙ
ൗࢸ۲ֹ֥ཿ༢
2UႨ֥ॴஆϱႄౣ )BSG#V[[ ऎุൌགྷ༥ࢫ൞ؓ2Uӱჴૼ֥
ࡼሳྙকሇߐູཞ SBTUFSJ[BUJPO ܻᅅ߄
ᛴಙิൕ IJOUJOH ҂Ⴈ WFSUJDBM IJOUJOH
QFont::setHintingPreference PreferDefaultHinting PreferNoHinting PreferVerticalHinting PreferFullHinting
ᄝၛ༯ݖӱᇏປӮ QPainter::drawText {QLabel/QTextEdit/QLineEdit}::paint QPainter::drawStaticText QTextLayout::draw QPainter::drawGlyphRun • • •
• •
ଽ҆ൌགྷཬᆩ് 2Uᄝ҂༯ิ܂ჰള֥ሳุᛴಙğ 8JOEPXT༯Ⴈ(%*%JSFDU8SJUF .BD049༯Ⴈ$PSF(SBQIJDT 9༯Ⴈ'SFF5ZQF ؓႿնႿQY֥ሳุđႨ21BJOUFSᆰ ࢤᛴಙ൏ਈক 2U༯ᆦӻEJTUBODFGJFMEᛴಙ •
– – – • •
໓Чᛴಙ֥ݖӱཬࢲ ሳژіղ ሳุྐ༏ ሳุ ሳྙა໊ ᇂྐ༏ ஆϱႄౣ ሳุࢳ༅ ሳุ९
ܻᅅ߄
2Uሳุ༢ࡏܒ 'POU3FOEFSFS %JTUBODF'JFME /BUJWF '5 $( (%* %8 -BZPVU&OHJOF)BSG#V[[
1MBUGPSN'POU%BUBCBTF CBTJD GPOUDPOGJH DPSFUFYU XJOEPXT
۲༯֥2Uൌགྷཬࢲ .BD 9 8JOEPXT 21" ሳุ९ "54 $PSF5FYU GPOUDPOGJH
(%* %JSFDU8SJUF CBTJD GPOUDPOGJH DPSFUFYU ሳุᄛೆ $PSF5FYU 'SFF5ZQF 'SFF5ZQF $PSF5FYU ஆϱ $PSF5FYU )BSG#V[[ )BSG#V[[ ᛴಙ $PSF5FYU 'SFF5ZQF (%* %JSFDU8SJUF %JTUBODF 'JFME /BUJWF
Ⴈ2Uᇅ໓Ч֥۲ᇕٚൔ
2.-5FYUჭ Text { text: "Qt" font.family: "STHeiti" font.pointSize: 24
color: "red" }
໓Ч॥ࡱ 2-BCFM 2-JOF&EJU 25FYU&EJU
QTextEdit textEdit(str); textEdit.document()->setDefaultFont(f); textEdit.show(); QLineEdit lineEdit(str); lineEdit.setFont(f); lineEdit.show(); QString
str = QString::fromUtf8("Qt"); QFont f("STHeiti"); QLabel label(str); label.setFont(f); label.show();
21BJOUFSESBX5FYU
ESBX5FYU֥ҕඔ ݺ2U ໓Чჰׄ ຓॿ ؓఊ
ૄՑေᇗྍ҃अđིੱ҂ۚ
class MyWidget: public QWidget { public: MyWidget(QWidget *parent =
0) : QWidget(parent) protected: void paintEvent(QPaintEvent *) { QPainter painter(this); painter.setFont(QFont("STHeiti")); painter.drawText(50, 50, QString::fromUtf8("Qt")); } };
24UBUJD5FYU 2U
ߏթ҃अྐ༏ၛิۚᇗ؇
҂ߏթᛴಙުཞၛࢫസଽթ
ྟିбࢠ _ _ _
24UBUJD5FYUൡކᄝଽթႵཋ֥ ഡСഈླေّگᇗ֥ࢸ૫ჭ
class MyWidget: public QWidget { public: MyWidget(QWidget *parent =
0) : QWidget(parent), m_staticText(QString::fromUtf8("Qt")) protected: void paintEvent(QPaintEvent *) { QPainter painter(this); painter.setFont(QFont("STHeiti")); painter.drawStaticText(50, 50, m_staticText); } private: QStaticText m_staticText; };
25FYU-BZPVU
ӈ֥໓Чஆϱଆൔ
ֆণ
؟ণ
໓Чߌಡ
҂ܿᄵྙሑ
25FYU-BZPVUᄍྸ॥ᇅૄྛ ໓Ч໊֥ᇂaэߐ࢘؇აྙሑ
QFont f("STHeiti"); QFontMetrics fontMetrics(f); QTextLayout textLayout(QString::fromUtf8("Qt"), f); int leading
= fontMetrics.leading(); qreal height = 0; textLayout.beginLayout(); while (1) { QTextLine line = textLayout.createLine(); if (!line.isValid()) break; line.setLineWidth(lineWidth); height += leading; line.setPosition(QPointF(0, height)); height += line.height(); } textLayout.endLayout(); QPainter p(this); textLayout.draw(&p, QPointF(50, 50));
ቋָҪğ23BX'POU 2(MZQI3VO
2'POUWT23BX'POU
2'POUሳุ࿊ᄴ౨֥ࠢކ
2'POU Ⴈğ ေ7FSEBOBሳุቂ ေุོ ေՙุ ༢ğ ቋᆃ۱౨֥ሳุ൞ "/Library/Fonts/Verdana Bold
Italic.ttf" • – – – • –
23BX'POU࿊ק֥ൌ࠽ሳุ
2(MZQI3VO ၂۱23BX'POU ؟ؓ ሳྙ෬ႄ ໊ᇂ
ႨႿླေᆰࢤߏթᇅሳྙൈğ 2U8FC,JUބ2.-4DFOF(SBQI
QFont f("Nokia Pure Text"); QFontMetrics fontMetrics(f); QTextLayout textLayout(QString::fromUtf8("Qt"), f);
... textLayout.endLayout(); // QGlyphRun QList<QGlyphRun> glyphRuns = textLayout.glyphRuns(); QPainter p(this); // STHeiti "" p.drawGlyphRun(QPointF(50, 50), glyphRuns[0]); // Nokia Pure Text "Qt" p.drawGlyphRun(QPointF(50, 50), glyphRuns[1]);
ીႵ௴ൡ֥໓ЧᛴಙٚمĆ
۴ऌႋႨླ࿊ᄴކൡ֥ٚم ߋ႒࿃ิ໙
ҕॉ໓֖ 4UBUFPG5FYU3FOEFSJOHCZ#FIEBE&TGBICPE IUUQCFIEBEPSHUFYU ໓Чᛴಙඌ֥၂Ց؋੪ྛCZ+JBOH+JBOH IUUQKKHPEPSHEPDTTMJEFTUFYUSFOEFSJOHUFDIQEG %JTUBODF'JFMEሳุᛴಙඌࢺകCZ:PBOO-PQFT IUUQMBCTRUOPLJBDPNUFYUSFOEFSJOHJOUIF RNMTDFOFHSBQI 23BX'POUა2(MZQI3VOࢺകCZ&TLJM"CSBIBNTFO#MPNGFMEU IUUQMBCTRUOPLJBDPNIJOUIJOUOVEHFOVEHF
TBZOPNPSF 24UBUJD5FYUࢺകCZ&TLJM"CSBIBNTFO IUUQMBCTRUOPLJBDPNJOTBOJUZJTTIBQJOHUIF TBNFUFYUBHBJOBOEFYQFDUJOHBEJGGFSFOUSFTVMU • • • • •
໙ีĤ