Moved IsFontUsable() to Globals.h/cpp

This commit is contained in:
JackBurton
2015-02-21 21:31:08 +01:00
parent 72bc3bf2bd
commit f88412ccda
3 changed files with 39 additions and 32 deletions
+2 -31
View File
@@ -27,6 +27,7 @@
#include <View.h>
#include "Colors.h"
#include "Globals.h"
#include "PrefHandler.h"
#include "TermConst.h"
#include "TermWindow.h"
@@ -36,35 +37,6 @@
#define B_TRANSLATION_CONTEXT "Terminal AppearancePrefView"
static bool
IsFontUsable(const BFont& font)
{
// TODO: If BFont::IsFullAndHalfFixed() was implemented, we could
// use that. But I don't think it's easily implementable using
// Freetype.
if (font.IsFixed())
return true;
// manually check if all applicable chars are the same width
char buffer[2] = { ' ', 0 };
int firstWidth = (int)ceilf(font.StringWidth(buffer));
// TODO: Workaround for broken fonts/font_subsystem
if (firstWidth <= 0)
return false;
for (int c = ' ' + 1; c <= 0x7e; c++) {
buffer[0] = c;
int width = (int)ceilf(font.StringWidth(buffer));
if (width != firstWidth)
return false;
}
return true;
}
// #pragma mark -
@@ -501,10 +473,9 @@ AppearancePrefView::_MakeFontMenu(uint32 command,
{
BPopUpMenu* menu = new BPopUpMenu("");
int32 numFamilies = count_font_families();
uint32 flags;
for (int32 i = 0; i < numFamilies; i++) {
font_family family;
uint32 flags;
if (get_font_family(i, &family, &flags) == B_OK) {
BFont font;
font_style style;
+34 -1
View File
@@ -3,9 +3,42 @@
* Distributed under the terms of the MIT License.
*/
#include "Globals.h"
#include <math.h>
#include <stddef.h>
#include "Globals.h"
#include <Font.h>
BClipboard* gMouseClipboard = NULL;
bool
IsFontUsable(const BFont& font)
{
// TODO: If BFont::IsFullAndHalfFixed() was implemented, we could
// use that. But I don't think it's easily implementable using
// Freetype.
if (font.IsFixed())
return true;
// manually check if all applicable chars are the same width
char buffer[2] = { ' ', 0 };
int firstWidth = (int)ceilf(font.StringWidth(buffer));
// TODO: Workaround for broken fonts/font_subsystem
if (firstWidth <= 0)
return false;
for (int c = ' ' + 1; c <= 0x7e; c++) {
buffer[0] = c;
int width = (int)ceilf(font.StringWidth(buffer));
if (width != firstWidth)
return false;
}
return true;
}
+3
View File
@@ -7,9 +7,12 @@
class BClipboard;
class BFont;
extern BClipboard* gMouseClipboard;
// clipboard used for mouse copy'n'paste
bool IsFontUsable(const BFont& font);
#endif // GLOBALS_H