| 697 | }; |
| 698 | |
| 699 | CSize DrawText(CDC* pDC, CRect rect, const CString& str, LOGFONT font, BOOL bCalculate = FALSE) |
| 700 | { |
| 701 | CSize sz(0, 0); |
| 702 | |
| 703 | if (str.IsEmpty()) |
| 704 | return sz; |
| 705 | |
| 706 | CPoint pt = rect.TopLeft(); |
| 707 | CPoint ptCur = pt; |
| 708 | |
| 709 | LOGFONT lf; |
| 710 | memcpy(&lf, &font, sizeof(LOGFONT)); |
| 711 | |
| 712 | CFont tempFont; |
| 713 | tempFont.CreateFontIndirect(&lf); |
| 714 | |
| 715 | CFont* pOldFont = pDC->SelectObject(&tempFont); |
| 716 | |
| 717 | TEXTMETRIC textMetric; |
| 718 | pDC->GetTextMetrics(&textMetric); |
| 719 | int nHeight = textMetric.tmHeight; |
| 720 | int nWidth = textMetric.tmAveCharWidth; |
| 721 | |
| 722 | CString strText; |
| 723 | |
| 724 | //iterate through all characters of the string |
| 725 | for (int i = 0; i <= str.GetLength(); ++i) |
| 726 | { |
| 727 | Command nCmd = Command::None; |
| 728 | if (i < str.GetLength()) |
| 729 | { |
| 730 | switch (str.GetAt(i)) |
| 731 | { |
| 732 | case L'\n': |
| 733 | nCmd = Command::NewLine; |
| 734 | break; |
| 735 | case L'\t': |
| 736 | nCmd = Command::Tabulation; |
| 737 | break; |
| 738 | case L'\r': |
| 739 | break; |
| 740 | default: |
| 741 | strText += str.GetAt(i); |
| 742 | break; |
| 743 | } |
| 744 | } |
| 745 | else // Immitates new line at the end of the string |
| 746 | nCmd = Command::NewLine; |
| 747 | |
| 748 | if (nCmd != Command::None) |
| 749 | { |
| 750 | if (!strText.IsEmpty()) |
| 751 | { |
| 752 | if (!bCalculate) |
| 753 | pDC->TextOut(ptCur.x, ptCur.y, strText); |
| 754 | CSize s = pDC->GetTextExtent(strText); |
| 755 | ptCur.x += s.cx; |
| 756 | strText.Empty(); |
no test coverage detected