* Renaming or moving a directory within the known font directories is now

handled correctly.
* The path of moved styles is now updated (also when their parent directories
  are moved).
* FontManager::_AddPath() can no longer crash when you leave the _newDirectory
  parameter set to NULL.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17163 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-04-18 15:14:10 +00:00
parent a88c592fb3
commit 90984a161a
3 changed files with 52 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2005, Haiku.
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -15,9 +15,10 @@
#include "FontManager.h"
#include <FontPrivate.h>
#include FT_CACHE_H
#include <Entry.h>
const uint32 kInvalidFamilyFlags = ~0UL;
@ -139,7 +140,23 @@ FontStyle::GetHeight(float size, font_height& height) const
const char*
FontStyle::Path() const
{
return fPath.String();
return fPath.Path();
}
/*!
\brief Updates the path of the font style in case the style
has been moved around.
*/
void
FontStyle::UpdatePath(const node_ref& parentNodeRef)
{
entry_ref ref;
ref.device = parentNodeRef.device;
ref.directory = parentNodeRef.node;
ref.set_name(fPath.Leaf());
fPath.SetTo(&ref);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2005, Haiku.
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -14,6 +14,7 @@
#include <Locker.h>
#include <Node.h>
#include <ObjectList.h>
#include <Path.h>
#include <Rect.h>
#include <String.h>
@ -142,6 +143,8 @@ class FontStyle : public ReferenceCounting, public Hashable/*, public BLocker*/
uint16 PreservedFace(uint16) const;
const char* Path() const;
void UpdatePath(const node_ref& parentNodeRef);
void GetHeight(float size, font_height &heigth) const;
font_direction Direction() const
{ return B_FONT_LEFT_TO_RIGHT; }
@ -165,7 +168,7 @@ class FontStyle : public ReferenceCounting, public Hashable/*, public BLocker*/
private:
FT_Face fFreeTypeFace;
BString fName;
BString fPath;
BPath fPath;
node_ref fNodeRef;
FontFamily* fFamily;

View File

@ -205,13 +205,32 @@ FontManager::MessageReceived(BMessage* message)
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()) {
// there is a new directory to watch for us
_AddPath(entry);
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 {
// test, if the source directory is one of ours as well
nodeRef.node = fromNode;
font_directory* fromDirectory = _FindDirectory(nodeRef);
if (fromDirectory != NULL) {
// find style in source and move it to the target
nodeRef.node = node;
@ -219,6 +238,7 @@ FontManager::MessageReceived(BMessage* message)
if (style != NULL) {
fromDirectory->styles.RemoveItem(style, false);
directory->styles.AddItem(style);
style->UpdatePath(directory->directory);
}
FTRACE(("font moved"));
} else {
@ -598,7 +618,8 @@ FontManager::_AddPath(BEntry& entry, font_directory** _newDirectory)
font_directory* directory = _FindDirectory(nodeRef);
if (directory != NULL) {
*_newDirectory = directory;
if (_newDirectory)
*_newDirectory = directory;
return B_OK;
}