* Added a third hinting mode: monospaced fonts only. This is especially helpful

with low resolution devices like the EeePC - small fonts can look pretty bad
  when hinting is turned on, and you still have the advantage of hinting for
  text editors and the terminal.
* Added a ServerFont::Hinting() method (that currently only evaluates the
  global hinting setting).
* Added a TODO comment on why having global settings is not what we aim for.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28837 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-12-31 18:44:02 +00:00
parent 16edc24aba
commit e4737a9260
11 changed files with 170 additions and 127 deletions

View File

@ -221,18 +221,18 @@ get_subpixel_antialiasing(bool* subpix)
void
set_hinting(bool hinting)
set_hinting_mode(uint8 hinting)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_HINTING);
link.Attach<bool>(hinting);
link.Attach<uint8>(hinting);
link.Flush();
}
status_t
get_hinting(bool* hinting)
get_hinting_mode(uint8* hinting)
{
BPrivate::AppServerLink link;
@ -240,7 +240,7 @@ get_hinting(bool* hinting)
int32 status = B_ERROR;
if (link.FlushWithReply(status) != B_OK || status < B_OK)
return status;
link.Read<bool>(hinting);
link.Read<uint8>(hinting);
return B_OK;
}
@ -438,7 +438,7 @@ get_click_speed(bigtime_t *speed)
status_t err = _control_input_server_(&command, &reply);
if (err != B_OK)
return err;
if (reply.FindInt64("speed", speed) != B_OK)
*speed = 500000;
@ -465,7 +465,7 @@ get_mouse_speed(int32 *speed)
status_t err = _control_input_server_(&command, &reply);
if (err != B_OK)
return err;
if (reply.FindInt32("speed", speed) != B_OK)
*speed = 65536;
@ -662,12 +662,12 @@ get_modifier_key(uint32 modifier, uint32 *key)
command.AddInt32("modifier", modifier);
_control_input_server_(&command, &reply);
status_t err = reply.FindInt32("key", (int32 *) &rkey);
if (err != B_OK)
return err;
*key = rkey;
return B_OK;
}

View File

@ -29,23 +29,30 @@
//#define DISABLE_HINTING_CONTROL
// if defined, the hinting menu is disabled (hinting not properly
// implemented)
static const int32 kMsgSetAntialiasing = 'anti';
static const int32 kMsgSetHinting = 'hint';
static const int32 kMsgSetAverageWeight = 'avrg';
static const char* kSubpixelLabel = "LCD subpixel";
static const char* kGrayscaleLabel = "Grayscale";
static const char* kNoHintingLabel = "Off";
static const char* kMonospacedHintingLabel = "Monospaced Fonts Only";
static const char* kFullHintingLabel = "On";
// #pragma mark - private libbe API
enum {
HINTING_MODE_OFF = 0,
HINTING_MODE_ON,
HINTING_MODE_MONOSPACED_ONLY
};
extern void set_subpixel_antialiasing(bool subpix);
extern status_t get_subpixel_antialiasing(bool* subpix);
extern void set_hinting(bool hinting);
extern status_t get_hinting(bool* hinting);
extern void set_hinting_mode(uint8 hinting);
extern status_t get_hinting_mode(uint8* hinting);
extern void set_average_weight(unsigned char averageWeight);
extern status_t get_average_weight(unsigned char* averageWeight);
@ -60,11 +67,11 @@ AntialiasingSettingsView::AntialiasingSettingsView(const char* name)
if (get_subpixel_antialiasing(&fCurrentSubpixelAntialiasing) != B_OK)
fCurrentSubpixelAntialiasing = false;
fSavedSubpixelAntialiasing = fCurrentSubpixelAntialiasing;
if (get_hinting(&fCurrentHinting) != B_OK)
fCurrentHinting = true;
if (get_hinting_mode(&fCurrentHinting) != B_OK)
fCurrentHinting = HINTING_MODE_ON;
fSavedHinting = fCurrentHinting;
if (get_average_weight(&fCurrentAverageWeight) != B_OK)
fCurrentAverageWeight = 100;
fSavedAverageWeight = fCurrentAverageWeight;
@ -75,7 +82,7 @@ AntialiasingSettingsView::AntialiasingSettingsView(const char* name)
_BuildAntialiasingMenu();
fAntialiasingMenuField = new BMenuField("antialiasing",
"Anti-aliasing type:", fAntialiasingMenu, NULL);
// "average weight" in subpixel filtering
fAverageWeightControl = new BSlider("averageWeightControl",
"Reduce colored edges filter strength:",
@ -84,7 +91,7 @@ AntialiasingSettingsView::AntialiasingSettingsView(const char* name)
fAverageWeightControl->SetHashMarks(B_HASH_MARKS_BOTTOM);
fAverageWeightControl->SetHashMarkCount(255 / 15);
fAverageWeightControl->SetEnabled(false);
// hinting menu
_BuildHintingMenu();
fHintingMenuField = new BMenuField("hinting", "Glyph hinting:",
@ -170,7 +177,7 @@ AntialiasingSettingsView::MessageReceived(BMessage *msg)
case kMsgSetAntialiasing:
{
bool subpixelAntialiasing;
if (msg->FindBool("antialiasing", &subpixelAntialiasing) != B_OK
if (msg->FindBool("antialiasing", &subpixelAntialiasing) != B_OK
|| subpixelAntialiasing == fCurrentSubpixelAntialiasing)
break;
fCurrentSubpixelAntialiasing = subpixelAntialiasing;
@ -183,13 +190,13 @@ AntialiasingSettingsView::MessageReceived(BMessage *msg)
}
case kMsgSetHinting:
{
bool hinting;
if (msg->FindBool("hinting", &hinting) != B_OK
int8 hinting;
if (msg->FindInt8("hinting", &hinting) != B_OK
|| hinting == fCurrentHinting)
break;
fCurrentHinting = hinting;
set_hinting(fCurrentHinting);
fCurrentHinting = hinting;
set_hinting_mode(fCurrentHinting);
Window()->PostMessage(kMsgUpdate);
break;
@ -224,7 +231,7 @@ AntialiasingSettingsView::_BuildAntialiasingMenu()
BMenuItem* item = new BMenuItem(kGrayscaleLabel, message);
fAntialiasingMenu->AddItem(item);
message = new BMessage(kMsgSetAntialiasing);
message->AddBool("antialiasing", true);
@ -240,18 +247,16 @@ AntialiasingSettingsView::_BuildHintingMenu()
fHintingMenu = new BPopUpMenu("Hinting menu");
BMessage* message = new BMessage(kMsgSetHinting);
message->AddBool("hinting", false);
message->AddInt8("hinting", HINTING_MODE_OFF);
fHintingMenu->AddItem(new BMenuItem(kNoHintingLabel, message));
BMenuItem* item = new BMenuItem(kNoHintingLabel, message);
fHintingMenu->AddItem(item);
message = new BMessage(kMsgSetHinting);
message->AddBool("hinting", true);
message->AddInt8("hinting", HINTING_MODE_ON);
fHintingMenu->AddItem(new BMenuItem(kFullHintingLabel, message));
item = new BMenuItem(kFullHintingLabel, message);
fHintingMenu->AddItem(item);
message = new BMessage(kMsgSetHinting);
message->AddInt8("hinting", HINTING_MODE_MONOSPACED_ONLY);
fHintingMenu->AddItem(new BMenuItem(kMonospacedHintingLabel, message));
}
@ -270,8 +275,20 @@ AntialiasingSettingsView::_SetCurrentAntialiasing()
void
AntialiasingSettingsView::_SetCurrentHinting()
{
BMenuItem *item = fHintingMenu->FindItem(
fCurrentHinting ? kFullHintingLabel : kNoHintingLabel);
const char* label = NULL;
switch (fCurrentHinting) {
case HINTING_MODE_OFF:
label = kNoHintingLabel;
break;
case HINTING_MODE_ON:
label = kFullHintingLabel;
break;
case HINTING_MODE_MONOSPACED_ONLY:
label = kMonospacedHintingLabel;
break;
}
BMenuItem *item = fHintingMenu->FindItem(label);
if (item != NULL)
item->SetMarked(true);
}
@ -300,9 +317,9 @@ AntialiasingSettingsView::IsDefaultable()
bool
AntialiasingSettingsView::IsRevertable()
{
return (fCurrentSubpixelAntialiasing != fSavedSubpixelAntialiasing)
|| (fCurrentHinting != fSavedHinting)
|| (fCurrentAverageWeight != fSavedAverageWeight);
return fCurrentSubpixelAntialiasing != fSavedSubpixelAntialiasing
|| fCurrentHinting != fSavedHinting
|| fCurrentAverageWeight != fSavedAverageWeight;
}
@ -317,7 +334,7 @@ AntialiasingSettingsView::Revert()
fCurrentAverageWeight = fSavedAverageWeight;
set_subpixel_antialiasing(fCurrentSubpixelAntialiasing);
set_hinting(fCurrentHinting);
set_hinting_mode(fCurrentHinting);
set_average_weight(fCurrentAverageWeight);
_SetCurrentAntialiasing();

View File

@ -45,8 +45,8 @@ protected:
bool fSavedSubpixelAntialiasing;
bool fCurrentSubpixelAntialiasing;
bool fSavedHinting;
bool fCurrentHinting;
uint8 fSavedHinting;
uint8 fCurrentHinting;
unsigned char fSavedAverageWeight;
unsigned char fCurrentAverageWeight;
};

View File

@ -75,7 +75,7 @@ DesktopSettingsPrivate::_SetDefaults()
memcpy(fShared.colors, BPrivate::kDefaultColors, sizeof(rgb_color) * kNumColors);
gSubpixelAntialiasing = false;
gDefaultHinting = true;
gDefaultHintingMode = HINTING_MODE_ON;
gSubpixelAverageWeight = 120;
gSubpixelOrderingRGB = true;
}
@ -145,7 +145,7 @@ DesktopSettingsPrivate::_Load()
const char* family;
const char* style;
float size;
bool hinting;
int32 hinting;
if (settings.FindString("plain family", &family) == B_OK
&& settings.FindString("plain style", &style) == B_OK
&& settings.FindFloat("plain size", &size) == B_OK) {
@ -168,8 +168,8 @@ DesktopSettingsPrivate::_Load()
fFixedFont.SetStyle(fontStyle);
fFixedFont.SetSize(size);
}
if (settings.FindBool("hinting", &hinting) == B_OK) {
gDefaultHinting = hinting;
if (settings.FindInt32("hinting", &hinting) == B_OK) {
gDefaultHintingMode = hinting;
}
gFontManager->Unlock();
}
@ -321,7 +321,7 @@ DesktopSettingsPrivate::Save(uint32 mask)
settings.AddString("fixed style", fFixedFont.Style());
settings.AddFloat("fixed size", fFixedFont.Size());
settings.AddBool("hinting", gDefaultHinting);
settings.AddInt32("hinting", gDefaultHintingMode);
BFile file;
status = file.SetTo(path.Path(), B_CREATE_FILE | B_ERASE_FILE
@ -597,17 +597,17 @@ DesktopSettingsPrivate::SubpixelAntialiasing() const
void
DesktopSettingsPrivate::SetHinting(bool hinting)
DesktopSettingsPrivate::SetHinting(uint8 hinting)
{
gDefaultHinting = hinting;
gDefaultHintingMode = hinting;
Save(kFontSettings);
}
bool
uint8
DesktopSettingsPrivate::Hinting() const
{
return gDefaultHinting;
return gDefaultHintingMode;
}
@ -739,7 +739,7 @@ DesktopSettings::SubpixelAntialiasing() const
}
bool
uint8
DesktopSettings::Hinting() const
{
return fSettings->Hinting();
@ -847,7 +847,7 @@ LockedDesktopSettings::SetSubpixelAntialiasing(bool subpix)
void
LockedDesktopSettings::SetHinting(bool hinting)
LockedDesktopSettings::SetHinting(uint8 hinting)
{
fSettings->SetHinting(hinting);
}

View File

@ -54,7 +54,7 @@ class DesktopSettings {
rgb_color UIColor(color_which which) const;
bool SubpixelAntialiasing() const;
bool Hinting() const;
uint8 Hinting() const;
uint8 SubpixelAverageWeight() const;
bool IsSubpixelOrderingRegular() const;
@ -81,7 +81,7 @@ class LockedDesktopSettings : public DesktopSettings {
void SetUIColor(color_which which, const rgb_color color);
void SetSubpixelAntialiasing(bool subpix);
void SetHinting(bool hinting);
void SetHinting(uint8 hinting);
void SetSubpixelAverageWeight(uint8 averageWeight);
void SetSubpixelOrderingRegular(bool subpixelOrdering);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2005-2007, Haiku.
* Copyright 2005-2008, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -19,69 +19,73 @@ struct server_read_only_memory;
class DesktopSettingsPrivate {
public:
DesktopSettingsPrivate(server_read_only_memory* shared);
~DesktopSettingsPrivate();
public:
DesktopSettingsPrivate(
server_read_only_memory* shared);
~DesktopSettingsPrivate();
status_t Save(uint32 mask = kAllSettings);
status_t Save(uint32 mask = kAllSettings);
void SetDefaultPlainFont(const ServerFont& font);
const ServerFont& DefaultPlainFont() const;
void SetDefaultPlainFont(const ServerFont& font);
const ServerFont& DefaultPlainFont() const;
void SetDefaultBoldFont(const ServerFont& font);
const ServerFont& DefaultBoldFont() const;
void SetDefaultBoldFont(const ServerFont& font);
const ServerFont& DefaultBoldFont() const;
void SetDefaultFixedFont(const ServerFont& font);
const ServerFont& DefaultFixedFont() const;
void SetDefaultFixedFont(const ServerFont& font);
const ServerFont& DefaultFixedFont() const;
void SetScrollBarInfo(const scroll_bar_info &info);
const scroll_bar_info& ScrollBarInfo() const;
void SetScrollBarInfo(const scroll_bar_info &info);
const scroll_bar_info& ScrollBarInfo() const;
void SetMenuInfo(const menu_info &info);
const menu_info& MenuInfo() const;
void SetMenuInfo(const menu_info &info);
const menu_info& MenuInfo() const;
void SetMouseMode(mode_mouse mode);
mode_mouse MouseMode() const;
bool FocusFollowsMouse() const;
void SetMouseMode(mode_mouse mode);
mode_mouse MouseMode() const;
bool FocusFollowsMouse() const;
void SetShowAllDraggers(bool show);
bool ShowAllDraggers() const;
void SetShowAllDraggers(bool show);
bool ShowAllDraggers() const;
void SetWorkspacesCount(int32 number);
int32 WorkspacesCount() const;
void SetWorkspacesCount(int32 number);
int32 WorkspacesCount() const;
void SetWorkspacesMessage(int32 index, BMessage& message);
const BMessage* WorkspacesMessage(int32 index) const;
void SetWorkspacesMessage(int32 index,
BMessage& message);
const BMessage* WorkspacesMessage(int32 index) const;
void SetUIColor(color_which which, const rgb_color color);
rgb_color UIColor(color_which which) const;
void SetUIColor(color_which which,
const rgb_color color);
rgb_color UIColor(color_which which) const;
void SetSubpixelAntialiasing(bool subpix);
bool SubpixelAntialiasing() const;
void SetHinting(bool hinting);
bool Hinting() const;
void SetSubpixelAverageWeight(uint8 averageWeight);
uint8 SubpixelAverageWeight() const;
void SetSubpixelOrderingRegular(bool SubpixelOrdering);
bool IsSubpixelOrderingRegular() const;
void SetSubpixelAntialiasing(bool subpix);
bool SubpixelAntialiasing() const;
void SetHinting(uint8 hinting);
uint8 Hinting() const;
void SetSubpixelAverageWeight(uint8 averageWeight);
uint8 SubpixelAverageWeight() const;
void SetSubpixelOrderingRegular(
bool subpixelOrdering);
bool IsSubpixelOrderingRegular() const;
private:
void _SetDefaults();
status_t _Load();
status_t _GetPath(BPath& path);
private:
void _SetDefaults();
status_t _Load();
status_t _GetPath(BPath& path);
ServerFont fPlainFont;
ServerFont fBoldFont;
ServerFont fFixedFont;
ServerFont fPlainFont;
ServerFont fBoldFont;
ServerFont fFixedFont;
scroll_bar_info fScrollBarInfo;
menu_info fMenuInfo;
mode_mouse fMouseMode;
bool fShowAllDraggers;
int32 fWorkspacesCount;
BMessage fWorkspaceMessages[kMaxWorkspaces];
scroll_bar_info fScrollBarInfo;
menu_info fMenuInfo;
mode_mouse fMouseMode;
bool fShowAllDraggers;
int32 fWorkspacesCount;
BMessage fWorkspaceMessages[kMaxWorkspaces];
server_read_only_memory& fShared;
server_read_only_memory& fShared;
};
#endif /* DESKTOP_SETTINGS_PRIVATE_H */

View File

@ -123,7 +123,7 @@ FontCacheEntry::Init(const ServerFont& font)
// TODO: encoding from font
FT_Encoding charMap = FT_ENCODING_NONE;
bool hinting = gDefaultHinting; // TODO: font.Hinting();
bool hinting = font.Hinting();
if (!fEngine.Init(font.Path(), 0, font.Size(), charMap,
renderingType, hinting)) {
@ -220,7 +220,7 @@ FontCacheEntry::GenerateSignature(char* signature, const ServerFont& font)
// TODO: read more of these from the font
FT_Encoding charMap = FT_ENCODING_NONE;
bool hinting = gDefaultHinting; // TODO: font.Hinting();
bool hinting = font.Hinting();
uint8 averageWeight = gSubpixelAverageWeight;
sprintf(signature, "%ld,%u,%d,%d,%.1f,%d,%d",
@ -255,7 +255,7 @@ FontCacheEntry::_RenderTypeFor(const ServerFont& font)
|| font.FalseBoldWidth() != 0.0
|| font.Flags() & B_DISABLE_ANTIALIASING
|| font.Size() > 30
|| !gDefaultHinting) {
|| !font.Hinting()) {
renderingType = glyph_ren_outline;
}

View File

@ -2192,14 +2192,14 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} else
status = B_OK;
} else {
// this is perhaps not ideal - it assumes that if the
// this is perhaps not ideal - it assumes that if the
// workspace is not the active one, then pull the
// configuration from active and store it to the specified
// configuration from active and store it to the specified
// workspace. This is safer since it's assumed that the
// active workspace has a display mode that's usable,
// but at the same time the API implies that you can set
// a non-visible workspace to whatever mode you like
// TODO: decide what to do here.
// TODO: decide what to do here.
if (makeDefault)
fDesktop->StoreConfiguration(workspace);
}
@ -2585,12 +2585,14 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
case AS_SET_HINTING:
{
bool hinting;
if (link.Read<bool>(&hinting) == B_OK) {
uint8 hinting;
if (link.Read<uint8>(&hinting) == B_OK && hinting < 3) {
LockedDesktopSettings settings(fDesktop);
settings.SetHinting(hinting);
if (hinting != settings.Hinting()) {
settings.SetHinting(hinting);
fDesktop->Redraw();
}
}
fDesktop->Redraw();
break;
}
@ -2598,7 +2600,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
{
DesktopSettings settings(fDesktop);
fLink.StartMessage(B_OK);
fLink.Attach<bool>(settings.Hinting());
fLink.Attach<uint8>(settings.Hinting());
fLink.Flush();
break;
}

View File

@ -16,6 +16,7 @@
#include <Rect.h>
#include "FontFamily.h"
#include "GlobalSubpixelSettings.h"
#include "Transformable.h"
class BShape;
@ -109,7 +110,7 @@ class ServerFont {
{ return fStyle->GlyphCount(); }
uint16 CharMapCount() const
{ return fStyle->CharMapCount(); }
inline bool Hinting() const;
FT_Face GetTransformedFace(bool rotate,
bool shear) const;
@ -118,9 +119,9 @@ class ServerFont {
status_t GetGlyphShapes(const char charArray[],
int32 numChars, BShape *shapeArray[]) const;
status_t GetHasGlyphs(const char charArray[],
status_t GetHasGlyphs(const char charArray[],
int32 numBytes, bool hasArray[]) const;
status_t GetEdges(const char charArray[], int32 numBytes,
edge_info edgeArray[]) const;
@ -156,7 +157,7 @@ class ServerFont {
// FT_Face GetFTFace() const
// { return fStyle->FreeTypeFace(); };
BRect BoundingBox();
void GetHeight(font_height& height) const;
@ -182,4 +183,17 @@ protected:
uint32 fEncoding;
};
inline bool ServerFont::Hinting() const
{
switch (gDefaultHintingMode) {
case HINTING_MODE_OFF:
return false;
default:
case HINTING_MODE_ON:
return true;
case HINTING_MODE_MONOSPACED_ONLY:
return IsFixedWidth();
}
}
#endif /* SERVER_FONT_H */

View File

@ -9,6 +9,6 @@
// NOTE: all these are initialized in DesktopSettings.cpp
bool gSubpixelAntialiasing;
bool gDefaultHinting;
unsigned char gSubpixelAverageWeight;
uint8 gDefaultHintingMode;
uint8 gSubpixelAverageWeight;
bool gSubpixelOrderingRGB;

View File

@ -1,22 +1,30 @@
/*
* Copyright 2008, Andrej Spielmann <andrej.spielmann@seh.ox.ac.uk>.
* All rights reserved. Distributed under the terms of the MIT License.
*
* Global settings of the app server regarding antialiasing and font hinting
*
*/
#ifndef GLOBAL_SUBPIXEL_SETTINGS_H
#define GLOBAL_SUBPIXEL_SETTINGS_H
#include <SupportDefs.h>
// TODO: these global settings need to be removed - once we have more than one
// user, we also must support more than one setting. That's why there is a
// DesktopSettings class in the first place...
enum {
HINTING_MODE_OFF = 0,
HINTING_MODE_ON,
HINTING_MODE_MONOSPACED_ONLY
};
#define AVERAGE_BASED_SUBPIXEL_FILTERING
extern bool gSubpixelAntialiasing;
extern bool gDefaultHinting;
extern uint8 gDefaultHintingMode;
// The weight with which the average of the subpixels is applied to counter
// color fringes (0 = full sharpness ... 255 = grayscale anti-aliasing)
extern unsigned char gSubpixelAverageWeight;
extern uint8 gSubpixelAverageWeight;
// There are two types of LCD displays in general - the more common have
// sub - pixels physically ordered as RGB within a pixel, but some are BGR.
@ -25,5 +33,3 @@ extern unsigned char gSubpixelAverageWeight;
extern bool gSubpixelOrderingRGB;
#endif // GLOBAL_SUBPIXEL_SETTINGS_H