     
     func setScaleFactorForUser() {
         var scaleFactor: ScaleFactor?
+        // if user had opened this PDF before, the stored scaleFactor is already optimized for safeArea.
         if pdfView.displayDirection == .vertical {
             scaleFactor = scaleFactorVertical
         } else if pdfView.displayDirection == .horizontal {

                    pdfView.scaleFactor = scaleFactor.portrait / 2
                }
            } else if UIApplication.shared.statusBarOrientation.isLandscape {
                // set scaleFactor to safe area for iPhone X and later
                let multiplier = (pdfView.frame.width - pdfView.safeAreaInsets.left - pdfView.safeAreaInsets.right) / pdfView.frame.width
                if pdfView.displayMode == .singlePageContinuous {
                    pdfView.scaleFactor = scaleFactor.landscape * multiplier
                } else if pdfView.displayMode == .twoUpContinuous {
                    pdfView.scaleFactor = scaleFactor.landscape / 2 * multiplier
                }
            }
        }

        if pdfView.displayDirection == .vertical {
            let frame = view.frame
            let aspectRatio = frame.size.width / frame.size.height
            // if it is iPhoneX, the pdfView.scaleFactorForSizeToFit is already optimized for save area
            let divider = (pdfView.frame.width - pdfView.safeAreaInsets.left - pdfView.safeAreaInsets.right) / pdfView.frame.width
            // the scaleFactor defines the super area scale factor
            var scaleFactor = pdfView.scaleFactorForSizeToFit / divider
            if pdfView.displayMode == .twoUpContinuous {
                scaleFactor *= 2
            }
