[haiku-commits] r37413 - haiku/trunk/src/servers/app

  • From: pulkomandy@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 6 Jul 2010 22:52:10 +0200 (CEST)

Author: pulkomandy
Date: 2010-07-06 22:52:10 +0200 (Tue, 06 Jul 2010)
New Revision: 37413
Changeset: http://dev.haiku-os.org/changeset/37413/haiku

Modified:
   haiku/trunk/src/servers/app/FontCacheEntry.cpp
   haiku/trunk/src/servers/app/GlyphLayoutEngine.h
Log:
Minimal font overlay :
 * FontCacheEntry will not use the "empty" glyph from fonts anymore, so squares 
are not drawn anymore
 * GlyphLayoutEngine will try the VL Gothic font, if the requested font doesn't 
have any glyph fo the requested character. The 
caching for the fallback is suboptimal, and the font choice quite limited, but 
this allows at least japanese text to display 
properly on haiku out of the box.


Modified: haiku/trunk/src/servers/app/FontCacheEntry.cpp
===================================================================
--- haiku/trunk/src/servers/app/FontCacheEntry.cpp      2010-07-06 15:41:33 UTC 
(rev 37412)
+++ haiku/trunk/src/servers/app/FontCacheEntry.cpp      2010-07-06 20:52:10 UTC 
(rev 37413)
@@ -192,6 +192,8 @@
 FontCacheEntry::Glyph(uint32 glyphCode)
 {
        uint32 glyphIndex = fEngine.GlyphIndexForGlyphCode(glyphCode);
+       if (glyphIndex==0)
+               return NULL;
        const GlyphCache* glyph = fGlyphCache->FindGlyph(glyphIndex);
        if (glyph) {
                return glyph;

Modified: haiku/trunk/src/servers/app/GlyphLayoutEngine.h
===================================================================
--- haiku/trunk/src/servers/app/GlyphLayoutEngine.h     2010-07-06 15:41:33 UTC 
(rev 37412)
+++ haiku/trunk/src/servers/app/GlyphLayoutEngine.h     2010-07-06 20:52:10 UTC 
(rev 37413)
@@ -13,6 +13,7 @@
 
 #include "FontCache.h"
 #include "FontCacheEntry.h"
+#include "FontManager.h"
 #include "ServerFont.h"
 
 #include <ctype.h>
@@ -95,6 +96,7 @@
        return false;
 }
 
+
 // LayoutGlyphs
 template<class GlyphConsumer>
 inline bool
@@ -107,6 +109,7 @@
        // TODO: implement spacing modes
 
        FontCacheEntry* entry = NULL;
+       FontCacheEntry* fallbackEntry = NULL;
        bool needsWriteLock = false;
        if (cacheReference) {
                entry = cacheReference->Entry();
@@ -171,11 +174,51 @@
 
                const GlyphCache* glyph = entry->Glyph(charCode);
                if (glyph == NULL) {
-                       fprintf(stderr, "failed to load glyph for 0x%04lx 
(%c)\n", charCode,
-                               isprint(charCode) ? (char)charCode : '-');
+                       // Try to find a suitable glyph in another font
+                       FontCache* cache = FontCache::Default();
+                       bool needsWriteLock = false;
+                       ServerFont f(*(gFontManager->GetStyleByIndex("VL 
Gothic",0)));
+                               // We always try to get the glyph from VL 
Gothic, so we can display
+                               // japanese character. Other scripts (indian, 
...) should be handled
+                               // too, perhaps with a charcode > font mapping.
+                       fallbackEntry = cache->FontCacheEntryFor(f);
+                       if (!fallbackEntry || !fallbackEntry->ReadLock()) {
+                               cache->Recycle(fallbackEntry);
+                               continue;
+                       }
 
-                       consumer.ConsumeEmptyGlyph(index, charCode, x, y);
-                       continue;
+                       needsWriteLock = !fallbackEntry->HasGlyphs(utf8String, 
length);
+
+                       if (needsWriteLock) {
+                               fallbackEntry->ReadUnlock();
+                               if (!fallbackEntry->WriteLock()) {
+                                       cache->Recycle(fallbackEntry);
+                                       continue;
+                               }
+                       }
+
+                       bool consumed = true;
+                       glyph = fallbackEntry->Glyph(charCode);
+                       if (glyph != NULL && !consumer.ConsumeGlyph(index, 
charCode, glyph, fallbackEntry, x, y)) {
+                               advanceX = 0;
+                               advanceY = 0;
+                               consumed = false;
+                       }
+
+                       if (needsWriteLock)
+                               fallbackEntry->WriteUnlock();
+                       else
+                               fallbackEntry->ReadUnlock();
+
+                       FontCache::Default()->Recycle(fallbackEntry);
+
+                       if (glyph == NULL) {
+                               consumer.ConsumeEmptyGlyph(index, charCode, x, 
y);
+                               continue;
+                       }
+
+                       if (!consumed)
+                               break;
                }
 
                if (!consumer.ConsumeGlyph(index, charCode, glyph, entry, x, 
y)) {


Other related posts: