diff --git a/src/servers/app/FontFamily.cpp b/src/servers/app/FontFamily.cpp index b0dff35624..f689ca7edd 100644 --- a/src/servers/app/FontFamily.cpp +++ b/src/servers/app/FontFamily.cpp @@ -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 - #include FT_CACHE_H +#include + 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); } diff --git a/src/servers/app/FontFamily.h b/src/servers/app/FontFamily.h index b513a9c73f..19dbbb1436 100644 --- a/src/servers/app/FontFamily.h +++ b/src/servers/app/FontFamily.h @@ -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 #include #include +#include #include #include @@ -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; diff --git a/src/servers/app/FontManager.cpp b/src/servers/app/FontManager.cpp index 19429718d8..110fa643eb 100644 --- a/src/servers/app/FontManager.cpp +++ b/src/servers/app/FontManager.cpp @@ -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; }