int main(void) { Job in[N]; Job jobs[N]; int cnt = 0; while (scanf("%s%d%d", in[cnt].name, &in[cnt].arrive_time, &in[cnt].serve_time) == 3) cnt++; copy(jobs, in, cnt); printf("FCFS\n"); FCFS(jobs, cnt); display(jobs, cnt); copy(jobs, in, cnt); printf("RR-1\n"); RR(jobs, cnt, 1); display(jobs, cnt); copy(jobs, in, cnt); printf("RR-4\n"); RR(jobs, cnt, 4); display(jobs, cnt); copy(jobs, in, cnt); printf("SJF\n"); SJF(jobs, cnt); display(jobs, cnt); copy(jobs, in, cnt); printf("HRN\n"); HRN(jobs, cnt); display(jobs, cnt); return 0; }
SkFontStyleSet* SkFontMgr_DirectWrite::onMatchFamily(const char familyName[]) const { SkSMallocWCHAR dwFamilyName; HRN(sk_cstring_to_wchar(familyName, &dwFamilyName)); UINT32 index; BOOL exists; HRNM(fFontCollection->FindFamilyName(dwFamilyName.get(), &index, &exists), "Failed while finding family by name."); if (!exists) { return nullptr; } return this->onCreateStyleSet(index); }
SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const { SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; // This transfers ownership of stream to the new object. HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get())); SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( fFactory.get(), fontFileLoader.get()); SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollectionLoader)); HRN(fFactory->RegisterFontCollectionLoader(fontCollectionLoader.get())); SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollectionLoader( fFactory.get(), fontCollectionLoader.get()); SkTScopedComPtr<IDWriteFontCollection> fontCollection; HRN(fFactory->CreateCustomFontCollection(fontCollectionLoader.get(), nullptr, 0, &fontCollection)); // Find the first non-simulated font which has the given ttc index. UINT32 familyCount = fontCollection->GetFontFamilyCount(); for (UINT32 familyIndex = 0; familyIndex < familyCount; ++familyIndex) { SkTScopedComPtr<IDWriteFontFamily> fontFamily; HRN(fontCollection->GetFontFamily(familyIndex, &fontFamily)); UINT32 fontCount = fontFamily->GetFontCount(); for (UINT32 fontIndex = 0; fontIndex < fontCount; ++fontIndex) { SkTScopedComPtr<IDWriteFont> font; HRN(fontFamily->GetFont(fontIndex, &font)); if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) { continue; } SkTScopedComPtr<IDWriteFontFace> fontFace; HRN(font->CreateFontFace(&fontFace)); UINT32 faceIndex = fontFace->GetIndex(); if (faceIndex == ttcIndex) { return DWriteFontTypeface::Create(fFactory.get(), fontFace.get(), font.get(), fontFamily.get(), autoUnregisterFontFileLoader.detatch(), autoUnregisterFontCollectionLoader.detatch()); } } } return nullptr; }
SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style, const char* bcp47[], int bcp47Count, SkUnichar character) const { const DWriteStyle dwStyle(style); const WCHAR* dwFamilyName = nullptr; SkSMallocWCHAR dwFamilyNameLocal; if (familyName) { HRN(sk_cstring_to_wchar(familyName, &dwFamilyNameLocal)); dwFamilyName = dwFamilyNameLocal; } WCHAR str[16]; UINT32 strLen = static_cast<UINT32>( SkUTF16_FromUnichar(character, reinterpret_cast<uint16_t*>(str))); const SkSMallocWCHAR* dwBcp47; SkSMallocWCHAR dwBcp47Local; if (bcp47Count < 1) { dwBcp47 = &fLocaleName; } else { // TODO: support fallback stack. // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses completely // and may produce a Japanese font. HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local)); dwBcp47 = &dwBcp47Local; } if (fFactory2.get()) { SkTScopedComPtr<IDWriteFontFallback> systemFontFallback; IDWriteFontFallback* fontFallback = fFontFallback.get(); if (!fontFallback) { HRNM(fFactory2->GetSystemFontFallback(&systemFontFallback), "Could not get system fallback."); fontFallback = systemFontFallback.get(); } SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution; HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, nullptr, TRUE, &numberSubstitution), "Could not create number substitution."); SkTScopedComPtr<FontFallbackSource> fontFallbackSource( new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get())); UINT32 mappedLength; SkTScopedComPtr<IDWriteFont> font; FLOAT scale; HRNM(fontFallback->MapCharacters(fontFallbackSource.get(), 0, // textPosition, strLen, fFontCollection.get(), dwFamilyName, dwStyle.fWeight, dwStyle.fSlant, dwStyle.fWidth, &mappedLength, &font, &scale), "Could not map characters"); if (!font.get()) { return nullptr; } SkTScopedComPtr<IDWriteFontFace> fontFace; HRNM(font->CreateFontFace(&fontFace), "Could not get font face from font."); SkTScopedComPtr<IDWriteFontFamily> fontFamily; HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font."); return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily.get()); } SkTScopedComPtr<IDWriteTextFormat> fallbackFormat; HRNM(fFactory->CreateTextFormat(dwFamilyName ? dwFamilyName : L"", fFontCollection.get(), dwStyle.fWeight, dwStyle.fSlant, dwStyle.fWidth, 72.0f, *dwBcp47, &fallbackFormat), "Could not create text format."); SkTScopedComPtr<IDWriteTextLayout> fallbackLayout; HRNM(fFactory->CreateTextLayout(str, strLen, fallbackFormat.get(), 200.0f, 200.0f, &fallbackLayout), "Could not create text layout."); SkTScopedComPtr<FontFallbackRenderer> fontFallbackRenderer( new FontFallbackRenderer(this, character)); HRNM(fallbackLayout->Draw(nullptr, fontFallbackRenderer.get(), 50.0f, 50.0f), "Could not draw layout with renderer."); return fontFallbackRenderer->FallbackTypeface(); }