コード例 #1
0
void
SkFontData::loadXml( SkTDArray<FontInitRec> &info )
{
    SkTDArray<FontFamily*> families;
    getFamilies( families );
    info.reset();

    for( int i = 0 ; i < families.count() ; ++i )
    {
        FontFamily * family = families[i];

        for( int j = 0 ; j < family->fFontFileArray.count() ; ++j )
        {
            const char * filename = family->fFontFileArray[j]->fFileName;
#ifndef DEPRECATED_CODE
            HyLogif( "DEPRECATED_CODE" );
            if( haveSystemFont( filename ) )
                continue;
#endif
            FontInitRec fontInfoRecord;
            fontInfoRecord.fFileName = filename;

            if( j == 0 )
            {
                if( family->fNames.count() == 0 )
                    fontInfoRecord.fNames = ( char ** )gFBNames; // fallback.
                else
                {
                    SkTDArray<const char*> names = family->fNames;
                    const char ** nameList = ( const char ** )calloc( ( names.count() + 1 ), sizeof( char * ) );

                    if( nameList == NULL )
                    {
                        break;
                    }

                    for( int n = 0 ; n < names.count() ; ++n )
                    {
                        nameList[n] = names[n];
                    }

                    nameList[names.count()] = NULL;
                    fontInfoRecord.fNames = nameList;
                }
            }
            else
            {
                fontInfoRecord.fNames = NULL;
            }

            *info.append() = fontInfoRecord;
        }
    }

    families.deleteAll();
}
コード例 #2
0
ファイル: SkFontMgr_android.cpp プロジェクト: sylvestre/skia
 SkFontMgr_Android(const SkFontMgr_Android_CustomFonts* custom) {
     SkTDArray<FontFamily*> families;
     if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem != custom->fSystemFontUse) {
         SkString base(custom->fBasePath);
         SkFontMgr_Android_Parser::GetCustomFontFamilies(
             families, base, custom->fFontsXml, custom->fFallbackFontsXml);
     }
     if (!custom ||
         (custom && SkFontMgr_Android_CustomFonts::kOnlyCustom != custom->fSystemFontUse))
     {
         SkFontMgr_Android_Parser::GetSystemFontFamilies(families);
     }
     if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem == custom->fSystemFontUse) {
         SkString base(custom->fBasePath);
         SkFontMgr_Android_Parser::GetCustomFontFamilies(
             families, base, custom->fFontsXml, custom->fFallbackFontsXml);
     }
     this->buildNameToFamilyMap(families, custom ? custom->fIsolated : false);
     this->findDefaultStyleSet();
     families.deleteAll();
 }
コード例 #3
0
ファイル: SkFontHost_android.cpp プロジェクト: bunhere/skia
/*  Load info from a configuration file that populates the system/fallback font structures
*/
static void load_font_info() {
    SkTDArray<FontFamily*> fontFamilies;
    if (gTestMainConfigFile) {
        getTestFontFamilies(fontFamilies, gTestMainConfigFile, gTestFallbackConfigFile);
    } else {
        getFontFamilies(fontFamilies);
    }

    SkTDArray<FontInitRec> fontInfo;
    bool firstInFamily = false;
    for (int i = 0; i < fontFamilies.count(); ++i) {
        FontFamily *family = fontFamilies[i];
        firstInFamily = true;
        for (int j = 0; j < family->fFileNames.count(); ++j) {
            FontInitRec fontInfoRecord;
            fontInfoRecord.fFileName = family->fFileNames[j];
            if (j == 0) {
                if (family->fNames.count() == 0) {
                    // Fallback font
                    fontInfoRecord.fNames = (char **)gFBNames;
                } else {
                    SkTDArray<const char*> names = family->fNames;
                    const char **nameList = (const char**)
                            malloc((names.count() + 1) * sizeof(char*));
                    if (nameList == NULL) {
                        // shouldn't get here
                        SkDEBUGFAIL("Failed to allocate nameList");
                        break;
                    }
                    if (gDefaultNames == NULL) {
                        gDefaultNames = (char**) nameList;
                    }
                    for (int i = 0; i < names.count(); ++i) {
                        nameList[i] = names[i];
                    }
                    nameList[names.count()] = NULL;
                    fontInfoRecord.fNames = nameList;
                }
            } else {
                fontInfoRecord.fNames = NULL;
            }
            *fontInfo.append() = fontInfoRecord;
        }
    }
    gNumSystemFonts = fontInfo.count();
    gSystemFonts = (FontInitRec*) malloc(gNumSystemFonts * sizeof(FontInitRec));
    gFallbackFonts = (uint32_t*) malloc((gNumSystemFonts + 1) * sizeof(uint32_t));
    if (gSystemFonts == NULL) {
        // shouldn't get here
        SkDEBUGFAIL("No system fonts were found");
        gNumSystemFonts = 0;
    }

#if SK_DEBUG_FONTS
    SkDebugf("---- We have %d system fonts", gNumSystemFonts);
#endif
    for (size_t i = 0; i < gNumSystemFonts; ++i) {
        gSystemFonts[i].fFileName = fontInfo[i].fFileName;
        gSystemFonts[i].fNames = fontInfo[i].fNames;
#if SK_DEBUG_FONTS
        SkDebugf("---- gSystemFonts[%d] fileName=%s", i, fontInfo[i].fFileName);
#endif
    }
    fontFamilies.deleteAll();
}
コード例 #4
0
ファイル: nanobench.cpp プロジェクト: Crawping/skia_custom
int tool_main(int argc, char** argv) {
    SetupCrashHandler();
    SkAutoGraphics ag;
    SkCommandLineFlags::Parse(argc, argv);

    const double overhead = estimate_timer_overhead();

    if (FLAGS_verbose) {
        // No header.
    } else if (FLAGS_quiet) {
        SkDebugf("min\tbench\tconfig\n");
    } else {
        SkDebugf("loops\tmin\tmean\tmax\tstddev\tbench\tconfig\n");
    }

    for (const BenchRegistry* r = BenchRegistry::Head(); r != NULL; r = r->next()) {
        SkAutoTDelete<Benchmark> bench(r->factory()(NULL));
        if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
            continue;
        }

        SkTDArray<SkSurface*> surfaces;
        SkTDArray<const char*> configs;
        create_surfaces(bench.get(), &surfaces, &configs);

        bench->preDraw();
        for (int j = 0; j < surfaces.count(); j++) {
            SkCanvas* canvas = surfaces[j] ? surfaces[j]->getCanvas() : NULL;
            const char* config = configs[j];

            bench->draw(1, canvas);  // Just paranoid warmup.
            safe_flush(canvas);
            const int loops = guess_loops(overhead, bench.get(), canvas);

            SkAutoTMalloc<double> samples(FLAGS_samples);
            WallTimer timer;
            for (int i = 0; i < FLAGS_samples; i++) {
                timer.start();
                bench->draw(loops, canvas);
                safe_flush(canvas);
                timer.end();
                samples[i] = timer.fWall / loops;
            }

            Stats stats(samples.get(), FLAGS_samples);

            if (FLAGS_verbose) {
                for (int i = 0; i < FLAGS_samples; i++) {
                    SkDebugf("%s  ", humanize(samples[i]).c_str());
                }
                SkDebugf("%s\n", bench->getName());
            } else if (FLAGS_quiet) {
                if (configs.count() == 1) {
                    config = ""; // Only print the config if we run the same bench on more than one.
                }
                SkDebugf("%s\t%s\t%s\n", humanize(stats.min).c_str(), bench->getName(), config);
            } else {
                const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
                SkDebugf("%d\t%s\t%s\t%s\t%.0f%%\t%s\t%s\n"
                        , loops
                        , humanize(stats.min).c_str()
                        , humanize(stats.mean).c_str()
                        , humanize(stats.max).c_str()
                        , stddev_percent
                        , bench->getName()
                        , config
                        );
            }
        }
        surfaces.deleteAll();
    }

    return 0;
}