void Font::Create(const FontParameters &fp) { Release(); // The minus one is done because since Scintilla uses SC_CHARSET_DEFAULT // internally and we need to have wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT // so we adjust the encoding before passing it to Scintilla. See also // wxStyledTextCtrl::StyleSetCharacterSet wxFontEncoding encoding = (wxFontEncoding)(fp.characterSet-1); wxFontEncodingArray ea = wxEncodingConverter::GetPlatformEquivalents(encoding); if (ea.GetCount()) encoding = ea[0]; wxFontWeight weight; if (fp.weight <= 300) weight = wxFONTWEIGHT_LIGHT; else if (fp.weight >= 700) weight = wxFONTWEIGHT_BOLD; else weight = wxFONTWEIGHT_NORMAL; wxFont font(fp.size, wxFONTFAMILY_DEFAULT, fp.italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL, weight, false, stc2wx(fp.faceName), encoding); fid = new wxFontWithAscent(font); }
void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, XYPOSITION *positions) { wxString str = stc2wx(s, len); wxArrayInt tpos; SetFont(font); hdc->GetPartialTextExtents(str, tpos); #if wxUSE_UNICODE // Map the widths for UCS-2 characters back to the UTF-8 input string // NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2 // so figure it out and fix it! size_t i = 0; size_t ui = 0; while ((int)i < len) { unsigned char uch = (unsigned char)s[i]; positions[i++] = tpos[ui]; if (uch >= 0x80) { if (uch < (0x80 + 0x40 + 0x20)) { positions[i++] = tpos[ui]; } else { positions[i++] = tpos[ui]; positions[i++] = tpos[ui]; } } ui++; } #else // !wxUSE_UNICODE // If not unicode then just use the widths we have for (int i = 0; i < len; i++) { positions[i] = tpos[i]; } #endif // wxUSE_UNICODE/!wxUSE_UNICODE }
int SurfaceImpl::WidthText(Font &font, const char *s, int len) { SetFont(font); int w; int h; hdc->GetTextExtent(stc2wx(s, len), &w, &h); return w; }
int SurfaceImpl::WidthChar(Font &font, char ch) { SetFont(font); int w; int h; char s[2] = { ch, 0 }; hdc->GetTextExtent(stc2wx(s, 1), &w, &h); return w; }
void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back) { SetFont(font); hdc->SetTextForeground(wxColourFromCA(fore)); hdc->SetTextBackground(wxColourFromCA(back)); FillRectangle(rc, back); // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); }
void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, const char *s, int len, ColourAllocated fore, ColourAllocated back) { SetFont(font); hdc->SetTextForeground(wxColourFromCA(fore)); hdc->SetTextBackground(wxColourFromCA(back)); FillRectangle(rc, back); hdc->SetClippingRegion(wxRectFromPRectangle(rc)); // see comments above hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); hdc->DestroyClippingRegion(); }
void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, int ybase, const char *s, int len, ColourAllocated fore) { SetFont(font); hdc->SetTextForeground(wxColourFromCA(fore)); hdc->SetBackgroundMode(wxTRANSPARENT); // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); hdc->SetBackgroundMode(wxSOLID); }
void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic, bool extraFontFlag) { Release(); // The minus one is done because since Scintilla uses SC_SHARSET_DEFAULT // internally and we need to have wxFONENCODING_DEFAULT == SC_SHARSET_DEFAULT // so we adjust the encoding before passing it to Scintilla. See also // wxStyledTextCtrl::StyleSetCharacterSet wxFontEncoding encoding = (wxFontEncoding)(characterSet-1); wxFontEncodingArray ea = wxEncodingConverter::GetPlatformEquivalents(encoding); if (ea.GetCount()) encoding = ea[0]; wxFont* font = new wxFont(size, wxDEFAULT, italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL, false, stc2wx(faceName), encoding); font->SetNoAntiAliasing(!extraFontFlag); id = font; }
void Window::SetTitle(const char *s) { GETWIN(id)->SetLabel(stc2wx(s)); }