<commit_before>! Copyright (C) 2011-2012 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: accessors arrays assocs calendar colors colors.gray
combinators combinators.short-circuit fonts formatting
hashtables io kernel make math math.parser sequences strings
xml.entities ;

IN: pdf.values

<PRIVATE

: escape-string ( str -- str' )
    H{
        { 0x08    "\\b"  }
        { 0x0c    "\\f"  }
        { CHAR: \n   "\\n"  }
        { CHAR: \r   "\\r"  }
        { CHAR: \t   "\\t"  }
        { CHAR: \\   "\\\\" }
        { CHAR: (    "\\("  }
        { CHAR: )    "\\)"  }
    } escape-string-by ;

PRIVATE>

GENERIC: pdf-value ( obj -- str )

M: number pdf-value number>string ;

M: t pdf-value drop "true" ;

M: f pdf-value drop "false" ;

M: color pdf-value
    >rgba-components drop "%f %f %f" sprintf ;

M: font pdf-value
    [
        "<<" ,
        "/Type /Font" ,
        "/Subtype /Type1" ,
        {
            [
                name>> {
                    { "sans-serif" [ "/Helvetica" ] }
                    { "serif"      [ "/Times"     ] }
                    { "monospace"  [ "/Courier"   ] }
                    [ " is unsupported" append throw ]
                } case
            ]
            [ [ bold?>> ] [ italic?>> ] bi or [ "-" append ] when ]
            [ bold?>> [ "Bold" append ] when ]
            [ italic?>> [ "Italic" append ] when ]
        } cleave
        "/BaseFont " prepend ,
        ">>" ,
    ] { } make "\n" join ;

M: timestamp pdf-value
    "%Y%m%d%H%M%S" strftime "D:" prepend ;

M: string pdf-value
    escape-string "(" ")" surround ;

M: sequence pdf-value
    [ "[" % [ pdf-value % " " % ] each "]" % ] "" make ;

M: hashtable pdf-value
    [
        "<<\n" %
        [ swap % " " % pdf-value % "\n" % ] assoc-each
        ">>" %
    ] "" make ;

: pdf-write ( obj -- )
    pdf-value write ;<commit_msg>pdf.values: fix names for some fonts.<commit_after>! Copyright (C) 2011-2012 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: accessors arrays assocs calendar colors colors.gray
combinators combinators.short-circuit fonts formatting
hashtables io kernel make math math.parser sequences splitting
strings xml.entities ;

IN: pdf.values

<PRIVATE

: escape-string ( str -- str' )
    H{
        { 0x08    "\\b"  }
        { 0x0c    "\\f"  }
        { CHAR: \n   "\\n"  }
        { CHAR: \r   "\\r"  }
        { CHAR: \t   "\\t"  }
        { CHAR: \\   "\\\\" }
        { CHAR: (    "\\("  }
        { CHAR: )    "\\)"  }
    } escape-string-by ;

PRIVATE>

GENERIC: pdf-value ( obj -- str )

M: number pdf-value number>string ;

M: t pdf-value drop "true" ;

M: f pdf-value drop "false" ;

M: color pdf-value
    >rgba-components drop "%f %f %f" sprintf ;

M: font pdf-value
    [
        "<<" ,
        "/Type /Font" ,
        "/Subtype /Type1" ,
        {
            [
                name>> {
                    { "sans-serif" [ "/Helvetica" ] }
                    { "serif"      [ "/Times"     ] }
                    { "monospace"  [ "/Courier"   ] }
                    [ " is unsupported" append throw ]
                } case
            ]
            [ [ bold?>> ] [ italic?>> ] bi or [ "-" append ] when ]
            [ bold?>> [ "Bold" append ] when ]
            [ italic?>> [ "Italic" append ] when ]
            [
                name>> { "sans-serif" "monospace" } member?
                [ "Italic" "Oblique" replace ] when
            ]
        } cleave
        "/BaseFont " prepend ,
        ">>" ,
    ] { } make "\n" join ;

M: timestamp pdf-value
    "%Y%m%d%H%M%S" strftime "D:" prepend ;

M: string pdf-value
    escape-string "(" ")" surround ;

M: sequence pdf-value
    [ "[" % [ pdf-value % " " % ] each "]" % ] "" make ;

M: hashtable pdf-value
    [
        "<<\n" %
        [ swap % " " % pdf-value % "\n" % ] assoc-each
        ">>" %
    ] "" make ;

: pdf-write ( obj -- )
    pdf-value write ;
{'fraction_non_alphanumeric': 0.17244014263881813, 'fraction_numerical': 0.007131940906775344, 'mean_word_length': 1.436104218362283, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1184614', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1348, 'n_words': 318}