r15890 by pierremarc - Fixed many minor issues regarding positionning of shaped glyphs
scribus-commit
scribus-commit at lists.scribus.net
Wed Nov 17 18:43:27 CET 2010
Author: pierremarc
Date: Wed Nov 17 17:43:27 2010
New Revision: 15890
URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15890
Log:
Fixed many minor issues regarding positionning of shaped glyphs
Modified:
branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
branches/ScribusOIF/scribus/fonts/scface_ttf.h
branches/ScribusOIF/scribus/langmgr.cpp
branches/ScribusOIF/scribus/langmgr.h
branches/ScribusOIF/scribus/text/boxes.cpp
branches/ScribusOIF/scribus/text/glyphstore.cpp
branches/ScribusOIF/scribus/text/shaper.cpp
Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15890&path=/branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface_ttf.cpp (original)
+++ branches/ScribusOIF/scribus/fonts/scface_ttf.cpp Wed Nov 17 17:43:27 2010
@@ -527,8 +527,6 @@
return ret;
}
-// TODO move it to a better place
-QMap<QString, QPair<hb_tag_t, hb_tag_t> > ScFace_ttf::scLangToTags;
QMap<QString, LanguageCodes> ScFace_ttf::icuLangList;
QMap<QString, ScriptCodes> ScFace_ttf::scriptTagToICUCode;
@@ -744,18 +742,18 @@
if(item >= itemCount)
return -1;
const TextStore * story(gs->story());
- QString language(story->charStyle(gs->itemTextPosition(item)).language());
+ LanguageManager * lm(LanguageManager::instance());
+ QString language(lm->getAbbrevFromLang(story->charStyle(gs->itemTextPosition(item)).language(), false, false));
bool isAuto(story->charStyle(gs->itemTextPosition(item)).autoShape());
double fSize(story->charStyle(gs->itemTextPosition(item)).fontSize() /10.0);
int itemPos(gs->itemTextPosition(item));
if(isAuto)
{
- LanguageManager *lm(LanguageManager::instance());
- hb_tag_t scriptTag = scLangToTags[language].first;
+ hb_tag_t scriptTag = stringToTag(lm->getScriptTag( language ));
LEErrorCode err(LE_NO_ERROR);
LayoutEngine * icuLE = LayoutEngine::layoutEngineFactory( icuFont,
scriptTagToICUCode.value( tagToString(scriptTag) ),
- icuLangList.value(lm->getIsoLangFromAbbr(lm->getAbbrevFromLang(language))),
+ icuLangList.value(lm->getIsoLangFromAbbr(language)),
err);
err = LE_NO_ERROR;
int sCount (gs->itemCharCount(item));
@@ -771,29 +769,47 @@
icuLE->reset();
int glAllocated = icuLE->layoutChars( ts, 0, sCount , sCount, false, 0, 0, err );
- LEGlyphID *glyphs = new LEGlyphID[glAllocated];
- le_int32 *indices = new le_int32[glAllocated];
- float *positions = new float[ ( glAllocated * 2 ) + 2];
+ le_int32 gCount(icuLE->getGlyphCount());
+ LEGlyphID *glyphs = new LEGlyphID[gCount];
+ le_int32 *indices = new le_int32[gCount];
+// float *positions = new float[ ( glAllocated * 2 ) + 2];
icuLE->getGlyphs ( glyphs, err );
icuLE->getCharIndices ( indices, err );
- icuLE->getGlyphPositions ( positions, err );
+// icuLE->getGlyphPositions ( positions, err );
float stackX ( 0.0 );
float stackY ( 0.0 );
QList<GlyphLayout> glList;
QList<le_int32> charList;
double sHeight((m_ascent - m_descent) * fSize);
- for ( int gIdx ( 0 ); gIdx < glAllocated ; ++gIdx )
+ float icuX(0);
+ float icuY(0);
+ float icuFwdX(0);
+ float icuFwdY(0);
+ for ( le_int32 gIdx ( 0 ); gIdx < gCount ; ++gIdx )
{
if(glyphs[gIdx] != 0xFFFF)
{
+ icuLE->getGlyphPosition(gIdx, icuX, icuY, err);
+ le_int32 nextIdx(gIdx + 1);
+ while((glyphs[nextIdx] == 0xFFFF) && (nextIdx < gCount))
+ ++nextIdx;
+ icuLE->getGlyphPosition(nextIdx, icuFwdX, icuFwdY, err);
+
+ if(err != LE_NO_ERROR)
+ continue;
GlyphLayout curGlyph;
curGlyph.glyph = glyphs[gIdx];
- curGlyph.xadvance = (positions[ ( gIdx + 1 ) * 2] * fSize / m_uniEM) - stackX;
- curGlyph.yoffset = ((stackY - positions[ ( ( gIdx + 1 ) * 2 ) + 1]) * fSize / m_uniEM) + sHeight;
- curGlyph.xoffset = curGlyph.yadvance = 0;
- stackX += curGlyph.xadvance;
- stackY = positions[ ( ( gIdx + 1 ) * 2 ) + 1];
+// curGlyph.xadvance = (positions[ ( gIdx + 1 ) * 2] * fSize / m_uniEM) - stackX;
+// curGlyph.yoffset = ((stackY - positions[ ( ( gIdx + 1 ) * 2 ) + 1]) * fSize / m_uniEM) + sHeight;
+ curGlyph.xadvance = glyphWidth(curGlyph.glyph, fSize);
+ curGlyph.xoffset = stackX;
+ curGlyph.yoffset = (icuY - stackY) * fSize / m_uniEM;
+ curGlyph.yadvance = 0;
+ stackY = icuFwdY;
+ stackX = ((icuFwdX - icuX) * fSize / m_uniEM) - curGlyph.xadvance;
+// stackX += curGlyph.xadvance;
+// stackY = positions[ ( ( gIdx + 1 ) * 2 ) + 1];
glList << curGlyph;
charList << indices[gIdx];
// qDebug()<<"icu"<<text.at(indices[gIdx])<< itemPos + indices[gIdx] << curGlyph.glyph <<curGlyph.xadvance <<curGlyph.yoffset ;
@@ -804,7 +820,7 @@
delete[] ts;
delete[] glyphs;
delete[] indices;
- delete[] positions;
+// delete[] positions;
gs->itemSetGlyphCount(item, glList.count());
GlyphLayout* curGlyph(gs->itemGlyphStart(item));
for(unsigned int i(0); i < glList.count(); ++i)
@@ -902,10 +918,11 @@
QList<unsigned int> ScFace_ttf::getlookupIndex(const QString &table, const QString &language, const QString &feature) const
{
hb_tag_t t = (table == QString("GSUB")) ? HB_OT_TAG_GSUB : HB_OT_TAG_GPOS;
- if(scLangToTags.contains(language))
- {
- hb_tag_t scriptTag = scLangToTags[language].first;
- hb_tag_t langTag = scLangToTags[language].second;
+ LanguageManager * lm(LanguageManager::instance());
+// if(scLangToTags.contains(language))
+ {
+ hb_tag_t scriptTag = stringToTag(lm->getScriptTag( language ));
+ hb_tag_t langTag = stringToTag(lm->getLangTag( language ));
if(feature.isEmpty())
{
// If no specific feature has been asked for, we return required feature for this language.
@@ -967,19 +984,19 @@
void ScFace_ttf::fillLangToTag()
{
- if(!scLangToTags.isEmpty())
+ if(!icuLangList.isEmpty())
return;
- LanguageManager *lm(LanguageManager::instance());
- QStringList langs;
- lm->fillInstalledStringList(&langs, false);
- // Latin scripts
- foreach(const QString& lang, langs)
- {
- QString abbr(lm->getAbbrevFromLang(lang));
- scLangToTags[lm->getLangFromTransLang(lang)] = qMakePair(HB_TAG('l','a','t','n'),
- hb_ot_tag_from_language(hb_language_from_string(abbr.toAscii().data())));
- }
+// LanguageManager *lm(LanguageManager::instance());
+// QStringList langs;
+// lm->fillInstalledStringList(&langs, false);
+// // Latin scripts
+// foreach(const QString& lang, langs)
+// {
+// QString abbr(lm->getAbbrevFromLang(lang));
+// scLangToTags[lm->getLangFromTransLang(lang)] = qMakePair(HB_TAG('l','a','t','n'),
+// hb_ot_tag_from_language(hb_language_from_string(abbr.toAscii().data())));
+// }
icuLangList.insert(QString("afk"), afkLanguageCode);
icuLangList.insert(QString("ara"), araLanguageCode);
Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15890&path=/branches/ScribusOIF/scribus/fonts/scface_ttf.h
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface_ttf.h (original)
+++ branches/ScribusOIF/scribus/fonts/scface_ttf.h Wed Nov 17 17:43:27 2010
@@ -118,7 +118,6 @@
int shapeText( GlyphStore* gs, unsigned int item) const;
private:
- static QMap<QString, QPair<hb_tag_t, hb_tag_t> > scLangToTags;
static QMap<QString, LanguageCodes> icuLangList;
static QMap<QString, ScriptCodes> scriptTagToICUCode;
void fillLangToTag();
Modified: branches/ScribusOIF/scribus/langmgr.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15890&path=/branches/ScribusOIF/scribus/langmgr.cpp
==============================================================================
--- branches/ScribusOIF/scribus/langmgr.cpp (original)
+++ branches/ScribusOIF/scribus/langmgr.cpp Wed Nov 17 17:43:27 2010
@@ -316,8 +316,23 @@
isoLang.insert(QString("za"), QString("zha"));
isoLang.insert(QString("zu"), QString("zul"));
- RTLLangs << QString("ar");
- RTLLangs << QString("he");
+ // Following lists and maps are somehow reversed (if possible), meaning that we list only what deviates from default (lazyness inside?)
+
+ // default is LTR
+ RTLLang << QString("ar");
+ RTLLang << QString("he");
+
+ // http://www.microsoft.com/typography/otspec/scripttags.htm
+ // default is "latn"
+ scriptTag.insert(QString("ar"), QString("arab"));
+ // TODO_OIF ...continue
+
+ // http://www.microsoft.com/typography/otspec/languagetags.htm
+ // default is "DFLT"
+ // note that a tag _MUST_ be 4 chars long (padded with space)
+ langTag.insert(QString("ar"), QString("ARA "));
+ // TODO_OIF ...continue
+
}
@@ -510,7 +525,7 @@
bool LanguageManager::isRightToLeft(const QString &langAbbr)
{
- return RTLLangs.contains(langAbbr);
+ return RTLLang.contains(langAbbr);
}
LanguageManager::~LanguageManager()
@@ -538,6 +553,18 @@
}
-
-
-
+const QString LanguageManager::getScriptTag(const QString &abbr)
+{
+ if(scriptTag.contains(abbr))
+ return scriptTag.value(abbr);
+ return QString("latn");
+}
+
+const QString LanguageManager::getLangTag(const QString &abbr)
+{
+ if(langTag.contains(abbr))
+ return langTag.value(abbr);
+ return QString("DFLT");
+}
+
+
Modified: branches/ScribusOIF/scribus/langmgr.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15890&path=/branches/ScribusOIF/scribus/langmgr.h
==============================================================================
--- branches/ScribusOIF/scribus/langmgr.h (original)
+++ branches/ScribusOIF/scribus/langmgr.h Wed Nov 17 17:43:27 2010
@@ -53,6 +53,8 @@
void printInstalledList();
QString numericSequence(QString seq);
bool isRightToLeft(const QString& langAbbr);
+ const QString getScriptTag(const QString& abbr);
+ const QString getLangTag(const QString& abbr);
void addHyphLang(const QString& lang, const QString& filename);
@@ -64,7 +66,9 @@
QMap<QString, QString> installedLangList;
QMap<QString, QString> hyphLangList; // <lang abbreviated, dict filename>
QMap<QString, QString> isoLang; // <lang abbreviated, iso639-2 abbreviation>
- QStringList RTLLangs;
+ QStringList RTLLang;
+ QMap<QString, QString> scriptTag; // <lang abbreviated, script tag>
+ QMap<QString, QString> langTag; // <lang abbreviated, lang tag>
void generateLangList();
void generateInstalledLangList();
Modified: branches/ScribusOIF/scribus/text/boxes.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15890&path=/branches/ScribusOIF/scribus/text/boxes.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/boxes.cpp (original)
+++ branches/ScribusOIF/scribus/text/boxes.cpp Wed Nov 17 17:43:27 2010
@@ -466,7 +466,7 @@
GlyphLayout* layout = cluster.glyphs();
uint glyph = layout->glyph;
if(rtl)
- p->translate(-layout->xadvance, 0);
+ p->translate(-(layout->xadvance + layout->xoffset), 0);
// qDebug() << "render pos"<< cluster.textPosition()<<"glyph" << glyph << "width" << layout->xadvance << "font" << style.font().scName() << "@" << x() << y() ;
if ((renderOptions.showControls) &&
(glyph == style.font().char2CMap(QChar(' ')) || glyph >= ScFace::CONTROL_GLYPHS))
@@ -521,7 +521,7 @@
}
*/
if(!rtl)
- p->translate(layout->xadvance, 0);
+ p->translate(layout->xadvance + layout->xoffset, 0);
if(m_glyphs->haveNext(cluster))
cluster = m_glyphs->next(cluster);
else
Modified: branches/ScribusOIF/scribus/text/glyphstore.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15890&path=/branches/ScribusOIF/scribus/text/glyphstore.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/glyphstore.cpp (original)
+++ branches/ScribusOIF/scribus/text/glyphstore.cpp Wed Nov 17 17:43:27 2010
@@ -247,7 +247,7 @@
double res = 0.0;
const GlyphLayout* end = itemGlyphStart(i) + itemGlyphCount(i);
for (const GlyphLayout* p = itemGlyphStart(i); p < end; ++p)
- res += p->xadvance;
+ res += p->xadvance + p->xoffset;
return res;
}
@@ -384,7 +384,7 @@
uint nglyphs = glyphCount(c);
for (uint i=0; i < nglyphs; ++i)
{
- result += c.glyphs()[i].xadvance;
+ result += c.glyphs()[i].xadvance + c.glyphs()[i].xoffset;
}
return result;
}
Modified: branches/ScribusOIF/scribus/text/shaper.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15890&path=/branches/ScribusOIF/scribus/text/shaper.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/shaper.cpp (original)
+++ branches/ScribusOIF/scribus/text/shaper.cpp Wed Nov 17 17:43:27 2010
@@ -79,7 +79,8 @@
foreach(uint it, items)
{
- if(story->charStyle(gs->itemTextPosition(it)).font().type() == ScFace::OTF)
+ if((story->charStyle(gs->itemTextPosition(it)).font().type() == ScFace::OTF)
+ || (story->charStyle(gs->itemTextPosition(it)).font().type() == ScFace::TTF))
{
story->charStyle(gs->itemTextPosition(it)).font().shapeText(gs, it);
}
More information about the scribus-commit
mailing list