368 | 368 |
virtual void RenderTextList(CDCHandle dc,
|
369 | 369 |
const vector<TextRenderingInfo> &display_list,
|
370 | 370 |
FONT_TYPE font_type) const {
|
371 | |
CreateRenderTargetIfNecessary();
|
372 | |
if (dc_render_target_ == nullptr) {
|
|
371 |
const size_t kMaxTrial = 3;
|
|
372 |
size_t trial = 0;
|
|
373 |
while (true) {
|
|
374 |
CreateRenderTargetIfNecessary();
|
|
375 |
if (dc_render_target_ == nullptr) {
|
|
376 |
// This is not a recoverable error.
|
|
377 |
return;
|
|
378 |
}
|
|
379 |
const HRESULT hr = RenderTextListImpl(dc, display_list, font_type);
|
|
380 |
if (hr == D2DERR_RECREATE_TARGET && trial < kMaxTrial) {
|
|
381 |
// This is a recoverable error just by recreating the render target.
|
|
382 |
dc_render_target_.Release();
|
|
383 |
++trial;
|
|
384 |
continue;
|
|
385 |
}
|
|
386 |
// For other error codes (including S_OK and S_FALSE), or if we exceed the
|
|
387 |
// maximum number of trials, we simply accept the result here.
|
373 | 388 |
return;
|
374 | 389 |
}
|
|
390 |
}
|
|
391 |
|
|
392 |
HRESULT RenderTextListImpl(CDCHandle dc,
|
|
393 |
const vector<TextRenderingInfo> &display_list,
|
|
394 |
FONT_TYPE font_type) const {
|
375 | 395 |
CRect total_rect;
|
376 | 396 |
for (const auto &item : display_list) {
|
377 | 397 |
const auto &item_rect = ToCRect(item.rect);
|
|
381 | 401 |
HRESULT hr = S_OK;
|
382 | 402 |
hr = dc_render_target_->BindDC(dc, &total_rect);
|
383 | 403 |
if (FAILED(hr)) {
|
384 | |
return;
|
|
404 |
return hr;
|
385 | 405 |
}
|
386 | 406 |
CComPtr<ID2D1SolidColorBrush> brush;
|
387 | 407 |
hr = dc_render_target_->CreateSolidColorBrush(
|
388 | 408 |
ToD2DColor(render_info_[font_type].color),
|
389 | 409 |
&brush);
|
390 | 410 |
if (FAILED(hr)) {
|
391 | |
return;
|
|
411 |
return hr;
|
392 | 412 |
}
|
393 | 413 |
D2D1_DRAW_TEXT_OPTIONS option = D2D1_DRAW_TEXT_OPTIONS_NONE;
|
394 | 414 |
if (SystemUtil::IsWindows8_1OrLater()) {
|
|
411 | 431 |
brush,
|
412 | 432 |
option);
|
413 | 433 |
}
|
414 | |
hr = dc_render_target_->EndDraw();
|
415 | |
if (hr == D2DERR_RECREATE_TARGET) {
|
416 | |
dc_render_target_.Release();
|
417 | |
}
|
|
434 |
return dc_render_target_->EndDraw();
|
418 | 435 |
}
|
419 | 436 |
|
420 | 437 |
Size MeasureStringImpl(FONT_TYPE font_type, const wstring &str,
|