diff --git a/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.cpp b/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.cpp index 0aaa7d5506..7e8a2ed2ff 100644 --- a/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.cpp +++ b/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.cpp @@ -106,7 +106,7 @@ static const wchar_t map_numbers[] = { }; /* Regenerate the font, pulling in settings from widgets. */ -void CTextureFontGeneratorDlg::UpdateFont() +void CTextureFontGeneratorDlg::UpdateFont( bool bSavingDoubleRes ) { m_bUpdateFontNeeded = false; @@ -126,16 +126,18 @@ void CTextureFontGeneratorDlg::UpdateFont() m_FontSize.GetWindowText(sText); g_pTextureFont->m_fFontSizePixels = (float) atof(sText); + if( bSavingDoubleRes ) + g_pTextureFont->m_fFontSizePixels *= 2; m_Padding.GetWindowText(sText); g_pTextureFont->m_iPadding = atoi(sText); + if( bSavingDoubleRes ) + g_pTextureFont->m_iPadding *= 2; CMenu *pMenu = GetMenu(); g_pTextureFont->m_bBold = !!( pMenu->GetMenuState(ID_STYLE_BOLD, 0) & MF_CHECKED ); g_pTextureFont->m_bItalic = !!( pMenu->GetMenuState(ID_STYLE_ITALIC, 0) & MF_CHECKED ); g_pTextureFont->m_bAntiAlias = !!( pMenu->GetMenuState(ID_STYLE_ANTIALIASED, 0) & MF_CHECKED ); - if( !!( pMenu->GetMenuState(ID_OPTIONS_DOUBLERES, 0) & MF_CHECKED ) ) - g_pTextureFont->m_fFontSizePixels *= 2; g_pTextureFont->m_PagesToGenerate.clear(); FontPageDescription desc; @@ -378,7 +380,7 @@ void CTextureFontGeneratorDlg::OnPaint() if( m_bUpdateFontNeeded ) { m_bUpdateFontViewAndCloseUpNeeded = true; - UpdateFont(); + UpdateFont( false ); } if( m_bUpdateFontViewAndCloseUpNeeded ) @@ -581,7 +583,22 @@ void CTextureFontGeneratorDlg::OnFileSave() } } */ - g_pTextureFont->Save( szFile ); + + CMenu *pMenu = GetMenu(); + if( !!( pMenu->GetMenuState(ID_OPTIONS_DOUBLERES, 0) & MF_CHECKED ) ) // DoubleRes checked? + { + g_pTextureFont->Save( szFile, "", true, false ); // save metrics + UpdateFont( true ); // generate DoubleRes bitmaps + g_pTextureFont->Save( szFile, " (doubleres)", false, true ); // save bitmaps + // reset to normal, non-DoubleRes font + m_bUpdateFontNeeded = true; + Invalidate( FALSE ); + UpdateWindow(); + } + else // normal res + { + g_pTextureFont->Save( szFile, "", true, true ); // save metrics and bitmaps + } } void CTextureFontGeneratorDlg::OnFileExit() diff --git a/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.h b/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.h index 2f89d03bba..bc42739fe9 100644 --- a/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.h +++ b/stepmania/src/Texture Font Generator/Texture Font GeneratorDlg.h @@ -38,7 +38,7 @@ protected: DECLARE_MESSAGE_MAP() void UpdateFontViewAndCloseUp(); - void UpdateFont(); + void UpdateFont( bool bSavingDoubleRes ); void UpdateCloseUp(); public: diff --git a/stepmania/src/Texture Font Generator/TextureFont.cpp b/stepmania/src/Texture Font Generator/TextureFont.cpp index b242cf72e2..cd840066e0 100644 --- a/stepmania/src/Texture Font Generator/TextureFont.cpp +++ b/stepmania/src/Texture Font Generator/TextureFont.cpp @@ -286,10 +286,9 @@ void TextureFont::FormatFontPage( int iPage, HDC hDC ) FontPage *pPage = m_apPages[iPage]; pPage->m_iFrameWidth = (m_BoundingRect.right - m_BoundingRect.left) + m_iPadding; pPage->m_iFrameHeight = (m_BoundingRect.bottom - m_BoundingRect.top) + m_iPadding; - if( pPage->m_iFrameWidth % 2 ) - ++pPage->m_iFrameWidth; - if( pPage->m_iFrameHeight % 2 ) - ++pPage->m_iFrameHeight; + int iDimensionMultiple = 4; // TODO: This only needs to be 4 for doubleres textures. It could be 2 otherwise and use less space + pPage->m_iFrameWidth = (int)ceil( pPage->m_iFrameWidth /(double)iDimensionMultiple ) * iDimensionMultiple; + pPage->m_iFrameHeight = (int)ceil( pPage->m_iFrameHeight /(double)iDimensionMultiple ) * iDimensionMultiple; pPage->m_iNumFramesX = (int) ceil( powf( (float) Desc.chars.size(), 0.5f ) ); pPage->m_iNumFramesY = (int) ceil( (float) Desc.chars.size() / pPage->m_iNumFramesX ); @@ -372,24 +371,29 @@ void wchar_to_utf8( wchar_t ch, string &out ) #include -void TextureFont::Save( CString sBasePath ) +void TextureFont::Save( CString sBasePath, CString sBitmapAppendBeforeExtension, bool bSaveMetrics, bool bSaveBitmaps ) { if( m_sError != "" ) return; const CString inipath = sBasePath + ".ini"; - ofstream f(inipath.GetString()); + ofstream f; - /* Write global properties: */ - f << "[common]\n"; + if( bSaveMetrics ) + { + f.open(inipath.GetString()); - f << "Baseline=" << m_iCharBaseline + GetTopPadding() << "\n"; - f << "Top=" << m_iCharTop + GetTopPadding() << "\n"; - f << "LineSpacing=" << m_iCharVertSpacing << "\n"; - f << "DrawExtraPixelsLeft=" << m_iCharLeftOverlap << "\n"; - f << "DrawExtraPixelsRight=" << m_iCharRightOverlap << "\n"; - f << "AdvanceExtraPixels=0\n"; + /* Write global properties: */ + f << "[common]\n"; + + f << "Baseline=" << m_iCharBaseline + GetTopPadding() << "\n"; + f << "Top=" << m_iCharTop + GetTopPadding() << "\n"; + f << "LineSpacing=" << m_iCharVertSpacing << "\n"; + f << "DrawExtraPixelsLeft=" << m_iCharLeftOverlap << "\n"; + f << "DrawExtraPixelsRight=" << m_iCharRightOverlap << "\n"; + f << "AdvanceExtraPixels=0\n"; + } for( unsigned i = 0; i < m_apPages.size(); ++i ) { @@ -397,58 +401,65 @@ void TextureFont::Save( CString sBasePath ) ASSERT( m_apPages[i]->m_hPage ); FontPage &page = *m_apPages[i]; - f << "\n" << "[" << desc.name.GetString() << "]\n"; - + if( bSaveMetrics ) { - int iWidth = 1; - if( desc.chars.size() / page.m_iNumFramesX > 10 ) - iWidth = 2; + f << "\n" << "[" << desc.name.GetString() << "]\n"; - unsigned iChar = 0; - unsigned iLine = 0; - while( iChar < desc.chars.size() ) { - f << "Line " << setw(iWidth) << iLine << "="; - f << setw(1); - for( int iX = 0; iX < page.m_iNumFramesX && iChar < desc.chars.size(); ++iX, ++iChar ) + int iWidth = 1; + if( desc.chars.size() / page.m_iNumFramesX > 10 ) + iWidth = 2; + + unsigned iChar = 0; + unsigned iLine = 0; + while( iChar < desc.chars.size() ) { - const wchar_t c = desc.chars[iChar]; - string sUTF8; - wchar_to_utf8( c, sUTF8 ); - f << sUTF8.c_str(); + f << "Line " << setw(iWidth) << iLine << "="; + f << setw(1); + for( int iX = 0; iX < page.m_iNumFramesX && iChar < desc.chars.size(); ++iX, ++iChar ) + { + const wchar_t c = desc.chars[iChar]; + string sUTF8; + wchar_to_utf8( c, sUTF8 ); + f << sUTF8.c_str(); + } + f << "\n"; + ++iLine; } - f << "\n"; - ++iLine; + } + + f << "\n"; + for( unsigned j = 0; j < desc.chars.size(); ++j ) + { + /* This is the total width to advance for the whole character, which is the + * sum of the ABC widths. */ + const wchar_t c = desc.chars[j]; + ABC &abc = m_ABC[c]; + int iCharWidth = abc.abcA + int(abc.abcB) + int(abc.abcC); + f << j << "=" << iCharWidth << "\n"; } } - f << "\n"; - for( unsigned j = 0; j < desc.chars.size(); ++j ) + if( bSaveBitmaps ) { - /* This is the total width to advance for the whole character, which is the - * sum of the ABC widths. */ - const wchar_t c = desc.chars[j]; - ABC &abc = m_ABC[c]; - int iCharWidth = abc.abcA + int(abc.abcB) + int(abc.abcC); - f << j << "=" << iCharWidth << "\n"; + Surface surf; + BitmapToSurface( m_apPages[i]->m_hPage, &surf ); + + GrayScaleToAlpha( &surf ); + + CString sFile; + sFile.Format( "%s [%s] %ix%i%s.png", + sBasePath.GetString(), + m_PagesToGenerate[i].name.GetString(), + m_apPages[i]->m_iNumFramesX, + m_apPages[i]->m_iNumFramesY, + sBitmapAppendBeforeExtension.GetString() ); + + FILE *f = fopen( sFile, "w+b" ); + char szErrorbuf[1024]; + SavePNG( f, szErrorbuf, &surf ); + fclose( f ); } - - Surface surf; - BitmapToSurface( m_apPages[i]->m_hPage, &surf ); - - GrayScaleToAlpha( &surf ); - - CString sFile; - sFile.Format( "%s [%s] %ix%i.png", - sBasePath.GetString(), - m_PagesToGenerate[i].name.GetString(), - m_apPages[i]->m_iNumFramesX, - m_apPages[i]->m_iNumFramesY ); - - FILE *f = fopen( sFile, "w+b" ); - char szErrorbuf[1024]; - SavePNG( f, szErrorbuf, &surf ); - fclose( f ); } } diff --git a/stepmania/src/Texture Font Generator/TextureFont.h b/stepmania/src/Texture Font Generator/TextureFont.h index d737ac4bc1..c17bf9f87b 100644 --- a/stepmania/src/Texture Font Generator/TextureFont.h +++ b/stepmania/src/Texture Font Generator/TextureFont.h @@ -37,7 +37,7 @@ public: vector m_PagesToGenerate; void FormatFontPage( int iPage, HDC hDC ); void FormatFontPages(); - void Save( CString sPath ); + void Save( CString sPath, CString sBitmapAppendBeforeExtension, bool bSaveMetrics, bool bSaveBitmaps ); map m_Characters;