PRBool test_permanent() { nsrefcnt count = NS_GetNumberOfAtoms(); { nsCOMPtr<nsIAtom> first = do_GetAtom(FIRST_PERM_ATOM_STR); if (!first->Equals(NS_LITERAL_STRING(FIRST_PERM_ATOM_STR)) || isStaticAtom(first)) return PR_FALSE; nsCOMPtr<nsIAtom> first_p = NS_NewPermanentAtom(NS_LITERAL_STRING(FIRST_PERM_ATOM_STR)); if (!first_p->Equals(NS_LITERAL_STRING(FIRST_PERM_ATOM_STR)) || !isStaticAtom(first_p) || first != first_p) return PR_FALSE; nsCOMPtr<nsIAtom> second_p = NS_NewPermanentAtom(NS_LITERAL_STRING(SECOND_PERM_ATOM_STR)); if (!second_p->Equals(NS_LITERAL_STRING(SECOND_PERM_ATOM_STR)) || !isStaticAtom(second_p)) return PR_FALSE; nsCOMPtr<nsIAtom> second = do_GetAtom(SECOND_PERM_ATOM_STR); if (!second->Equals(NS_LITERAL_STRING(SECOND_PERM_ATOM_STR)) || !isStaticAtom(second) || second != second_p) return PR_FALSE; } return NS_GetNumberOfAtoms() == count + 2; }
NS_IMETHODIMP nsAtomService::GetPermanentAtomUTF8(const char *aValue, nsIAtom* *aResult) { *aResult = NS_NewPermanentAtom(aValue); if (!*aResult) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; }
nsresult nsAtomService::GetPermanentAtom(const PRUnichar *aString, nsIAtom ** aResult) { *aResult = NS_NewPermanentAtom(aString); if (!*aResult) return NS_ERROR_OUT_OF_MEMORY; return NS_OK; }
void RunTest (TestEntry *test, gfxContext *ctx) { if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) { gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL, NS_FONT_STRETCH_NORMAL, 400, 16.0, NS_NewPermanentAtom(NS_LITERAL_STRING("en")), 0.0, PR_FALSE, PR_FALSE, PR_FALSE, NS_LITERAL_STRING(""), NS_LITERAL_STRING("")); fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nsnull); } nsAutoPtr<gfxTextRun> textRun; PRUint32 i; bool isASCII = true; for (i = 0; test->mString[i]; ++i) { if (test->mString[i] & 0x80) { isASCII = PR_FALSE; } } gfxTextRunFactory::Parameters params = { ctx, nsnull, nsnull, nsnull, 0, 60 }; PRUint32 flags = gfxTextRunFactory::TEXT_IS_PERSISTENT; PRUint32 length; if (isASCII) { flags |= gfxTextRunFactory::TEXT_IS_ASCII | gfxTextRunFactory::TEXT_IS_8BIT; length = strlen(test->mString); textRun = fontGroup->MakeTextRun(reinterpret_cast<const PRUint8*>(test->mString), length, ¶ms, flags); } else { NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString)); length = str.Length(); textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms, flags); } // Should we test drawing? // textRun->Draw(ctx, gfxPoint(0,0), 0, length, nsnull, nsnull, nsnull); textRun->GetAdvanceWidth(0, length, nsnull); }
ANPTypeface* anp_typeface_createFromName(const char name[], ANPTypefaceStyle aStyle) { LOG("%s - %s\n", __PRETTY_FUNCTION__, name); gfxFontStyle style (aStyle == kItalic_ANPTypefaceStyle ? FONT_STYLE_ITALIC : FONT_STYLE_NORMAL, NS_FONT_STRETCH_NORMAL, aStyle == kBold_ANPTypefaceStyle ? 700 : 400, 16.0, NS_NewPermanentAtom(NS_LITERAL_STRING("en")), 0.0, false, false, NS_LITERAL_STRING(""), NS_LITERAL_STRING("")); ANPTypeface* tf = new ANPTypeface; gfxAndroidPlatform * p = (gfxAndroidPlatform*)gfxPlatform::GetPlatform(); nsRefPtr<gfxFont> font = gfxFT2Font::GetOrMakeFont(NS_ConvertASCIItoUTF16(name), &style); font.forget(&tf->mFont); if (tf->mFont) { ++tf->mRefCnt; } return tf; }
int main (int argc, char **argv) { #ifdef MOZ_WIDGET_GTK2 gtk_init(&argc, &argv); #endif #ifdef XP_MACOSX CocoaPoolInit(); #endif // Initialize XPCOM nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) return -1; rv = gfxPlatform::Init(); if (NS_FAILED(rv)) return -1; // let's get all the xpcom goop out of the system fflush (stderr); fflush (stdout); gTextRuns = new FrameTextRunCache(); nsRefPtr<gfxContext> ctx = MakeContext(); { gfxFontStyle style (FONT_STYLE_NORMAL, NS_FONT_STRETCH_NORMAL, 139, 10.0, NS_NewPermanentAtom(NS_LITERAL_STRING("en")), 0.0, PR_FALSE, PR_FALSE, PR_FALSE, NS_LITERAL_STRING(""), NS_LITERAL_STRING("")); nsRefPtr<gfxFontGroup> fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_LITERAL_STRING("Geneva, MS Sans Serif, Helvetica,serif"), &style, nsnull); gfxTextRunFactory::Parameters params = { ctx, nsnull, nsnull, nsnull, 0, 60 }; PRUint32 flags = gfxTextRunFactory::TEXT_IS_PERSISTENT; // First load an Arabic word into the cache const char cString[] = "\xd8\xaa\xd9\x85"; nsDependentCString cStr(cString); NS_ConvertUTF8toUTF16 str(cStr); gfxTextRun *tr = MakeTextRun(str.get(), str.Length(), fontGroup, ¶ms, flags); tr->GetAdvanceWidth(0, str.Length(), nsnull); // Now try to trigger an assertion with a word cache bug. The first // word is in the cache so it gets added to the new textrun directly. // The second word is not in the cache const char cString2[] = "\xd8\xaa\xd9\x85\n\xd8\xaa\xd8\x85 "; nsDependentCString cStr2(cString2); NS_ConvertUTF8toUTF16 str2(cStr2); gfxTextRun *tr2 = MakeTextRun(str2.get(), str2.Length(), fontGroup, ¶ms, flags); tr2->GetAdvanceWidth(0, str2.Length(), nsnull); } fflush (stderr); fflush (stdout); }