本文整理汇总了C++中FontStyle类的典型用法代码示例。如果您正苦于以下问题:C++ FontStyle类的具体用法?C++ FontStyle怎么用?C++ FontStyle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FontStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
FontStyle* FontStyleManager::requestFontStyle(string style){
list <FontStyle*>::iterator it;
for (it = mFontStyle.begin();it != mFontStyle.end();it++){
if ((*it)->getName() == style){
return (*it);
}
}
/*File f(style+".xml", "media\\fonts");
if (f.error() != FILE_OK){
throw ("Font Style Not Found : "+style);
}
XML* xml = new XML(f.getStrContent());*/
XML* xml = new XML(style+".xml", "media\\fonts");
XMLIterator xIt(xml);
xIt.setElemName("fontstyle");
xIt.gotoZero();
xIt.gotoNext();
FontStyle* fs = new FontStyle(style, xIt.getElem().getString("font"), xIt.getElem().getFloat("size"));
Ogre::ColourValue prim = colourValueFromString(xIt.getElem().getString("colour"));
Ogre::ColourValue sec = colourValueFromString(xIt.getElem().getString("shadow"));
fs->setColour(prim, sec);
delete xml;
mFontStyle.push_back(fs);
return fs;
}
示例2: SaveList
/*!
\brief This saves all family names and styles to the file specified in
ServerConfig.h as SERVER_FONT_LIST as a flattened BMessage.
This operation is not done very often because the access to disk adds a significant
performance hit.
The format for storage consists of two things: an array of strings with the name 'family'
and a number of small string arrays which have the name of the font family. These are
the style lists.
Additionally, any fonts which have bitmap strikes contained in them or any fonts which
are fixed-width are named in the arrays 'tuned' and 'fixed'.
*/
void FontServer::SaveList(void)
{
int32 famcount=0, stycount=0,i=0,j=0;
FontFamily *fam;
FontStyle *sty;
BMessage fontmsg, familymsg('FONT');
BString famname, styname, extraname;
bool fixed,tuned;
famcount=families->CountItems();
for(i=0; i<famcount; i++)
{
fam=(FontFamily*)families->ItemAt(i);
fixed=false;
tuned=false;
if(!fam)
continue;
famname=fam->Name();
// Add the family to the message
familymsg.AddString("name",famname);
stycount=fam->CountStyles();
for(j=0;j<stycount;j++)
{
styname.SetTo(fam->GetStyle(j));
if(styname.CountChars()>0)
{
// Add to list
familymsg.AddString("styles", styname);
// Check to see if it has prerendered strikes (has "tuned" fonts)
sty=fam->GetStyle(styname.String());
if(!sty)
continue;
if(sty->HasTuned() && sty->IsScalable())
tuned=true;
// Check to see if it is fixed-width
if(sty->IsFixedWidth())
fixed=true;
}
}
if(tuned)
familymsg.AddBool("tuned",true);
if(fixed)
familymsg.AddBool("fixed",true);
fontmsg.AddMessage("family",&familymsg);
familymsg.MakeEmpty();
}
BFile file(SERVER_FONT_LIST,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
if(file.InitCheck()==B_OK)
fontmsg.Flatten(&file);
}
示例3: computeMatch
// Compute a matching metric between two styles - 0 is an exact match
static int computeMatch(FontStyle style1, FontStyle style2) {
if (style1 == style2)
return 0;
int score = abs(style1.getWeight() - style2.getWeight());
if (style1.getItalic() != style2.getItalic()) {
score += 2;
}
return score;
}
示例4: key
FontFamily*
FontManager::GetFamily(uint16 familyID) const
{
FontKey key(familyID, 0);
FontStyle* style = (FontStyle*)fStyleHashTable.GetValue(key);
if (style != NULL)
return style->Family();
return NULL;
}
示例5: computeFakery
static FontFakery computeFakery(FontStyle wanted, FontStyle actual) {
// If desired weight is semibold or darker, and 2 or more grades
// higher than actual (for example, medium 500 -> bold 700), then
// select fake bold.
int wantedWeight = wanted.getWeight();
bool isFakeBold =
wantedWeight >= 6 && (wantedWeight - actual.getWeight()) >= 2;
bool isFakeItalic = wanted.getItalic() && !actual.getItalic();
return FontFakery(isFakeBold, isFakeItalic);
}
示例6:
/*!
\brief Destructor
Deletes all attached styles. Note that a FontFamily must only be deleted
by the font manager.
*/
FontFamily::~FontFamily()
{
for (int32 i = fStyles.CountItems(); i-- > 0;) {
FontStyle* style = fStyles.RemoveItemAt(i);
// we remove us before deleting the style, so that the font manager
// is not contacted to remove the style from us
style->_SetFontFamily(NULL, -1);
delete style;
}
}
示例7:
FontStyle*
FontManager::font_directory::FindStyle(const node_ref& nodeRef) const
{
for (int32 i = styles.CountItems(); i-- > 0;) {
FontStyle* style = styles.ItemAt(i);
if (nodeRef == style->NodeRef())
return style;
}
return NULL;
}
示例8: Shear
/*!
\brief Constructor
\param style Style object to which the ServerFont belongs
\param size Character size in points
\param rotation Rotation in degrees
\param shear Shear (slant) in degrees. 45 <= shear <= 135
\param flags Style flags as defined in <Font.h>
\param spacing String spacing flag as defined in <Font.h>
*/
ServerFont::ServerFont(FontStyle& style, float size, float rotation,
float shear, float falseBoldWidth, uint16 flags, uint8 spacing)
:
fStyle(&style),
fSize(size),
fRotation(rotation),
fShear(shear),
fFalseBoldWidth(falseBoldWidth),
fBounds(0, 0, 0, 0),
fFlags(flags),
fSpacing(spacing),
fDirection(style.Direction()),
fFace(style.Face()),
fEncoding(B_UNICODE_UTF8)
{
fStyle->Acquire();
}
示例9: Rect
Rect glArchivItem_Font::getBounds(DrawPoint pos, const std::string& text, FontStyle format) const
{
if(text.empty())
return Rect(Position(pos), 0, 0);
unsigned width = getWidth(text);
unsigned numLines = static_cast<unsigned>(std::count(text.begin(), text.end(), '\n')) + 1;
Rect result(Position(pos), width, numLines * getHeight());
Position offset(0, 0);
if(format.is(FontStyle::RIGHT))
offset.x = width;
else if(format.is(FontStyle::CENTER))
offset.x = width / 2;
if(format.is(FontStyle::BOTTOM))
offset.y = getHeight();
else if(format.is(FontStyle::VCENTER))
offset.y = getHeight() / 2;
result.move(-offset);
return result;
}
示例10:
/*!
\brief Sets the ServerFont instance to whatever font is specified
This method will lock the font manager.
\param familyID ID number of the family to set
\param styleID ID number of the style to set
\return B_OK if successful, B_ERROR if not
*/
status_t
ServerFont::SetFamilyAndStyle(uint16 familyID, uint16 styleID)
{
FontStyle* style = NULL;
if (gFontManager->Lock()) {
style = gFontManager->GetStyle(familyID, styleID);
if (style != NULL)
style->Acquire();
gFontManager->Unlock();
}
if (style == NULL)
return B_ERROR;
SetStyle(style);
style->Release();
return B_OK;
}
示例11: TypefaceImpl_resolveDefault
void MinikinUtils::doLayout(Layout* layout, const Paint* paint, int bidiFlags, TypefaceImpl* typeface,
const uint16_t* buf, size_t start, size_t count, size_t bufSize) {
TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface);
layout->setFontCollection(resolvedFace->fFontCollection);
FontStyle resolved = resolvedFace->fStyle;
/* Prepare minikin FontStyle */
std::string lang = paint->getTextLocale();
FontLanguage minikinLang(lang.c_str(), lang.size());
FontVariant minikinVariant = (paint->getFontVariant() == VARIANT_ELEGANT) ? VARIANT_ELEGANT
: VARIANT_COMPACT;
FontStyle minikinStyle(minikinLang, minikinVariant, resolved.getWeight(), resolved.getItalic());
/* Prepare minikin Paint */
MinikinPaint minikinPaint;
minikinPaint.size = (int)/*WHY?!*/paint->getTextSize();
minikinPaint.scaleX = paint->getTextScaleX();
minikinPaint.skewX = paint->getTextSkewX();
minikinPaint.letterSpacing = paint->getLetterSpacing();
minikinPaint.paintFlags = MinikinFontSkia::packPaintFlags(paint);
minikinPaint.fontFeatureSettings = paint->getFontFeatureSettings();
layout->doLayout(buf, start, count, bufSize, bidiFlags, minikinStyle, minikinPaint);
}
示例12: FamilyID
status_t
ServerFont::SetFace(uint16 face)
{
// TODO: This needs further investigation. The face variable is actually
// flags, but some of them are not enforcable at the same time. Also don't
// confuse the Be API "face" with the Freetype face, which is just an
// index in case a single font file exports multiple font faces. The
// FontStyle class takes care of mapping the font style name to the Be
// API face flags in FontStyle::_TranslateStyleToFace().
FontStyle* style = NULL;
uint16 familyID = FamilyID();
if (gFontManager->Lock()) {
int32 count = gFontManager->CountStyles(familyID);
for (int32 i = 0; i < count; i++) {
style = gFontManager->GetStyleByIndex(familyID, i);
if (style == NULL)
break;
if (style->Face() == face) {
style->Acquire();
break;
} else
style = NULL;
}
gFontManager->Unlock();
}
if (!style)
return B_ERROR;
SetStyle(style);
style->Release();
return B_OK;
}
示例13: applyBaseStyle
void FontStyle::applyBaseStyle(const FontStyle& baseStyle, const ArgList& args)
{
setDefaultedAttr(m_sName, "font", args, baseStyle.getFont());
setDefaultedAttr(m_sVariant, "variant", args, baseStyle.getFontVariant());
setDefaultedAttr(m_Color, "color", args, baseStyle.getColor());
setDefaultedAttr(m_AAGamma, "aagamma", args, baseStyle.getAAGamma());
setDefaultedAttr(m_Size, "fontsize", args, baseStyle.getFontSize());
setDefaultedAttr(m_Indent, "indent", args, baseStyle.getIndent());
setDefaultedAttr(m_LineSpacing, "linespacing", args, baseStyle.getLineSpacing());
setDefaultedAttr(m_Alignment, "alignment", args, baseStyle.getAlignmentVal());
setDefaultedAttr(m_WrapMode, "wrapmode", args, baseStyle.getWrapModeVal());
setDefaultedAttr(m_bJustify, "justify", args, baseStyle.getJustify());
setDefaultedAttr(m_LetterSpacing, "letterspacing", args,
baseStyle.getLetterSpacing());
setDefaultedAttr(m_bHint, "hint", args, baseStyle.getHint());
}
示例14: switch
void
FontManager::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_NODE_MONITOR:
{
// TODO: support removing fonts!
int32 opcode;
if (message->FindInt32("opcode", &opcode) != B_OK)
return;
switch (opcode) {
case B_ENTRY_CREATED:
{
const char* name;
node_ref nodeRef;
if (message->FindInt32("device", &nodeRef.device) != B_OK
|| message->FindInt64("directory", &nodeRef.node) != B_OK
|| message->FindString("name", &name) != B_OK)
break;
// TODO: make this better (possible under Haiku)
snooze(100000);
// let the font be written completely before trying to open it
BEntry entry;
if (set_entry(nodeRef, name, entry) != B_OK)
break;
if (entry.IsDirectory()) {
// a new directory to watch for us
_AddPath(entry);
} else {
// a new font
font_directory* directory = _FindDirectory(nodeRef);
if (directory == NULL) {
// unknown directory? how come?
break;
}
_AddFont(*directory, entry);
}
break;
}
case B_ENTRY_MOVED:
{
// has the entry been moved into a monitored directory or has
// it been removed from one?
const char* name;
node_ref nodeRef;
uint64 fromNode;
uint64 node;
if (message->FindInt32("device", &nodeRef.device) != B_OK
|| message->FindInt64("to directory", &nodeRef.node) != B_OK
|| message->FindInt64("from directory", (int64 *)&fromNode) != B_OK
|| message->FindInt64("node", (int64 *)&node) != B_OK
|| message->FindString("name", &name) != B_OK)
break;
font_directory* directory = _FindDirectory(nodeRef);
BEntry entry;
if (set_entry(nodeRef, name, entry) != B_OK)
break;
if (directory != NULL) {
// something has been added to our watched font directories
// test, if the source directory is one of ours as well
nodeRef.node = fromNode;
font_directory* fromDirectory = _FindDirectory(nodeRef);
if (entry.IsDirectory()) {
if (fromDirectory == NULL) {
// there is a new directory to watch for us
_AddPath(entry);
FTRACE("new directory moved in");
} else {
// A directory from our watched directories has
// been renamed or moved within the watched
// directories - we only need to update the
// path names of the styles in that directory
nodeRef.node = node;
directory = _FindDirectory(nodeRef);
if (directory != NULL) {
for (int32 i = 0; i < directory->styles.CountItems(); i++) {
FontStyle* style = directory->styles.ItemAt(i);
style->UpdatePath(directory->directory);
}
}
FTRACE("directory renamed");
}
} else {
if (fromDirectory != NULL) {
// find style in source and move it to the target
nodeRef.node = node;
FontStyle* style = fromDirectory->FindStyle(nodeRef);
if (style != NULL) {
//.........这里部分代码省略.........
示例15: _GetPath
status_t
DesktopSettingsPrivate::_Load()
{
// TODO: add support for old app_server_settings file as well
BPath basePath;
status_t status = _GetPath(basePath);
if (status < B_OK)
return status;
// read workspaces settings
BPath path(basePath);
path.Append("workspaces");
BFile file;
status = file.SetTo(path.Path(), B_READ_ONLY);
if (status == B_OK) {
BMessage settings;
status = settings.Unflatten(&file);
if (status == B_OK) {
int32 columns;
int32 rows;
if (settings.FindInt32("columns", &columns) == B_OK
&& settings.FindInt32("rows", &rows) == B_OK) {
_ValidateWorkspacesLayout(columns, rows);
fWorkspacesColumns = columns;
fWorkspacesRows = rows;
}
int32 i = 0;
while (i < kMaxWorkspaces && settings.FindMessage("workspace",
i, &fWorkspaceMessages[i]) == B_OK) {
i++;
}
}
}
// read font settings
path = basePath;
path.Append("fonts");
status = file.SetTo(path.Path(), B_READ_ONLY);
if (status == B_OK) {
BMessage settings;
status = settings.Unflatten(&file);
if (status == B_OK && gFontManager->Lock()) {
const char* family;
const char* style;
float size;
if (settings.FindString("plain family", &family) == B_OK
&& settings.FindString("plain style", &style) == B_OK
&& settings.FindFloat("plain size", &size) == B_OK) {
FontStyle* fontStyle = gFontManager->GetStyle(family, style);
fPlainFont.SetStyle(fontStyle);
fPlainFont.SetSize(size);
}
if (settings.FindString("bold family", &family) == B_OK
&& settings.FindString("bold style", &style) == B_OK
&& settings.FindFloat("bold size", &size) == B_OK) {
FontStyle* fontStyle = gFontManager->GetStyle(family, style);
fBoldFont.SetStyle(fontStyle);
fBoldFont.SetSize(size);
}
if (settings.FindString("fixed family", &family) == B_OK
&& settings.FindString("fixed style", &style) == B_OK
&& settings.FindFloat("fixed size", &size) == B_OK) {
FontStyle* fontStyle = gFontManager->GetStyle(family, style);
if (fontStyle != NULL && fontStyle->IsFixedWidth())
fFixedFont.SetStyle(fontStyle);
fFixedFont.SetSize(size);
}
int32 hinting;
if (settings.FindInt32("hinting", &hinting) == B_OK)
gDefaultHintingMode = hinting;
gFontManager->Unlock();
}
}
// read mouse settings
path = basePath;
path.Append("mouse");
status = file.SetTo(path.Path(), B_READ_ONLY);
if (status == B_OK) {
BMessage settings;
status = settings.Unflatten(&file);
if (status == B_OK) {
int32 mode;
if (settings.FindInt32("mode", &mode) == B_OK)
fMouseMode = (mode_mouse)mode;
int32 focusFollowsMouseMode;
//.........这里部分代码省略.........