void RotatedDC::SetFont(const wxFont& font) { if (quality == QUALITY_LOW && zoomX == 1 && zoomY == 1) { dc.SetFont(font); } else { wxFont scaled = font; if (quality == QUALITY_LOW) { scaled.SetPointSize((int) trY(font.GetPointSize())); } else { scaled.SetPointSize((int) (trY(font.GetPointSize()) * text_scaling)); } dc.SetFont(scaled); } }
// Get attributes from font. bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags) { if (!font.Ok()) return false; if (flags & wxTEXT_ATTR_FONT_SIZE) m_fontSize = font.GetPointSize(); if (flags & wxTEXT_ATTR_FONT_ITALIC) m_fontStyle = font.GetStyle(); if (flags & wxTEXT_ATTR_FONT_WEIGHT) m_fontWeight = font.GetWeight(); if (flags & wxTEXT_ATTR_FONT_UNDERLINE) m_fontUnderlined = font.GetUnderlined(); if (flags & wxTEXT_ATTR_FONT_FACE) m_fontFaceName = font.GetFaceName(); if (flags & wxTEXT_ATTR_FONT_ENCODING) m_fontEncoding = font.GetEncoding(); if (flags & wxTEXT_ATTR_FONT_FAMILY) m_fontFamily = font.GetFamily(); m_flags |= flags; return true; }
/************************************************************** *** ** FontConfig --- setFont *** ***************************************************************/ void FontConfig::setFont( const int &i, const wxFont &f ) { assert( i >= 0 && i < MAX_FONTS ); fd[i].pointSize = f.GetPointSize(); fd[i].family = f.GetFamily(); fd[i].style = f.GetStyle(); fd[i].weight = f.GetWeight(); fd[i].facename = f.GetFaceName(); }
void wxExStyle::Set(const wxXmlNode* node, const wxString& macro) { SetNo( wxExLexers::Get()->ApplyMacro(node->GetAttribute("no", "0"), macro), macro); m_Value = node->GetNodeContent().Strip(wxString::both); #ifdef wxExUSE_CPP0X const auto it = wxExLexers::Get()->GetThemeMacros().find(m_Value); #else std::map<wxString, wxString>::const_iterator it = wxExLexers::Get()->GetThemeMacros().find(m_Value); #endif if (it != wxExLexers::Get()->GetThemeMacros().end()) { wxString value = it->second; if (value.Contains("default-font")) { const wxFont font(wxConfigBase::Get()->ReadObject(_("Default font"), wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT))); value.Replace("default-font", wxString::Format("face:%s,size:%d", font.GetFaceName().c_str(), font.GetPointSize())); const wxFontStyle style = font.GetStyle(); if (style == wxFONTSTYLE_ITALIC || style == wxFONTSTYLE_SLANT) { value += ",italic"; } if (font.GetWeight() == wxFONTWEIGHT_BOLD) { value += ",bold"; } if (font.GetUnderlined()) { value += ",underline"; } } m_Value = value; } if (!IsOk()) { wxLogError(_("Illegal style: %s on line: %d"), m_Value.c_str(), node->GetLineNumber()); } }
bool HtmlText::SetFont(const wxFont & font) { if (! wxControl::SetFont(font)) return false; if (m_parser) m_parser->SetStandardFonts(font.GetPointSize(), font.GetFaceName()); LayoutCell(); Refresh(); return true; }
void wxGCDCImpl::SetFont( const wxFont &font ) { m_font = font; if ( m_graphicContext ) { wxFont f = font; if ( f.IsOk() ) f.SetPointSize( /*LogicalToDeviceYRel*/(font.GetPointSize())); m_graphicContext->SetFont( f, m_textForegroundColour ); } }
static void AdjustFontSize(wxFont& font, wxDC& dc, const wxSize& pixelSize) { int currentSize = 0; int largestGood = 0; int smallestBad = 0; bool initialGoodFound = false; bool initialBadFound = false; // NB: this assignment was separated from the variable definition // in order to fix a gcc v3.3.3 compiler crash currentSize = font.GetPointSize(); while (currentSize > 0) { dc.SetFont(font); // if currentSize (in points) results in a font that is smaller // than required by pixelSize it is considered a good size if (dc.GetCharHeight() <= pixelSize.GetHeight() && (!pixelSize.GetWidth() || dc.GetCharWidth() <= pixelSize.GetWidth())) { largestGood = currentSize; initialGoodFound = true; } else { smallestBad = currentSize; initialBadFound = true; } if (!initialGoodFound) { currentSize /= 2; } else if (!initialBadFound) { currentSize *= 2; } else { int distance = smallestBad - largestGood; if (distance == 1) break; currentSize = largestGood + distance / 2; } font.SetPointSize(currentSize); } if (currentSize != largestGood) font.SetPointSize(largestGood); }
TranslDlg::TranslDlg(wxWindow *parent) : wxPanel(parent) {//===================================================== int height; int width; int x,y; int font_size; int height_ph = 350; wxTextAttr attr; wxFont font = wxFont(12,wxFONTFAMILY_ROMAN,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_LIGHT,false,_T(""),wxFONTENCODING_SYSTEM); attr.SetFont(font); wxClientDisplayRect(&x,&y,&width, &height); #ifdef PLATFORM_WINDOWS if(height <= 768) height_ph = height - 416; #else if(height <= 800) height_ph = 280; #endif t_source = new wxTextCtrl(this,T_SOURCE,_T(""),wxPoint(0,4), wxSize(298,250),wxTE_MULTILINE,wxDefaultValidator,_T("Text input window")); t_source->SetDefaultStyle(attr); t_phonetic = new wxTextCtrl(this,T_PHONETIC,_T(""),wxPoint(0,262), wxSize(298,height_ph),wxTE_MULTILINE | wxTE_READONLY, wxDefaultValidator,_T("Phoneme translation window")); style_phonetic = t_phonetic->GetDefaultStyle(); font_phonetic = style_phonetic.GetFont(); font_size = font_phonetic.GetPointSize(); font_phonetic_large = font_phonetic; style_phonetic_large = style_phonetic; //font_phonetic_large.SetFamily(wxFONTFAMILY_SWISS); font_phonetic_large.SetPointSize(font_size+1); style_phonetic_large.SetFont(font_phonetic_large); y = height_ph + 270; t_translate = new wxButton(this,T_TRANSLATE,_T("Translate"),wxPoint(4,y)); t_translate = new wxButton(this,T_RULES,_T("Show Rules"),wxPoint(4,y+32)); t_translate = new wxButton(this,T_TRANSLATE_IPA,_T("Show IPA"),wxPoint(100,y+32)); t_process = new wxButton(this,T_PROCESS,_T("Speak"),wxPoint(100,y)); t_source->SetFocus(); } // end of TransDlg::TransDlg
/***************************************************** ** ** Painter --- getTextExtent ** ******************************************************/ MPoint Painter::getTextExtent( const MToken &token ) { const wxFont oldFont = getCurrentFont(); wxString s; Lang lang; SheetFormatter formatter( writercfg ); MPoint p; wxChar symbol = 0; SymbolProvider sp( writercfg ); switch ( token.entity ) { case TTSE_PLANET: if ( writercfg->planetSymbols ) symbol = sp.getPlanetCode( (ObjectId)token.entityId ); if ( ! symbol ) s = formatter.getObjectNamePlain( (ObjectId)token.entityId, token.textFormat, token.vedic ); break; case TTSE_SIGN: if ( writercfg->signSymbols ) symbol = sp.getSignCode( (Rasi)token.entityId ); if ( ! symbol ) s = lang.getSignName( (Rasi)token.entityId, token.textFormat ); //, writercfg->vedicSignNames ); break; case TTSE_ASPECT: symbol = SymbolProvider().getAspectCode( (ASPECT_TYPE)token.entityId ); if ( ! symbol ) s = AspectExpert::getAspectShortDescription( (int)token.entityId ); break; case TTSE_DIRECTION: symbol = sp.getRetroCode( (MOVING_DIRECTION)token.entityId ); if ( ! symbol ) s = wxT( "R" ); break; default: symbol = 0; s = token.text; break; } if ( symbol ) { const int pointSize = oldFont.GetPointSize(); setFont( *FontProvider::get()->getFontBySize( FONT_GRAPHIC_SYMBOLS, pointSize )); p = getTextExtent( symbol ); } else { p = getTextExtent( s ); } setFont( oldFont ); return p; }
void ColoursAndFontsManager::SetGlobalFont(const wxFont& font) { this->m_globalFont = font; // Loop for every lexer and update the font per style std::for_each(m_allLexers.begin(), m_allLexers.end(), [&](LexerConf::Ptr_t lexer) { StyleProperty::Map_t& props = lexer->GetLexerProperties(); StyleProperty::Map_t::iterator iter = props.begin(); for(; iter != props.end(); ++iter) { StyleProperty& sp = iter->second; sp.SetFaceName(font.GetFaceName()); sp.SetFontSize(font.GetPointSize()); sp.SetBold(font.GetWeight() == wxFONTWEIGHT_BOLD); sp.SetItalic(font.GetStyle() == wxFONTSTYLE_ITALIC); sp.SetUnderlined(font.GetUnderlined()); } }); }
bool wxWindowSettings::SaveFont(wxConfigBase& config, const wxString& windowName, const wxFont& font) { if (!font.Ok()) return FALSE; wxString pathBase(wxT("/Fonts/")); pathBase += windowName; pathBase += wxT("/"); config.Write(pathBase + wxT("PointSize"), (long) font.GetPointSize()); config.Write(pathBase + wxT("Family"), (long) font.GetFamily()); config.Write(pathBase + wxT("Style"), (long) font.GetStyle()); config.Write(pathBase + wxT("Weight"), (long) font.GetWeight()); config.Write(pathBase + wxT("Underlined"), (long) font.GetUnderlined()); config.Write(pathBase + wxT("FaceName"), font.GetFaceName()); return TRUE; }
// Get attributes from font. bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags) { if (!font.IsOk()) return false; if (flags & wxTEXT_ATTR_FONT_SIZE) m_fontSize = font.GetPointSize(); if (flags & wxTEXT_ATTR_FONT_ITALIC) m_fontStyle = font.GetStyle(); if (flags & wxTEXT_ATTR_FONT_WEIGHT) m_fontWeight = font.GetWeight(); if (flags & wxTEXT_ATTR_FONT_UNDERLINE) m_fontUnderlined = font.GetUnderlined(); if (flags & wxTEXT_ATTR_FONT_STRIKETHROUGH) m_fontStrikethrough = font.GetStrikethrough(); if (flags & wxTEXT_ATTR_FONT_FACE) m_fontFaceName = font.GetFaceName(); if (flags & wxTEXT_ATTR_FONT_ENCODING) m_fontEncoding = font.GetEncoding(); if (flags & wxTEXT_ATTR_FONT_FAMILY) { // wxFont might not know its family, avoid setting m_fontFamily to an // invalid value and rather pretend that we don't have any font family // information at all in this case const wxFontFamily fontFamily = font.GetFamily(); if ( fontFamily == wxFONTFAMILY_UNKNOWN ) flags &= ~wxTEXT_ATTR_FONT_FAMILY; else m_fontFamily = fontFamily; } m_flags |= flags; return true; }
void CustomGauge::RedrawNow() { wxClientDC m_canvas(m_panel); m_canvas.Clear(); // Set default font m_canvas.SetFont(m_font); m_canvas.SetTextForeground(m_font_col); // Draw gauge background m_canvas.SetBrush(m_backFill); m_canvas.SetPen(m_pen); wxRect FillRect(0, 0, m_canvas.GetSize().GetWidth(), m_canvas.GetSize().GetHeight()); m_canvas.DrawRectangle(FillRect); // Draw gauge bar m_canvas.SetBrush(m_foreFill); wxCoord w = m_canvas.GetSize().GetWidth() * GetValue() / GetRange(); wxCoord h = m_canvas.GetSize().GetHeight(); wxRect rectToDraw(0, 0, w, h); m_canvas.DrawRectangle(rectToDraw); if (m_label) { const wxFont currentFont = m_canvas.GetFont(); int fw = currentFont.GetPointSize(); m_canvas.DrawText(wxString::Format("%u%", GetValue() * 100 / GetRange() ), m_canvas.GetSize().GetWidth() / 2 - fw / 0.75, m_canvas.GetSize().GetHeight() / 2 - fw / 1.25 ); } }
bool wxFontBase::operator==(const wxFont& font) const { // either it is the same font, i.e. they share the same common data or they // have different ref datas but still describe the same font return IsSameAs(font) || ( IsOk() == font.IsOk() && GetPointSize() == font.GetPointSize() && // in wxGTK1 GetPixelSize() calls GetInternalFont() which uses // operator==() resulting in infinite recursion so we can't use it // in that port #if !defined(__WXGTK__) || defined(__WXGTK20__) GetPixelSize() == font.GetPixelSize() && #endif GetFamily() == font.GetFamily() && GetStyle() == font.GetStyle() && GetWeight() == font.GetWeight() && GetUnderlined() == font.GetUnderlined() && GetFaceName().IsSameAs(font.GetFaceName(), false) && GetEncoding() == font.GetEncoding() ); }
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) { wxPaintDC dc(this); PrepareDC(dc); // set background dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); dc.SetFont(m_font); // one text line height wxCoord hLine = dc.GetCharHeight(); // the current text origin wxCoord x = 5, y = 5; // output the font name/info wxString fontInfo; fontInfo.Printf(wxT("Face name: %s, family: %s"), m_font.GetFaceName().c_str(), m_font.GetFamilyString().c_str()); dc.DrawText(fontInfo, x, y); y += hLine; fontInfo.Printf(wxT("Size: %d points or %d pixels; %d*%d average char size"), m_font.GetPointSize(), m_font.GetPixelSize().y, dc.GetCharWidth(), dc.GetCharHeight()); dc.DrawText(fontInfo, x, y); y += hLine; fontInfo.Printf(wxT("Style: %s, weight: %s, fixed width: %s, encoding: %s"), m_font.GetStyleString().c_str(), m_font.GetWeightString().c_str(), m_font.IsFixedWidth() ? wxT("yes") : wxT("no"), wxFontMapper::GetEncodingDescription(m_font.GetEncoding())); dc.DrawText(fontInfo, x, y); y += hLine; if ( m_font.IsOk() ) { const wxNativeFontInfo *info = m_font.GetNativeFontInfo(); if ( info ) { wxString fontDesc = m_font.GetNativeFontInfoUserDesc(); fontInfo.Printf(wxT("Native font info: %s"), fontDesc.c_str()); dc.DrawText(fontInfo, x, y); y += hLine; } } y += hLine; // prepare to draw the font dc.SetTextForeground(m_colour); // the size of one cell (Normally biggest char + small margin) wxCoord maxCharWidth, maxCharHeight; dc.GetTextExtent(wxT("W"), &maxCharWidth, &maxCharHeight); int w = maxCharWidth + 5, h = maxCharHeight + 4; // print all font symbols from 32 to 256 in 7 rows of 32 chars each for ( int i = 0; i < 7; i++ ) { for ( int j = 0; j < 32; j++ ) { wxChar c = (wxChar)(32 * (i + 1) + j); wxCoord charWidth, charHeight; dc.GetTextExtent(c, &charWidth, &charHeight); dc.DrawText ( c, x + w*j + (maxCharWidth - charWidth) / 2 + 1, y + h*i + (maxCharHeight - charHeight) / 2 ); } } // draw the lines between them dc.SetPen(*wxBLUE_PEN); int l; // horizontal for ( l = 0; l < 8; l++ ) { int yl = y + h*l - 2; dc.DrawLine(x - 2, yl, x + 32*w - 1, yl); } // and vertical for ( l = 0; l < 33; l++ ) { int xl = x + w*l - 2; dc.DrawLine(xl, y - 2, xl, y + 7*h - 1); } }
// Get attributes from font. bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags) { if (!font.IsOk()) return false; // If we pass both pixel and point size attributes, this is an indication // to choose the most appropriate units. if ((flags & wxTEXT_ATTR_FONT) == wxTEXT_ATTR_FONT) { if (font.IsUsingSizeInPixels()) { m_fontSize = font.GetPixelSize().y; flags &= ~wxTEXT_ATTR_FONT_POINT_SIZE; } else { m_fontSize = font.GetPointSize(); flags &= ~wxTEXT_ATTR_FONT_PIXEL_SIZE; } } else if (flags & wxTEXT_ATTR_FONT_POINT_SIZE) { m_fontSize = font.GetPointSize(); flags &= ~wxTEXT_ATTR_FONT_PIXEL_SIZE; } else if (flags & wxTEXT_ATTR_FONT_PIXEL_SIZE) { m_fontSize = font.GetPixelSize().y; } if (flags & wxTEXT_ATTR_FONT_ITALIC) m_fontStyle = font.GetStyle(); if (flags & wxTEXT_ATTR_FONT_WEIGHT) m_fontWeight = font.GetWeight(); if (flags & wxTEXT_ATTR_FONT_UNDERLINE) m_fontUnderlined = font.GetUnderlined(); if (flags & wxTEXT_ATTR_FONT_STRIKETHROUGH) m_fontStrikethrough = font.GetStrikethrough(); if (flags & wxTEXT_ATTR_FONT_FACE) m_fontFaceName = font.GetFaceName(); if (flags & wxTEXT_ATTR_FONT_ENCODING) m_fontEncoding = font.GetEncoding(); if (flags & wxTEXT_ATTR_FONT_FAMILY) { // wxFont might not know its family, avoid setting m_fontFamily to an // invalid value and rather pretend that we don't have any font family // information at all in this case const wxFontFamily fontFamily = font.GetFamily(); if ( fontFamily == wxFONTFAMILY_UNKNOWN ) flags &= ~wxTEXT_ATTR_FONT_FAMILY; else m_fontFamily = fontFamily; } m_flags |= flags; return true; }