[BeOS]Bug 200589. Two UTF-8 related fixes in gfx, font size rounding bugfix. r=thesuckiestemail@yahoo.se, No sr required, BeOS-only
This commit is contained in:
Родитель
97a30d4e7a
Коммит
869429c467
|
@ -113,12 +113,7 @@ NS_IMETHODIMP nsFontMetricsBeOS::Init(const nsFont& aFont, nsIAtom* aLangGroup,
|
|||
|
||||
mFont = aFont;
|
||||
|
||||
float app2dev, app2twip;
|
||||
app2dev = aContext->AppUnitsToDevUnits();
|
||||
app2twip = aContext->DevUnitsToTwips();
|
||||
|
||||
app2twip *= app2dev;
|
||||
float rounded = ((float)NSIntPointsToTwips(NSTwipsToFloorIntPoints(nscoord(mFont.size * app2twip)))) / app2twip;
|
||||
float app2twip = aContext->DevUnitsToTwips();
|
||||
|
||||
// process specified fonts from first item of the array.
|
||||
// stop processing next when a real font found;
|
||||
|
@ -210,8 +205,7 @@ NS_IMETHODIMP nsFontMetricsBeOS::Init(const nsFont& aFont, nsIAtom* aLangGroup,
|
|||
&& !(mFontHandle.Face() & B_ITALIC_FACE))
|
||||
mFontHandle.SetShear(105.0);
|
||||
|
||||
mFontHandle.SetSize( rounded * app2dev );
|
||||
fflush(stdout);
|
||||
mFontHandle.SetSize(mFont.size/app2twip);
|
||||
#ifdef NOISY_FONTS
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "looking for font %s (%d)", wildstring, aFont.size / app2twip);
|
||||
|
@ -411,37 +405,9 @@ NS_IMETHODIMP nsFontMetricsBeOS::GetFontHandle(nsFontHandle &aHandle)
|
|||
nsresult
|
||||
nsFontMetricsBeOS::FamilyExists(const nsString& aName)
|
||||
{
|
||||
//Do we really need it here? BeOS supports UTF-8 overall natively,
|
||||
//including UTF-8 fonts names with non-ascii chars inside
|
||||
if (!IsASCII(aName))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString name;
|
||||
name.AssignWithConversion(aName.get());
|
||||
ToLowerCase(name);
|
||||
PRBool isthere = PR_FALSE;
|
||||
|
||||
int32 numFamilies = count_font_families();
|
||||
for (int32 i = 0; i < numFamilies; i++)
|
||||
{
|
||||
font_family family;
|
||||
uint32 flags;
|
||||
if (get_font_family(i, &family, &flags) == B_OK)
|
||||
{
|
||||
if (name.Equals(family) == 0)
|
||||
{
|
||||
isthere = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//printf("%s there? %s\n", name.get(), isthere?"Yes":"No" );
|
||||
|
||||
if (PR_TRUE == isthere)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
NS_ConvertUTF16toUTF8 family(aName);
|
||||
printf("exists? %s", (font_family)family.get());
|
||||
return (count_font_styles((font_family)family.get()) > 0) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// The Font Enumerator
|
||||
|
|
|
@ -1147,8 +1147,30 @@ NS_IMETHODIMP nsRenderingContextBeOS::GetTextDimensions(const char* aString, PRI
|
|||
{
|
||||
// Code is borrowed from win32 implementation including comments.
|
||||
// Minor changes are introduced due multibyte/utf-8 nature of char* strings handling in BeOS.
|
||||
char * utf8ptr = (char *)aString;
|
||||
PRInt32 *utf8pos =0;
|
||||
PRInt32 num_of_glyphs = 0; // Number of glyphs isn't equal to number of bytes in case of UTF-8
|
||||
PRInt32 utf8posbuf[1025];
|
||||
if (aLength < 1025)
|
||||
utf8pos = utf8posbuf;
|
||||
else
|
||||
utf8pos = new PRInt32[aLength + 1];
|
||||
|
||||
NS_PRECONDITION(aBreaks[aNumBreaks - 1] == aLength, "invalid break array");
|
||||
// counting number of glyphs (not bytes) in utf-8 string
|
||||
//and recording positions of first byte for each utf-8 char
|
||||
PRInt32 i = 0;
|
||||
while (i < aLength)
|
||||
{
|
||||
if ( BEGINS_CHAR( utf8ptr[i] ) )
|
||||
{
|
||||
utf8pos[num_of_glyphs] = i;
|
||||
++num_of_glyphs;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
utf8pos[num_of_glyphs] = i; // IMPORTANT for non-ascii strings for proper last-string-in-block.
|
||||
NS_PRECONDITION(aBreaks[aNumBreaks - 1] == num_of_glyphs, "invalid break array");
|
||||
|
||||
// If we need to back up this state represents the last place we could
|
||||
// break. We can use this to avoid remeasuring text
|
||||
PRInt32 prevBreakState_BreakIndex = -1; // not known (hasn't been computed)
|
||||
|
@ -1162,32 +1184,11 @@ NS_IMETHODIMP nsRenderingContextBeOS::GetTextDimensions(const char* aString, PRI
|
|||
PRInt32 start = 0;
|
||||
nscoord aveCharWidth;
|
||||
PRInt32 numBytes = 0;
|
||||
PRInt32 num_of_glyphs = 0; // Number of glyphs isn't equal to number of bytes in case of UTF-8
|
||||
PRInt32 *utf8pos =0;
|
||||
// allocating array for positions of first bytes of utf-8 chars in utf-8 string
|
||||
// from stack if possible
|
||||
PRInt32 utf8posbuf[1025];
|
||||
if (aLength < 1025)
|
||||
utf8pos = utf8posbuf;
|
||||
else
|
||||
utf8pos = new PRInt32[aLength + 1];
|
||||
|
||||
char * utf8ptr = (char *)aString;
|
||||
// counting number of glyphs (not bytes) in utf-8 string
|
||||
//and recording positions of first byte for each utf-8 char
|
||||
PRInt32 i = 0;
|
||||
while (i < aLength)
|
||||
{
|
||||
if ( BEGINS_CHAR( utf8ptr[i] ) )
|
||||
{
|
||||
utf8pos[num_of_glyphs] = i;
|
||||
++num_of_glyphs;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
mFontMetrics->GetAveCharWidth(aveCharWidth);
|
||||
utf8pos[num_of_glyphs] = i; // IMPORTANT for non-ascii strings for proper last-string-in-block.
|
||||
|
||||
|
||||
while (start < num_of_glyphs)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче