// File: /workspace/github_c_makefile_star2_O0/smilingthax[P]libfontembed/embed_sfnt.c
// Function: emb_otf_get_pdf_fontdescr
void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret) // {{{
{
  int len;

//  TODO
//  ... fill in struct
  char *head=otf_get_table(otf,OTF_TAG('h','e','a','d'),&len);
  assert(head); // version is 1.0 from otf_load
  ret->bbxmin=get_SHORT(head+36)*1000/otf->unitsPerEm;
  ret->bbymin=get_SHORT(head+38)*1000/otf->unitsPerEm;
  ret->bbxmax=get_SHORT(head+40)*1000/otf->unitsPerEm;
  ret->bbymax=get_SHORT(head+42)*1000/otf->unitsPerEm;
  const int macStyle=get_USHORT(head+44);
  free(head);

  char *post=otf_get_table(otf,OTF_TAG('p','o','s','t'),&len);
  assert(post);
  const unsigned int post_version=get_ULONG(post);
  // check length
  assert( (post_version!=0x00010000)||(len==32) );
  assert( (post_version!=0x00020000)||(len>=34+2*otf->numGlyphs) );
  assert( (post_version!=0x00025000)||(len==35+otf->numGlyphs) );
  assert( (post_version!=0x00030000)||(len==32) );
  assert( (post_version!=0x00020000)||(get_USHORT(post+32)==otf->numGlyphs) ); // v4?
//  assert( (post_version==0x00030000)==(!!(otf->flags&OTF_F_FMT_CFF)) ); // ghostscript embedding does this..
  // TODO: v4 (apple) :  uint16 reencoding[numGlyphs]
  if ( (post_version==0x00010000)||
       (post_version==0x00020000)||
       (post_version==0x00025000)||
       (post_version==0x00030000)||
       (post_version==0x00040000) ) {
    ret->italicAngle=get_LONG(post+4)>>16;
    if (get_ULONG(post+12)>0) { // monospaced
      ret->flags|=1;
    }
  } else {
    fprintf(stderr,"WARNING: no italicAngle, no monospaced flag\n");
  }
  free(post);

  char *os2=otf_get_table(otf,OTF_TAG('O','S','/','2'),&len);
  if (os2) {
    const unsigned short os2_version=get_USHORT(os2);
    // check len
    assert( (os2_version!=0x0000)||(len==78) );
    assert( (os2_version!=0x0001)||(len==86) );
    assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
    if (os2_version<=0x0004) {

      // from PDF14Deltas.pdf, pg 113
      const int weightClass=get_USHORT(os2+4);
      ret->stemV=50+weightClass*weightClass/(65*65); // TODO, really bad
//printf("a %d\n",weightClass);

      if (ret->supplement>=0) { // cid
        ret->panose=ret->data;
        memcpy(ret->panose,os2+30,12); // sFamilyClass + panose
      }
      const unsigned short fsSelection=get_USHORT(os2+62);
      if (fsSelection&0x01) { // italic
        ret->flags|=0x0040;
      }
      if ( (fsSelection&0x10)&&(weightClass>600) ) { // force bold
        ret->flags|=0x0400;
      }
      const unsigned char family_class=get_USHORT(os2+30)>>8;
      if (family_class==10) { // script
        ret->flags|=0x0008;
      }
      if (family_class!=8) { // not sans-serif
        ret->flags|=0x0002;
      }

      ret->avgWidth=get_SHORT(os2+2)*1000/otf->unitsPerEm;
      ret->ascent=get_SHORT(os2+68)*1000/otf->unitsPerEm;
      ret->descent=get_SHORT(os2+70)*1000/otf->unitsPerEm;
      if (os2_version>=0x0002) {
        ret->xHeight=get_SHORT(os2+86)*1000/otf->unitsPerEm;
        ret->capHeight=get_SHORT(os2+88)*1000/otf->unitsPerEm;
      } // else capHeight fixed later
    } else {
      free(os2);
      os2=NULL;
    }
  } else {
    fprintf(stderr,"WARNING: no OS/2 table\n");
    // e.g. subsetted font from ghostscript // e.g. CFF
  }
  if (os2) {
    free(os2);
  } else { // TODO (if(CFF))
    fprintf(stderr,"WARNING: no ascent/descent, capHeight, stemV, flags\n");
    if (macStyle&0x01) { // force bold - just do it on bold
      ret->flags|=0x0400;
    }
    if (macStyle&0x02) { // italic
      ret->flags|=0x0004;
    }
    //  ... flags TODO? (Serif, Script, Italic, AllCap,SmallCap, ForceBold)
  }

// ? maybe get ascent,descent,capHeight,xHeight,stemV directly from cff
  // Fallbacks
  if ( (!ret->ascent)||(!ret->descent) ) {
    char *hhea=otf_get_table(otf,OTF_TAG('h','h','e','a'),&len);
    if (hhea) {
      ret->ascent=get_SHORT(hhea+4)*1000/otf->unitsPerEm;
      ret->descent=get_SHORT(hhea+6)*1000/otf->unitsPerEm;
    }
    free(hhea);
  }
  if (!ret->stemV) { // TODO? use name
    const unsigned short d_gid=otf_from_unicode(otf,'.');
    if (d_gid) { // stemV=bbox['.'].width;
      len=otf_get_glyph(otf,d_gid);
      assert(len>=10);
      ret->stemV=(get_SHORT(otf->gly+6)-get_SHORT(otf->gly+2))*1000/otf->unitsPerEm;
    } else {
      if (macStyle&1) { // bold
        ret->stemV=165;
      } else {
        ret->stemV=109; // TODO... unserious values...
      }
    }
  }
  if (!ret->capHeight) { // TODO? only reqd. for fonts with latin...
    ret->capHeight=ret->ascent;
    // TODO: OTF spec says:  use metrics of 'H' (0 if not available)
  }
  if (0) { // TODO? uses only adobe latin standard? ?? e.g. Type1
    ret->flags|=0x0020;
  } else {
    ret->flags|=0x0004;
  }
  // TODO SmallCap by font name(?)

// TODO ;   ? cid ?
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x68656164, %esi       # imm = 0x68656164
leaq -0x14(%rbp), %rdx
callq 0x4000
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x66df
jmp 0x66fe
leaq 0x8456(%rip), %rdi      # 0xeb3c
leaq 0x839c(%rip), %rsi      # 0xea89
movl $0x58, %edx
leaq 0x8448(%rip), %rcx      # 0xeb41
callq 0x2100
movq -0x20(%rbp), %rdi
addq $0x24, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rdi
addq $0x26, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rdi
addq $0x2a, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rdi
addq $0x2c, %rdi
callq 0x6450
movzwl %ax, %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
callq 0x21b0
movq -0x8(%rbp), %rdi
movl $0x706f7374, %esi       # imm = 0x706F7374
leaq -0x14(%rbp), %rdx
callq 0x4000
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x67d9
jmp 0x67f8
leaq 0x83a1(%rip), %rdi      # 0xeb81
leaq 0x82a2(%rip), %rsi      # 0xea89
movl $0x61, %edx
leaq 0x834e(%rip), %rcx      # 0xeb41
callq 0x2100
movq -0x30(%rbp), %rdi
callq 0x6e80
movl %eax, -0x34(%rbp)
cmpl $0x10000, -0x34(%rbp)   # imm = 0x10000
jne 0x6813
cmpl $0x20, -0x14(%rbp)
jne 0x6815
jmp 0x6834
leaq 0x836a(%rip), %rdi      # 0xeb86
leaq 0x8266(%rip), %rsi      # 0xea89
movl $0x64, %edx
leaq 0x8312(%rip), %rcx      # 0xeb41
callq 0x2100
cmpl $0x20000, -0x34(%rbp)   # imm = 0x20000
jne 0x6851
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x4c(%rcx), %ecx
shll %ecx
addl $0x22, %ecx
cmpl %ecx, %eax
jl 0x6853
jmp 0x6872
leaq 0x8352(%rip), %rdi      # 0xebac
leaq 0x8228(%rip), %rsi      # 0xea89
movl $0x65, %edx
leaq 0x82d4(%rip), %rcx      # 0xeb41
callq 0x2100
cmpl $0x25000, -0x34(%rbp)   # imm = 0x25000
jne 0x688d
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x4c(%rcx), %ecx
addl $0x23, %ecx
cmpl %ecx, %eax
jne 0x688f
jmp 0x68ae
leaq 0x834d(%rip), %rdi      # 0xebe3
leaq 0x81ec(%rip), %rsi      # 0xea89
movl $0x66, %edx
leaq 0x8298(%rip), %rcx      # 0xeb41
callq 0x2100
cmpl $0x30000, -0x34(%rbp)   # imm = 0x30000
jne 0x68bd
cmpl $0x20, -0x14(%rbp)
jne 0x68bf
jmp 0x68de
leaq 0x8352(%rip), %rdi      # 0xec18
leaq 0x81bc(%rip), %rsi      # 0xea89
movl $0x67, %edx
leaq 0x8268(%rip), %rcx      # 0xeb41
callq 0x2100
cmpl $0x20000, -0x34(%rbp)   # imm = 0x20000
jne 0x6903
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
callq 0x6450
movzwl %ax, %eax
movq -0x8(%rbp), %rcx
movzwl 0x4c(%rcx), %ecx
cmpl %ecx, %eax
jne 0x6905
jmp 0x6924
leaq 0x8332(%rip), %rdi      # 0xec3e
leaq 0x8176(%rip), %rsi      # 0xea89
movl $0x68, %edx
leaq 0x8222(%rip), %rcx      # 0xeb41
callq 0x2100
cmpl $0x10000, -0x34(%rbp)   # imm = 0x10000
je 0x6951
cmpl $0x20000, -0x34(%rbp)   # imm = 0x20000
je 0x6951
cmpl $0x25000, -0x34(%rbp)   # imm = 0x25000
je 0x6951
cmpl $0x30000, -0x34(%rbp)   # imm = 0x30000
je 0x6951
cmpl $0x40000, -0x34(%rbp)   # imm = 0x40000
jne 0x698b
movq -0x30(%rbp), %rdi
addq $0x4, %rdi
callq 0x6ec0
movl %eax, %ecx
sarl $0x10, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x30(%rbp), %rdi
addq $0xc, %rdi
callq 0x6e80
cmpl $0x0, %eax
jbe 0x6989
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x69a3
movq 0xc64e(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x82e4(%rip), %rsi      # 0xec80
movb $0x0, %al
callq 0x21e0
movq -0x30(%rbp), %rdi
callq 0x21b0
movq -0x8(%rbp), %rdi
movl $0x4f532f32, %esi       # imm = 0x4F532F32
leaq -0x14(%rbp), %rdx
callq 0x4000
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x6c58
movq -0x40(%rbp), %rdi
callq 0x6450
movw %ax, -0x42(%rbp)
movzwl -0x42(%rbp), %eax
cmpl $0x0, %eax
jne 0x69e9
cmpl $0x4e, -0x14(%rbp)
jne 0x69eb
jmp 0x6a0a
leaq 0x8076(%rip), %rdi      # 0xea68
leaq 0x8090(%rip), %rsi      # 0xea89
movl $0x7d, %edx
leaq 0x813c(%rip), %rcx      # 0xeb41
callq 0x2100
movzwl -0x42(%rbp), %eax
cmpl $0x1, %eax
jne 0x6a19
cmpl $0x56, -0x14(%rbp)
jne 0x6a1b
jmp 0x6a3a
leaq 0x80a2(%rip), %rdi      # 0xeac4
leaq 0x8060(%rip), %rsi      # 0xea89
movl $0x7e, %edx
leaq 0x810c(%rip), %rcx      # 0xeb41
callq 0x2100
movzwl -0x42(%rbp), %eax
cmpl $0x2, %eax
jl 0x6a52
movzwl -0x42(%rbp), %eax
cmpl $0x4, %eax
jg 0x6a52
cmpl $0x60, -0x14(%rbp)
jne 0x6a54
jmp 0x6a73
leaq 0x808a(%rip), %rdi      # 0xeae5
leaq 0x8027(%rip), %rsi      # 0xea89
movl $0x7f, %edx
leaq 0x80d3(%rip), %rcx      # 0xeb41
callq 0x2100
movzwl -0x42(%rbp), %eax
cmpl $0x4, %eax
jg 0x6c45
movq -0x40(%rbp), %rdi
addq $0x4, %rdi
callq 0x6450
movzwl %ax, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
imull -0x48(%rbp), %eax
movl $0x1081, %ecx           # imm = 0x1081
cltd
idivl %ecx
movl %eax, %ecx
addl $0x32, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jl 0x6ae1
movq -0x10(%rbp), %rcx
addq $0x54, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x1e(%rcx), %rdx
movq %rdx, (%rax)
movl 0x26(%rcx), %ecx
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rdi
addq $0x3e, %rdi
callq 0x6450
movw %ax, -0x4a(%rbp)
movzwl -0x4a(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6b0b
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x40, %ecx
movl %ecx, 0x8(%rax)
movzwl -0x4a(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x6b30
cmpl $0x258, -0x48(%rbp)     # imm = 0x258
jle 0x6b30
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rdi
addq $0x1e, %rdi
callq 0x6450
movzwl %ax, %eax
sarl $0x8, %eax
movb %al, -0x4b(%rbp)
movzbl -0x4b(%rbp), %eax
cmpl $0xa, %eax
jne 0x6b5c
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x8(%rax)
movzbl -0x4b(%rbp), %eax
cmpl $0x8, %eax
je 0x6b72
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rdi
addq $0x2, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x40(%rbp), %rdi
addq $0x44, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x40(%rbp), %rdi
addq $0x46, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movzwl -0x42(%rbp), %eax
cmpl $0x2, %eax
jl 0x6c43
movq -0x40(%rbp), %rdi
addq $0x56, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x40(%rbp), %rdi
addq $0x58, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x6c56
movq -0x40(%rbp), %rdi
callq 0x21b0
movq $0x0, -0x40(%rbp)
jmp 0x6c70
movq 0xc381(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x8044(%rip), %rsi      # 0xecad
movb $0x0, %al
callq 0x21e0
cmpq $0x0, -0x40(%rbp)
je 0x6c82
movq -0x40(%rbp), %rdi
callq 0x21b0
jmp 0x6ccf
movq 0xc357(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
leaq 0x8032(%rip), %rsi      # 0xecc5
movb $0x0, %al
callq 0x21e0
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6cb5
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, 0x8(%rax)
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x6ccd
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x8(%rax)
jmp 0x6ccf
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x6ce3
movq -0x10(%rbp), %rax
cmpl $0x0, 0x24(%rax)
jne 0x6d59
movq -0x8(%rbp), %rdi
movl $0x68686561, %esi       # imm = 0x68686561
leaq -0x14(%rbp), %rdx
callq 0x4000
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x6d50
movq -0x58(%rbp), %rdi
addq $0x4, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x58(%rbp), %rdi
addq $0x6, %rdi
callq 0x6e60
cwtl
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x58(%rbp), %rdi
callq 0x21b0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x6e35
movq -0x8(%rbp), %rdi
movl $0x2e, %esi
callq 0x5280
movw %ax, -0x5a(%rbp)
cmpw $0x0, -0x5a(%rbp)
je 0x6e0e
movq -0x8(%rbp), %rdi
movzwl -0x5a(%rbp), %esi
callq 0x5040
movl %eax, -0x14(%rbp)
cmpl $0xa, -0x14(%rbp)
jl 0x6d9c
jmp 0x6dbb
leaq 0x7f57(%rip), %rdi      # 0xecfa
leaq 0x7cdf(%rip), %rsi      # 0xea89
movl $0xc4, %edx
leaq 0x7d8b(%rip), %rcx      # 0xeb41
callq 0x2100
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
addq $0x6, %rdi
callq 0x6e60
cwtl
movl %eax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
addq $0x2, %rdi
callq 0x6e60
movw %ax, %cx
movl -0x60(%rbp), %eax
movswl %cx, %ecx
subl %ecx, %eax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movq -0x8(%rbp), %rcx
movzwl 0x48(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
jmp 0x6e33
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6e26
movq -0x10(%rbp), %rax
movl $0xa5, 0x2c(%rax)
jmp 0x6e31
movq -0x10(%rbp), %rax
movl $0x6d, 0x2c(%rax)
jmp 0x6e33
jmp 0x6e35
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x6e4d
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x8(%rax)
addq $0x60, %rsp
popq %rbp
retq