?? text.c
字號:
*nChar += wordLen; if (nCount == 0) break; if (*pText == '\t') { tabs ++; if (uFormat & DT_EXPANDTABS) { lineWidth += nTabWidth; gdi_start_new_line (pdc->pLogFont); } else lineWidth += gdi_width_one_char (pdc->pLogFont, pdc->pLogFont->sbc_devfont, pText, 1, &x, &y); pText ++; nCount --; } else if (*pText == '\n' || *pText == '\r') { (*nChar) ++; break; } else if (*pText == ' ') { lineWidth += gdi_width_one_char (pdc->pLogFont, pdc->pLogFont->sbc_devfont, pText, 1, &x, &y); (*nChar) ++; pText ++; nCount --; } } if (!(uFormat & DT_EXPANDTABS)) { *nChar += tabs; tabs = 0; } return tabs;}int DrawTextEx (HDC hdc, const char* pText, int nCount, RECT* pRect, int indent, UINT nFormat){ PDC pdc; int n, nLines = 0, width = 0; BOOL bOutput = TRUE; int x, y; RECT rcDraw, rcOutput; int nTabWidth, tabs; SIZE size; int line_height; pdc = dc_HDC2PDC(hdc); if (nCount == -1) nCount = strlen (pText); line_height = pdc->pLogFont->size + pdc->alExtra + pdc->blExtra; if (nFormat & DT_TABSTOP) nTabWidth = HIWORD (nFormat) * (*pdc->pLogFont->sbc_devfont->font_ops->get_ave_width) (pdc->pLogFont, pdc->pLogFont->sbc_devfont); else nTabWidth = pdc->tabstop * (*pdc->pLogFont->sbc_devfont->font_ops->get_ave_width) (pdc->pLogFont, pdc->pLogFont->sbc_devfont); // Transfer logical to device to screen here. rcDraw = *pRect; coor_LP2SP(pdc, &rcDraw.left, &rcDraw.top); coor_LP2SP(pdc, &rcDraw.right, &rcDraw.bottom); NormalizeRect (&rcDraw); if (dc_IsGeneralDC (pdc)) { LOCK (&pdc->pGCRInfo->lock); if (!dc_GenerateECRgn (pdc, FALSE)) bOutput = FALSE; }#ifdef _LITE_VERSION if (CHECK_DRAWING (pdc)) bOutput = FALSE;#endif // Draw text here. if (nFormat & DT_CALCRECT) bOutput = FALSE; y = rcDraw.top; if (nFormat & DT_SINGLELINE) { if (nFormat & DT_BOTTOM) y = rcDraw.bottom - pdc->pLogFont->size; else if (nFormat & DT_VCENTER) y = rcDraw.top + ((RECTH (rcDraw) - pdc->pLogFont->size) >> 1); } while (nCount != 0) { int nOutput; int maxwidth; if (nLines == 0) { maxwidth = rcDraw.right - rcDraw.left - indent; if (maxwidth <= 0) { // new line y += pdc->pLogFont->size; nLines ++; continue; } } else maxwidth = rcDraw.right - rcDraw.left; gdi_start_new_line (pdc->pLogFont); tabs = txtGetOneLine (pdc, pText, nCount, nTabWidth, maxwidth, nFormat, &n); gdi_get_TextOut_extent (pdc, pdc->pLogFont, pText, n, &size); width = size.cx + tabs * nTabWidth; n += tabs; if ( (pText[n-1] == '\n' || pText[n-1] == '\r') && !(nFormat & DT_SINGLELINE) ) { int tmpx = 0, tmpy = 0; nOutput = n - 1; width -= gdi_width_one_char (pdc->pLogFont, pdc->pLogFont->sbc_devfont, pText + n - 1, 1, &tmpx, &tmpy); } else nOutput = n; if (nFormat & DT_RIGHT) x = rcDraw.right - width; else if (nFormat & DT_CENTER) x = rcDraw.left + ((RECTW (rcDraw) - width) >> 1); else x = rcDraw.left; x += (nLines ? 0 : indent); rcOutput.left = x; rcOutput.top = y; rcOutput.right = rcOutput.left + width; rcOutput.bottom = rcOutput.top + line_height; if (nFormat & DT_CALCRECT) { if (nLines == 0) *pRect = rcOutput; else GetBoundRect (pRect, pRect, &rcOutput); } // draw one line if (bOutput && width > 0) { if (nFormat & DT_NOCLIP) txtDrawOneLine (pdc, pText, nOutput, x, y, &rcOutput, nFormat, nTabWidth); else { RECT rcClip; IntersectRect (&rcClip, &rcOutput, &rcDraw); txtDrawOneLine (pdc, pText, nOutput, x, y, &rcClip, nFormat, nTabWidth); } } pText += n; // new line y += line_height; nLines ++; // left characters nCount = nCount - n; } /* we are done, so release global clipping region */ UNLOCK_GCRINFO (pdc); if (nFormat & DT_CALCRECT) { coor_SP2LP (pdc, &pRect->left, &pRect->top); coor_SP2LP (pdc, &pRect->right, &pRect->bottom); } if (!(nFormat & DT_CALCRECT)) { // update text out position x += width; y -= line_height; coor_SP2LP (pdc, &x, &y); pdc->CurTextPos.x = x; pdc->CurTextPos.y = y; } return line_height * nLines;}/************************* Text parse support ********************************/int GUIAPI GetTextMCharInfo (PLOGFONT log_font, const char* mstr, int len, int* pos_chars){ DEVFONT* sbc_devfont = log_font->sbc_devfont; DEVFONT* mbc_devfont = log_font->mbc_devfont; int count = 0; int left_bytes = len; int len_cur_char; while (left_bytes) { if (pos_chars) pos_chars [count] = len - left_bytes; if (mbc_devfont) { len_cur_char = (*mbc_devfont->charset_ops->len_first_char) (mstr, left_bytes); if (len_cur_char != 0) { count ++; left_bytes -= len_cur_char; mstr += len_cur_char; continue; } } len_cur_char = (*sbc_devfont->charset_ops->len_first_char) (mstr, left_bytes); if (len_cur_char != 0) { count ++; left_bytes -= len_cur_char; mstr += len_cur_char; } } return count;}int GUIAPI GetTextWordInfo (PLOGFONT log_font, const char* mstr, int len, int* pos_words, WORDINFO* info_words){ DEVFONT* sbc_devfont = log_font->sbc_devfont; DEVFONT* mbc_devfont = log_font->mbc_devfont; WORDINFO word_info; int count = 0; int left_bytes = len; int mbc_sub_len, sbc_sub_len, word_len; while (left_bytes) { sbc_sub_len = left_bytes; if (mbc_devfont) { int mbc_pos; mbc_pos = (*mbc_devfont->charset_ops->pos_first_char) (mstr, left_bytes); if (mbc_pos == 0) { mbc_sub_len = (*mbc_devfont->charset_ops->len_first_substr) (mstr, left_bytes); while (mbc_sub_len) { (*mbc_devfont->charset_ops->get_next_word) (mstr, mbc_sub_len, &word_info); if (pos_words) pos_words [count] = len - left_bytes; if (info_words) memcpy (info_words + count, &word_info, sizeof (WORDINFO)); count ++; word_len = word_info.len + word_info.nr_delimiters; mbc_sub_len -= word_len; left_bytes -= word_len; mstr += word_len; } continue; } else if (mbc_pos > 0) sbc_sub_len = mbc_pos; } while (sbc_sub_len) { (*sbc_devfont->charset_ops->get_next_word) (mstr, sbc_sub_len, &word_info); if (pos_words) pos_words [count] = len - left_bytes; if (info_words) memcpy (info_words + count, &word_info, sizeof (WORDINFO)); count ++; word_len = word_info.len + word_info.nr_delimiters; sbc_sub_len -= word_len; left_bytes -= word_len; mstr += word_len; } } return count;}int GUIAPI GetFirstMCharLen (PLOGFONT log_font, const char* mstr, int len){ DEVFONT* sbc_devfont = log_font->sbc_devfont; DEVFONT* mbc_devfont = log_font->mbc_devfont; int len_cur_char = 0; if (mbc_devfont) { len_cur_char = (*mbc_devfont->charset_ops->len_first_char) (mstr, len); if (len_cur_char != 0) return len_cur_char; } len_cur_char = (*sbc_devfont->charset_ops->len_first_char) (mstr, len); if (len_cur_char != 0) return len_cur_char; return len_cur_char;}int GUIAPI GetFirstWord (PLOGFONT log_font, const char* mstr, int len, WORDINFO* word_info){ DEVFONT* sbc_devfont = log_font->sbc_devfont; DEVFONT* mbc_devfont = log_font->mbc_devfont; if (mbc_devfont) { int mbc_pos; mbc_pos = (*mbc_devfont->charset_ops->pos_first_char) (mstr, len); if (mbc_pos == 0) { len = (*mbc_devfont->charset_ops->len_first_substr) (mstr, len); (*mbc_devfont->charset_ops->get_next_word) (mstr, len, word_info); return word_info->len + word_info->nr_delimiters; } else if (mbc_pos > 0) len = mbc_pos; } (*sbc_devfont->charset_ops->get_next_word) (mstr, len, word_info); return word_info->len + word_info->nr_delimiters;}int GUIAPI GetTextExtentPoint (HDC hdc, const char* text, int len, int max_extent, int* fit_chars, int* pos_chars, int* dx_chars, SIZE* size){ PDC pdc = dc_HDC2PDC (hdc); LOGFONT* log_font = pdc->pLogFont; DEVFONT* sbc_devfont = log_font->sbc_devfont; DEVFONT* mbc_devfont = log_font->mbc_devfont; int len_cur_char, width_cur_char; int left_bytes = len; int char_count = 0; int x = 0, y = 0; gdi_start_new_line (log_font); size->cy = log_font->size + pdc->alExtra + pdc->blExtra; size->cx = 0; while (left_bytes) { if (pos_chars) pos_chars [char_count] = len - left_bytes; if (dx_chars) dx_chars [char_count] = size->cx; if (mbc_devfont && (len_cur_char = (*mbc_devfont->charset_ops->len_first_char) (text, left_bytes))) { width_cur_char = gdi_width_one_char (log_font, mbc_devfont, text, len_cur_char, &x, &y); } else { if ((len_cur_char = (*sbc_devfont->charset_ops->len_first_char) (text, left_bytes))) { width_cur_char = gdi_width_one_char (log_font, sbc_devfont, text, len_cur_char, &x, &y); } else break; } width_cur_char += pdc->cExtra; if (max_extent > 0 && (size->cx + width_cur_char) > max_extent) { goto ret; } char_count ++; size->cx += width_cur_char; left_bytes -= len_cur_char; text += len_cur_char; }ret: if (fit_chars) *fit_chars = char_count; return len - left_bytes;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -