qtextimagehandler.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextimagehandler.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5extern QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,-
6 qreal *sourceDevicePixelRatio);-
7static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePixelRatio,-
8 qreal *sourceDevicePixelRatio)-
9{-
10-
11-
12-
13-
14 if (url->isValid()
url->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
15 if (url->scheme() == QLatin1Literal("qrc")
url->scheme() ...Literal("qrc")Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
16 fileName = fileName.right(fileName.length() - 3);-
17 }
never executed: end of block
0
18 else if (url->scheme() == QLatin1Literal("file")
url->scheme() ...iteral("file")Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
19 fileName = url->toLocalFile();-
20 }
never executed: end of block
0
21 }
never executed: end of block
0
22-
23 if (targetDevicePixelRatio <= 1.0
targetDevicePixelRatio <= 1.0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
24 return
never executed: return fileName;
fileName;
never executed: return fileName;
0
25-
26-
27 return
never executed: return qt_findAtNxFile(fileName, targetDevicePixelRatio, sourceDevicePixelRatio);
qt_findAtNxFile(fileName, targetDevicePixelRatio, sourceDevicePixelRatio);
never executed: return qt_findAtNxFile(fileName, targetDevicePixelRatio, sourceDevicePixelRatio);
0
28}-
29-
30-
31static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, const qreal devicePixelRatio = 1.0)-
32{-
33 QPixmap pm;-
34-
35 QString name = format.name();-
36 if (name.startsWith(QLatin1String(":/"))
name.startsWit...1String(":/"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
37 name.prepend(QLatin1String("qrc"));
never executed: name.prepend(QLatin1String("qrc"));
0
38 QUrl url = QUrl(name);-
39 qreal sourcePixelRatio = 1.0;-
40 name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio);-
41 const QVariant data = doc->resource(QTextDocument::ImageResource, url);-
42 if (data.type() == QVariant::Pixmap
data.type() ==...ariant::PixmapDescription
TRUEnever evaluated
FALSEnever evaluated
|| data.type() == QVariant::Image
data.type() == QVariant::ImageDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
43 pm = qvariant_cast<QPixmap>(data);-
44 }
never executed: end of block
else if (data.type() == QVariant::ByteArray
data.type() ==...ant::ByteArrayDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
45 pm.loadFromData(data.toByteArray());-
46 }
never executed: end of block
0
47-
48 if (pm.isNull()
pm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
49 QImage img;-
50 if (name.isEmpty()
name.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| !img.load(name)
!img.load(name)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
51 return
never executed: return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
never executed: return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
0
52-
53 pm = QPixmap::fromImage(img);-
54 doc->addResource(QTextDocument::ImageResource, url, pm);-
55 }
never executed: end of block
0
56-
57 if (name.contains(QLatin1String("@2x"))
name.contains(...String("@2x"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
58 pm.setDevicePixelRatio(sourcePixelRatio);
never executed: pm.setDevicePixelRatio(sourcePixelRatio);
0
59-
60 return
never executed: return pm;
pm;
never executed: return pm;
0
61}-
62-
63static QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format)-
64{-
65 QPixmap pm;-
66-
67 const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth);-
68 const int width = qRound(format.width());-
69 const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight);-
70 const int height = qRound(format.height());-
71-
72 QSize size(width, height);-
73 if (!hasWidth
!hasWidthDescription
TRUEnever evaluated
FALSEnever evaluated
|| !hasHeight
!hasHeightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
74 pm = getPixmap(doc, format);-
75 const int pmWidth = pm.width() / pm.devicePixelRatio();-
76 const int pmHeight = pm.height() / pm.devicePixelRatio();-
77-
78 if (!hasWidth
!hasWidthDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
79 if (!hasHeight
!hasHeightDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
80 size.setWidth(pmWidth);
never executed: size.setWidth(pmWidth);
0
81 else-
82 size.setWidth(qRound(height * (pmWidth / (qreal) pmHeight)));
never executed: size.setWidth(qRound(height * (pmWidth / (qreal) pmHeight)));
0
83 }-
84 if (!hasHeight
!hasHeightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
85 if (!hasWidth
!hasWidthDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
86 size.setHeight(pmHeight);
never executed: size.setHeight(pmHeight);
0
87 else-
88 size.setHeight(qRound(width * (pmHeight / (qreal) pmWidth)));
never executed: size.setHeight(qRound(width * (pmHeight / (qreal) pmWidth)));
0
89 }-
90 }
never executed: end of block
0
91-
92 qreal scale = 1.0;-
93 QPaintDevice *pdev = doc->documentLayout()->paintDevice();-
94 if (pdev
pdevDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
95 if (pm.isNull()
pm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
96 pm = getPixmap(doc, format);
never executed: pm = getPixmap(doc, format);
0
97 if (!pm.isNull()
!pm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
98 scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
never executed: scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
0
99 }
never executed: end of block
0
100 size *= scale;-
101-
102 return
never executed: return size;
size;
never executed: return size;
0
103}-
104-
105static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const qreal devicePixelRatio = 1.0)-
106{-
107 QImage image;-
108-
109 QString name = format.name();-
110 if (name.startsWith(QLatin1String(":/"))
name.startsWit...1String(":/"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
111 name.prepend(QLatin1String("qrc"));
never executed: name.prepend(QLatin1String("qrc"));
0
112 QUrl url = QUrl(name);-
113 qreal sourcePixelRatio = 1.0;-
114 name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio);-
115 const QVariant data = doc->resource(QTextDocument::ImageResource, url);-
116 if (data.type() == QVariant::Image
data.type() == QVariant::ImageDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
117 image = qvariant_cast<QImage>(data);-
118 }
never executed: end of block
else if (data.type() == QVariant::ByteArray
data.type() ==...ant::ByteArrayDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
119 image.loadFromData(data.toByteArray());-
120 }
never executed: end of block
0
121-
122 if (image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
123 if (name.isEmpty()
name.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| !image.load(name)
!image.load(name)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
124 return
never executed: return QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
never executed: return QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
0
125-
126 doc->addResource(QTextDocument::ImageResource, url, image);-
127 }
never executed: end of block
0
128-
129 if (sourcePixelRatio != 1.0
sourcePixelRatio != 1.0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
130 image.setDevicePixelRatio(sourcePixelRatio);
never executed: image.setDevicePixelRatio(sourcePixelRatio);
0
131-
132 return
never executed: return image;
image;
never executed: return image;
0
133}-
134-
135static QSize getImageSize(QTextDocument *doc, const QTextImageFormat &format)-
136{-
137 QImage image;-
138-
139 const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth);-
140 const int width = qRound(format.width());-
141 const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight);-
142 const int height = qRound(format.height());-
143-
144 QSize size(width, height);-
145 if (!hasWidth
!hasWidthDescription
TRUEnever evaluated
FALSEnever evaluated
|| !hasHeight
!hasHeightDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
146 image = getImage(doc, format);-
147 if (!hasWidth
!hasWidthDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
148 size.setWidth(image.width() / image.devicePixelRatio());
never executed: size.setWidth(image.width() / image.devicePixelRatio());
0
149 if (!hasHeight
!hasHeightDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
150 size.setHeight(image.height() / image.devicePixelRatio());
never executed: size.setHeight(image.height() / image.devicePixelRatio());
0
151 }
never executed: end of block
0
152-
153 qreal scale = 1.0;-
154 QPaintDevice *pdev = doc->documentLayout()->paintDevice();-
155 if (pdev
pdevDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
156 if (image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
157 image = getImage(doc, format);
never executed: image = getImage(doc, format);
0
158 if (!image.isNull()
!image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
159 scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
never executed: scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
0
160 }
never executed: end of block
0
161 size *= scale;-
162-
163 return
never executed: return size;
size;
never executed: return size;
0
164}-
165-
166QTextImageHandler::QTextImageHandler(QObject *parent)-
167 : QObject(parent)-
168{-
169}
never executed: end of block
0
170-
171QSizeF QTextImageHandler::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)-
172{-
173 (void)posInDocument;-
174 const QTextImageFormat imageFormat = format.toImageFormat();-
175-
176 if (QCoreApplication::instance()->thread() != QThread::currentThread()
QCoreApplicati...urrentThread()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
177 return
never executed: return getImageSize(doc, imageFormat);
getImageSize(doc, imageFormat);
never executed: return getImageSize(doc, imageFormat);
0
178 return
never executed: return getPixmapSize(doc, imageFormat);
getPixmapSize(doc, imageFormat);
never executed: return getPixmapSize(doc, imageFormat);
0
179}-
180-
181QImage QTextImageHandler::image(QTextDocument *doc, const QTextImageFormat &imageFormat)-
182{-
183 ((!(doc != 0)) ? qt_assert("doc != 0",__FILE__,249) : qt_noop());-
184-
185 return
never executed: return getImage(doc, imageFormat);
getImage(doc, imageFormat);
never executed: return getImage(doc, imageFormat);
0
186}-
187-
188void QTextImageHandler::drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format)-
189{-
190 (void)posInDocument;-
191 const QTextImageFormat imageFormat = format.toImageFormat();-
192-
193 if (QCoreApplication::instance()->thread() != QThread::currentThread()
QCoreApplicati...urrentThread()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
194 const QImage image = getImage(doc, imageFormat, p->device()->devicePixelRatioF());-
195 p->drawImage(rect, image, image.rect());-
196 }
never executed: end of block
else {
0
197 const QPixmap pixmap = getPixmap(doc, imageFormat, p->device()->devicePixelRatioF());-
198 p->drawPixmap(rect, pixmap, pixmap.rect());-
199 }
never executed: end of block
0
200}-
201-
202-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9