Fixed SMask/ExtGstate scanning rule in pdf writer

Currently pdf writer mostly write direct object to out, assuming
all internal are direct objs, that's why
extgstate is not scanned in resource scanning. However, /SMask normal
are external objs, required to be scanned and put into the output's xref
struct.
In case writer can not find ref in output's xref struct, it will retrieve
original from doc's obj tree, and write out as direct obj.