PS Dosyalarına Metin Ekleme

PS dosyalarının metinleriyle çalışmak için C++ API çözümü

 

Güçlü bir sayfa tanımlama dili olan PostScript, metin yerleşimi ve biçimlendirmesi üzerinde ayrıntılı kontrol sunar. PostScript'te metinle çalışırken göz önünde bulundurulması gereken bazı temel incelikler şunlardır:

  • PostScript, yazı tiplerini PostScript adlarını kullanarak seçmenize olanak tanır. Times Roman, Helvetica ve Courier gibi yaygın yazı tipleri genellikle varsayılan olarak mevcuttur. Farklı sistemlerde tutarlı oluşturma sağlamak için yazı tiplerini doğrudan PostScript dosyanıza gömebilirsiniz. Bu, özellikle özel yazı tipleri veya daha az yaygın yazı tipi aileleri için önemlidir.
  • Yazı Tipi Boyutu ve Stili - fontsize operatörü, yazı tipi boyutunu punto cinsinden ayarlar. Yazı tipi stillerini değiştirmek için kalın, italik veya diğer varyasyonları belirten setfont gibi operatörleri kullanın.
  • Metin Konumlandırma - moveto operatörü, metin imlecini sayfadaki belirli bir noktaya konumlandırır. PostScript’te doğrudan hizalama operatörleri bulunmasa da, dikkatli hesaplamalarla hizalama sağlayabilirsiniz.
  • Metin Döndürme ve Ölçekleme - rotate operatörü metni belirli bir açıda döndürmek için kullanılabilir ve scale operatörü metni büyütmek veya küçültmek için kullanılabilir.
  • Metin Oluşturma - PostScript, daha iyi okunabilirlik için metnin kenarlarını düzelten kenar yumuşatmayı (anti-aliasing) destekler. Metnin görünümüne ince ayar yapmak için karakterler arasındaki boşluğu (kerning) ve satırlar arasındaki boşluğu (leading) da kontrol edebilirsiniz.

Bu yönleri anlamak, PostScript tabanlı iş akışlarında uygun yazı tipi kullanımını ve tutarlı oluşturmayı sağlamaya yardımcı olabilir. Ancak ne olursa olsun - Aspose.Page size PS dosyalarının yazı tiplerini kolayca yönetme işlevselliği sağlar. Bu API ile özel veya sistem yazı tiplerini kullanarak farklı renklerde ve fırçalarda metinler ekleyebilirsiniz. PS dosyalarıyla nasıl başa çıkılacağı ve özellikle PS dosyalarının metinleriyle nasıl çalışılacağı hakkında daha fazla bilgi edinmek için belgeleri takip edin.

PS belgelerine metin eklemek için şunlara ihtiyacımız var:

  • Zengin özelliklere sahip, güçlü ve kullanımı kolay bir belge düzenleme ve dönüştürme C++ API'si olan Aspose.Page for C++ API'sini edinin.

  • NuGet paket yöneticisini açın, Aspose.Page.Cpp'yi arayın ve kurun. Ayrıca Paket Yöneticisi Konsolu'ndan aşağıdaki komutu da kullanabilirsiniz.

Package Manager Console Command

    PM> Install-Package Aspose.Page.Cpp

Bir PS dosyasına metin ekleme adımları.

Aşağıdaki kod parçası, C++‘daki Aspose.Page kitaplığını kullanarak bir PostScript (PS) belgesine Unicode dizesi kullanarak nasıl metin ekleneceğini gösterir. Örneği daha kapsamlı bir şekilde görmek ve daha fazla örnek için Aspose.Page-for-C++ GitHub projesine gidin.

  1. Belgeleri içeren dizinin yolu ile dataDir değişkenini başlatın.
  2. FONTS_FOLDER değişkenini gerekli yazı tiplerini içeren klasörün yoluna ayarlayın.
  3. FileStream sınıfını kullanarak PostScript belgesi için bir çıktı akışı oluşturun.
  4. PsSaveOptions nesnesini kullanarak PostScript belgesi için kaydetme seçeneklerini belirtin.
  5. Seçenekler nesnesinin AdditionalFontsFolders özelliği, FONTS_FOLDER yolunu içeren bir diziye ayarlanır. Bu, sistemin bu klasördeki gerekli yazı tiplerini bulmasını sağlar.
  6. Metni ve boyutunu belirtin.
  7. Çıktı akışı, seçenekler ve parametre olarak false ile yeni bir PsDocument örneği oluşturun. Bu, belirtilen seçeneklerle yeni bir PostScript belgesi başlatır.
  8. Belge nesnesi üzerinde ClosePage() yöntemini çağırarak geçerli sayfanın tamamlandığını belirtin.
  9. PS belgesinde yapılan değişiklikleri kaydetmek için Save() yöntemini kullanın.
Bir PS dosyasına metin eklemek için C++ Kodu
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithText();
    
    System::String FONTS_FOLDER = RunExamples::GetDataDir_Data() + u"necessary_fonts/";
    
    //Create output stream for PostScript document
    {
        System::SharedPtr<System::IO::Stream> outPsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"AddText_outPS.ps", System::IO::FileMode::Create);
        // Clearing resources under 'using' statement
        System::Details::DisposeGuard<1> __dispose_guard_0({ outPsStream});
        // ------------------------------------------
        
        try
        {
            //Create save options with A4 size
            System::SharedPtr<PsSaveOptions> options = System::MakeObject<PsSaveOptions>();
            // Set custom fonts folder. It will be added to system fonts folders for finding needed font.
            options->set_AdditionalFontsFolders(System::MakeArray<System::String>({FONTS_FOLDER}));
            //A text to write to PS file
            System::String str = u"ABCDEFGHIJKLMNO";
            int32_t fontSize = 48;
            
            // Create new 1-paged PS Document
            System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(outPsStream, options, false);
            
            ////////////////////////////////////// Using sysem font (located in system fonts folders) for filling text //////////////////
            System::SharedPtr<System::Drawing::Font> font = System::MakeObject<System::Drawing::Font>(u"Times New Roman", static_cast<float>(fontSize), System::Drawing::FontStyle::Bold);
            //Fill text with default or already defined color. In given case it is black.
            document->FillText(str, font, 50.0f, 100.0f);
            //Fill text with Blue color.
            document->FillText(str, font, 50.0f, 150.0f, System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_Blue()));
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            ////////////////////////////////////// Using custom font (located in custom fonts folders) for filling text /////////////////
            System::SharedPtr<DrFont> drFont = ExternalFontCache::FetchDrFont(u"Palatino Linotype", static_cast<float>(fontSize), System::Drawing::FontStyle::Regular);
            //Fill text with default or already defined color. In given case it is black.
            document->FillText(str, drFont, 50.0f, 200.0f);
            //Fill text with Blue color.
            document->FillText(str, drFont, 50.0f, 250.0f, System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_Blue()));
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            ////////////////////////////////////// Using sysem font (located in system fonts folders) for outlining text ////////////////
            //Outline text with default or already defined pen. In given case it is black colored 1-points width pen.
            document->OutlineText(str, font, 50.0f, 300.0f);
            //Outline text with blue-violet colored 2-points width pen.
            document->OutlineText(str, font, 50.0f, 350.0f, System::MakeObject<System::Drawing::Pen>(System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_BlueViolet()), 2.0f));
            //Fill text with orange color and stroke with blue colored 2-points width pen.
            document->FillAndStrokeText(str, font, 50.0f, 400.0f, System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_Yellow()), System::MakeObject<System::Drawing::Pen>(System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_BlueViolet()), 2.0f));
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            ////////////////////////////////////// Using custom font (located in custom fonts folders) for outlining text /////////////////
            //Outline text with default or already defined pen. In given case it is black colored 1-points width pen.
            document->OutlineText(str, drFont, 50.0f, 450.0f);
            //Outline text with blue-violet colored 2-points width pen.
            document->OutlineText(str, drFont, 50.0f, 500.0f, System::MakeObject<System::Drawing::Pen>(System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_BlueViolet()), 2.0f));
            //Fill text with orange color and stroke with blue colored 2-points width pen.
            document->FillAndStrokeText(str, drFont, 50.0f, 550.0f, System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_Orange()), System::MakeObject<System::Drawing::Pen>(System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_Blue()), 2.0f));
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            /////////////////////////////// Using custom font (located in custom fonts folders) ang glyphs widths for filling text ////////
            drFont = ExternalFontCache::FetchDrFont(u"Palatino Linotype", static_cast<float>(fontSize), System::Drawing::FontStyle::Regular);
            //Glyphs widths
            System::ArrayPtr<float> widths = System::MakeArray<float>({87, 87, 87, 87, 34, 87, 87});
            //Fill ASCII text using with assigning glyphs widths.
            document->FillText(u"BAMBOOK", widths, drFont, 50.0f, 600.0f, System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_Blue()));
            ///////////////////////////// Using custom font (located in custom fonts folders) ang glyphs widths for filling unicode text //
            //Glyphs widths
            widths = System::MakeArray<float>({87, 34, 87, 87, 87, 87, 87});
            //Fill Unicode text using with assigning glyphs widths.
            document->FillText(u"ЗООПАРК", widths, drFont, 50.0f, 650.0f, System::MakeObject<System::Drawing::SolidBrush>(System::Drawing::Color::get_Orange()));
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            //Close current page
            document->ClosePage();
            
            //Save the document
            document->Save();
        }
        catch(...)
        {
            __dispose_guard_0.SetCurrentException(std::current_exception());
        }
    }

PS What is PS File Format

PS (PostScript), metin ve grafiği tek dosyada birleştiren bir sayfa tanımlama dilidir. Çoğu görüntü düzenleyici ve yazıcı tarafından desteklenir ve yazıcıya sayfanın nasıl render edileceğini bildirir.