MCPcopy Create free account
hub / github.com/KikoPlayProject/KikoPlay / createImage

Method createImage

Play/Danmu/Render/cacheworker.cpp:162–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162void CacheWorker::createImage(CacheMiddleInfo &midInfo)
163{
164 DanmuComment *comment=midInfo.comment;
165 QFont danmuFont(this->danmuFont);
166 if(danmuStyle->randomSize)
167 {
168 danmuFont.setPointSize(QRandomGenerator::global()->
169 bounded(danmuStyle->fontSizeTable[DanmuComment::FontSizeLevel::Small],
170 danmuStyle->fontSizeTable[DanmuComment::FontSizeLevel::Large]));
171 }
172 else if(comment->mergedList && danmuStyle->enlargeMerged)
173 {
174 float enlargeRate(qBound(1.f,log2f(comment->mergedList->count()+1)/2,2.5f));
175 danmuFont.setPointSize(danmuStyle->fontSizeTable[DanmuComment::FontSizeLevel::Normal]*enlargeRate);
176 }
177 else
178 {
179 danmuFont.setPointSize(danmuStyle->fontSizeTable[comment->fontSizeLevel]);
180 }
181 QFontMetrics metrics(danmuFont);
182 QPen danmuStrokePen;
183 danmuStrokePen.setWidthF(danmuStyle->strokeWidth);
184 int strokeWidth=danmuStyle->strokeWidth;
185 int left=qAbs(metrics.leftBearing(comment->text.front()));
186
187 QSize textSize;
188 int pointSize=danmuFont.pointSize();
189 int minPointSize=pointSize/2;
190 //If the width is greater than 2048, then adjust the font size
191 //but the font size cannot be less than half of the previous point size
192 do
193 {
194 danmuFont.setPointSize(pointSize--);
195 QFontMetrics tMetrice(danmuFont);
196 textSize = tMetrice.size(0, comment->text);
197 metrics.swap(tMetrice);
198 }while(textSize.width()>2048 && pointSize>minPointSize);
199
200 QSize imgSize=textSize+QSize(strokeWidth*2+left,strokeWidth);
201 int mergeCountWidth=0;
202 if(comment->mergedList && danmuStyle->mergeCountPos>0)
203 {
204 QFont tmpFont(danmuFont);
205 tmpFont.setPointSize(tmpFont.pointSize()/2);
206 QFontMetrics metrics(tmpFont);
207 mergeCountWidth=metrics.size(0,QString("[%1]").arg(comment->mergedList->count())).width();
208 imgSize.rwidth()+=mergeCountWidth;
209 }
210 if(imgSize.width()>2048)imgSize.rwidth()=2048;
211 if(imgSize.height()>2048)imgSize.rheight()=2048;
212
213 DanmuDrawInfo *drawInfo=new DanmuDrawInfo;
214 drawInfo->useCount = 0;
215 drawInfo->cacheFlag = false;
216 drawInfo->height=imgSize.height();
217 drawInfo->width=imgSize.width();
218 //drawInfo->img=img;
219

Callers

nothing calls this directly

Calls 8

QStringClass · 0.85
QColorClass · 0.85
countMethod · 0.80
swapMethod · 0.80
splitMethod · 0.80
sizeMethod · 0.45
setColorMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected