Пример #1
0
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);
}
void SetItemFont(wxListCtrl *listctrl, long item, wxFont &font)
{
    wxListItem it;
    it.SetId(item);
    listctrl->GetItem(it);
    font.SetPointSize(g_DefaultFontSize);
    it.SetFont(font);
    listctrl->SetItem(it);
}
Пример #3
0
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
Пример #4
0
/// Initializes a wxFont object using the FontSetting data
/// @param font wxFont object to initialize
void FontSetting::GetFont(wxFont& font) const
{
    //------Last Checked------//
    // - Dec 6, 2004
    font.SetPointSize(GetPointSize());
    font.SetFamily(wxDEFAULT);
    font.SetStyle(((IsItalic()) ? wxITALIC : wxNORMAL));
    
    if (m_weight <= weightLight)
        font.SetWeight(wxLIGHT);
    else if (m_weight < weightBold)
        font.SetWeight(wxNORMAL);
    else
        font.SetWeight(wxBOLD);
    font.SetUnderlined(IsUnderline());
    font.SetFaceName(GetFaceName());
}
Пример #5
0
wxCoord SjVisBg::SetFontPixelH(wxDC& dc, wxFont& font, wxCoord pixelH, wxCoord fontPtSize)
{
	wxCoord w, h;

	while( 1 )
	{
		font.SetPointSize(fontPtSize);
		dc.SetFont(font);
		dc.GetTextExtent(wxT("Ag"), &w, &h);
		if( h<=pixelH || fontPtSize<=6 )
		{
			break;
		}
		fontPtSize--;
	}

	return fontPtSize;
}
Пример #6
0
wxCoord SjVisBg::SetFontPixelH(wxDC& dc, wxFont& font,
                               const wxSize& sizeToFit, const wxString& strToFit)
{
	wxCoord fontPtSize = 64, w, h;

	while( 1 )
	{
		font.SetPointSize(fontPtSize);
		dc.SetFont(font);
		dc.GetTextExtent(strToFit, &w, &h);
		if( (h<=sizeToFit.y && w<=sizeToFit.x) || fontPtSize<=6 )
		{
			break;
		}
		fontPtSize--;
	}

	return fontPtSize;
}
Пример #7
0
void SjOscTitle::Draw(wxDC& dc, const wxSize& clientSize, bool titleChanged, const wxString& newTitle)
{
	// client size changed?
	if( m_clientSize != clientSize )
	{
		m_clientSize = clientSize;

		// create new font
		int pt = clientSize.y / 20; if( pt < 7 ) pt = 7;
		m_font.SetPointSize(pt);

		// calculate new size
		CalcCurrTitleSize(dc);
	}

	// title changed?
	if( titleChanged )
	{
		if( m_currTitle.IsEmpty() )
		{
			m_currTitle = newTitle;
			CalcCurrTitleSize(dc);
			m_titleOp = TITLEOP_WIPEIN;
			m_titleWipe = 0.0F;
		}
		else if( m_titleOp == TITLEOP_WIPEIN )
		{
			m_nextTitle = newTitle; // fast switch - however, this only happens for very short tracks
			CalcCurrTitleSize(dc);
		}
		else if( newTitle != m_currTitle )
		{
			m_nextTitle = newTitle;
			CalcCurrTitleSize(dc);
			if( m_titleOp == TITLEOP_NOP )
			{
				m_titleOp = TITLEOP_WIPEOUT;
				m_titleWipe = 0.0F;
			}
		}
	}

	// draw the title
	dc.SetFont(m_font);

	// scroll?
	#define SCROLL_PIX 8
	#define SCROLL_INITIAL_WAIT_MS 2000
	#define SCROLL_LEFT_END_WAIT_MS 2000
	#define SCROLL_RIGHT_END_WAIT_MS 12000
	if( m_scroll == SCROLL_WAIT )
	{
		m_scrollCnt--;
		if( m_scrollCnt <= 0 )
		{
			m_scroll = m_currTitleX<0? SCROLL_RIGHT : SCROLL_LEFT;
		}
	}
	else if( m_scroll == SCROLL_LEFT )
	{
		m_currTitleX -= SCROLL_PIX;
		if( m_currTitleX+m_currTitleW <= m_clientSize.x )
		{
			m_scroll = SCROLL_WAIT;
			m_scrollCnt = (SCROLL_LEFT_END_WAIT_MS / SLEEP_MS);
		}
	}
	else if( m_scroll == SCROLL_RIGHT )
	{
		m_currTitleX += SCROLL_PIX;
		if( m_currTitleX >= 0 )
		{
			m_scroll = SCROLL_WAIT;
			m_scrollCnt = (SCROLL_RIGHT_END_WAIT_MS / SLEEP_MS);
		}
	}

	// apply our wipe effect
	if( m_titleOp )
	{
		m_titleWipe += 1.0L/(double)SLEEP_MS;

		wxRect wipeRect(0, m_currTitleY, m_clientSize.x, m_currTitleH);

		if( m_titleOp == TITLEOP_WIPEIN )
		{
			wipeRect.width = (int) ( wipeRect.width * m_titleWipe );
		}
		else
		{
			wipeRect.x = (int) ( wipeRect.width * m_titleWipe );
		}

		// clip out the wipe rectangle and draw the text
		//dc.DrawRectangle(wipeRect);
		dc.SetClippingRegion(wipeRect);
		dc.DrawText(m_currTitle, m_currTitleX, m_currTitleY);
		dc.DestroyClippingRegion();

		// this wipe done?
		if( m_titleWipe >= 1.0 )
		{
			if( m_titleOp == TITLEOP_WIPEOUT )
			{
				m_currTitle = m_nextTitle;
				CalcCurrTitleSize(dc);
				m_titleOp = TITLEOP_WIPEIN;
				m_titleWipe = 0.0F;
			}
			else
			{
				m_titleOp = TITLEOP_NOP;
			}
		}
	}
	else
	{
		// just draw the text, no wiping currently needed
		dc.DrawText(m_currTitle, m_currTitleX, m_currTitleY);
	}
}