OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 { | 979 { |
980 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u sed by the | 980 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u sed by the |
981 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis mark drawing function. | 981 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis mark drawing function. |
982 | 982 |
983 float* advances = currentRun->advances(); | 983 float* advances = currentRun->advances(); |
984 unsigned numGlyphs = currentRun->numGlyphs(); | 984 unsigned numGlyphs = currentRun->numGlyphs(); |
985 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); | 985 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); |
986 unsigned graphemesInCluster = 1; | 986 unsigned graphemesInCluster = 1; |
987 float clusterAdvance = 0; | 987 float clusterAdvance = 0; |
988 uint16_t clusterStart; | 988 uint16_t clusterStart; |
989 bool isRTL = m_run.rtl(); | |
Dominik Röttsches
2014/11/14 10:10:47
I wouldn't create a redundant copy here.
Habib Virji
2014/11/24 11:52:31
Reason was it is used quite a lot below. Would rem
| |
990 float glyphAdv = 0; | |
Dominik Röttsches
2014/11/14 10:10:47
Please do not use abbreviations in variable naming
Habib Virji
2014/11/24 11:52:30
Will update to initialAdvance.
| |
989 | 991 |
990 // A "cluster" in this context means a cluster as it is used by HarfBuzz: | 992 // A "cluster" in this context means a cluster as it is used by HarfBuzz: |
991 // The minimal group of characters and corresponding glyphs, that cannot be broken | 993 // The minimal group of characters and corresponding glyphs, that cannot be broken |
992 // down further from a text shaping point of view. | 994 // down further from a text shaping point of view. |
993 // A cluster can contain multiple glyphs and grapheme clusters, with mutuall y | 995 // A cluster can contain multiple glyphs and grapheme clusters, with mutuall y |
994 // overlapping boundaries. Below we count grapheme clusters per HarfBuzz clu sters, | 996 // overlapping boundaries. Below we count grapheme clusters per HarfBuzz clu sters, |
995 // then linearly split the sum of corresponding glyph advances by the number of | 997 // then linearly split the sum of corresponding glyph advances by the number of |
996 // grapheme clusters in order to find positions for emphasis mark drawing. | 998 // grapheme clusters in order to find positions for emphasis mark drawing. |
997 | 999 |
998 if (m_run.rtl()) | 1000 clusterStart = currentRun->startIndex() + (isRTL ? currentRun->numCharacters () : glyphToCharacterIndexes[0]); |
Dominik Röttsches
2014/11/14 10:10:47
As far as I can see, this is functionally equivale
Habib Virji
2014/11/24 11:52:31
Agreed. The change was to ease in following code,
| |
999 clusterStart = currentRun->startIndex() + currentRun->numCharacters(); | |
1000 else | |
1001 clusterStart = currentRun->startIndex() + glyphToCharacterIndexes[0]; | |
1002 | 1001 |
1003 for (unsigned i = 0; i < numGlyphs; ++i) { | 1002 for (unsigned i = 0; i < numGlyphs; ++i) { |
1004 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToChara cterIndexes[i]; | 1003 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToChara cterIndexes[i]; |
1005 bool isRunEnd = (i + 1 == numGlyphs); | 1004 bool isRunEnd = (i + 1 == numGlyphs); |
1006 bool isClusterEnd = isRunEnd || (currentRun->startIndex() + glyphToChar acterIndexes[i + 1] != currentCharacterIndex); | 1005 bool isClusterEnd = isRunEnd || (currentRun->startIndex() + glyphToChara cterIndexes[i + 1] != currentCharacterIndex); |
1006 | |
1007 if ((isRTL && currentCharacterIndex >= m_toIndex) || (!isRTL && currentC haracterIndex < m_fromIndex)) { | |
1008 glyphAdv += advances[i]; | |
1009 isRTL ? --clusterStart : ++clusterStart; | |
1010 continue; | |
1011 } | |
1012 | |
1013 if (glyphAdv) { | |
1014 glyphBuffer->add(0, currentRun->fontData(), glyphAdv); | |
Dominik Röttsches
2014/11/14 10:10:47
Instead of already adding a glyph here, the first
Habib Virji
2014/11/24 11:52:30
That's the issue I struggled with. Adding initialA
| |
1015 glyphAdv = 0; | |
1016 } | |
1017 | |
1007 clusterAdvance += advances[i]; | 1018 clusterAdvance += advances[i]; |
1008 | |
1009 if (isClusterEnd) { | 1019 if (isClusterEnd) { |
1010 uint16_t clusterEnd; | 1020 uint16_t clusterEnd = isRTL ? currentCharacterIndex : |
Dominik Röttsches
2014/11/14 10:10:47
Same as above, code is functionally identical to t
Habib Virji
2014/11/24 11:52:30
Acknowledged.
| |
1011 if (m_run.rtl()) | 1021 currentRun->startIndex() + (isRunEnd ? currentRun->numCharacters () : glyphToCharacterIndexes[i + 1]); |
1012 clusterEnd = currentCharacterIndex; | |
1013 else | |
1014 clusterEnd = isRunEnd ? currentRun->startIndex() + currentRun->n umCharacters() : currentRun->startIndex() + glyphToCharacterIndexes[i + 1]; | |
1015 | 1022 |
1016 graphemesInCluster = countGraphemesInCluster(m_normalizedBuffer.get( ), m_normalizedBufferLength, clusterStart, clusterEnd); | 1023 graphemesInCluster = countGraphemesInCluster(m_normalizedBuffer.get( ), m_normalizedBufferLength, clusterStart, clusterEnd); |
1017 if (!graphemesInCluster || !clusterAdvance) | 1024 if (!graphemesInCluster || !clusterAdvance) |
1018 continue; | 1025 continue; |
1019 | 1026 |
1020 float glyphAdvanceX = clusterAdvance / graphemesInCluster; | 1027 float glyphAdvanceX = clusterAdvance / graphemesInCluster; |
1021 for (unsigned j = 0; j < graphemesInCluster; ++j) { | 1028 for (unsigned j = 0; j < graphemesInCluster; ++j) { |
1022 // Do not put emphasis marks on space, separator, and control ch aracters. | 1029 // Do not put emphasis marks on space, separator, and control ch aracters. |
1023 Glyph glyphToAdd = Character::canReceiveTextEmphasis(m_run[curre ntCharacterIndex]) ? 1 : 0; | 1030 Glyph glyphToAdd = Character::canReceiveTextEmphasis(m_run[curre ntCharacterIndex]) ? 1 : 0; |
1024 glyphBuffer->add(glyphToAdd, currentRun->fontData(), glyphAdvanc eX); | 1031 glyphBuffer->add(glyphToAdd, currentRun->fontData(), glyphAdvanc eX); |
Dominik Röttsches
2014/11/14 10:10:47
So you'd need to use your accumulated initial adva
Habib Virji
2014/11/24 11:52:31
This is what i tried, but due to wrong position of
| |
1025 } | 1032 } |
1026 clusterStart = clusterEnd; | 1033 clusterStart = clusterEnd; |
1027 clusterAdvance = 0; | 1034 clusterAdvance = 0; |
1028 } | 1035 } |
1029 } | 1036 } |
1030 } | 1037 } |
1031 | 1038 |
1032 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) | 1039 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) |
1033 { | 1040 { |
1034 unsigned numRuns = m_harfBuzzRuns.size(); | 1041 unsigned numRuns = m_harfBuzzRuns.size(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 point.x() + fromX, point.x() + toX, | 1152 point.x() + fromX, point.x() + toX, |
1146 point.y(), height); | 1153 point.y(), height); |
1147 } | 1154 } |
1148 | 1155 |
1149 return Font::pixelSnappedSelectionRect( | 1156 return Font::pixelSnappedSelectionRect( |
1150 point.x() + toX, point.x() + fromX, | 1157 point.x() + toX, point.x() + fromX, |
1151 point.y(), height); | 1158 point.y(), height); |
1152 } | 1159 } |
1153 | 1160 |
1154 } // namespace blink | 1161 } // namespace blink |
OLD | NEW |